sgrossman

Livestreamer.ahk

Feb 19th, 2014
519
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3. Title: Livestreamer GUI
  4. Author: Scott Grossman
  5. Author Contact: scott DOT grossman AT me DOT com
  6. Version: 1.01
  7. Requires: Livestreamer (livestreamer.tanuki.se) & json.ahk (https://raw2.github.com/cocobelgica/AutoHotkey-JSON/master/JSON.ahk)
  8.  
  9. Modify and distribute as you please.
  10.  
  11. Changelog:
  12. v1.0
  13.     Initial release
  14. v1.01
  15.     Added a MsgBox when no streams are found.
  16. v1.1
  17.     Removed hotkeys and persistence
  18.     Run hotkeys in another script or just launch the script with a shortcut or something
  19.     To run it in quick-mode (skipping the GUI) just pass the script any command line parameter
  20.     Example hotkeys:
  21.         PrintScreen::RunWait, Livestreamer.ahk ; Launch GUI
  22.         *PrintScreen::Runwait, Livestreamer.ahk true ; Quick-Mode (No GUI)
  23. */
  24.  
  25.  
  26. #Include %A_ScriptDir%
  27. #Include json.ahk ;https://raw2.github.com/cocobelgica/AutoHotkey-JSON/master/JSON.ahk
  28. #SingleInstance ignore
  29. #LTrim
  30.  
  31. favoritestreams =
  32. (
  33.     riotgames
  34.     TSM_TheOddOne
  35.     TSM_Dyrus
  36.     wingsofdeath
  37.     TSM_Reginald
  38.     TSM_Bjergsen
  39.     imaqtpie
  40.     TSM_WildTurtle
  41.     Trick2g
  42.     PhantomL0rd
  43.     dandinh
  44.     Westrice
  45.     TSM_Xpecial
  46. )
  47.  
  48. variablefiledir := A_ScriptDir . "\Livestreamer"
  49. variablefile := variablefiledir . "\stream"
  50.  
  51. Loop, Parse, favoritestreams, `n
  52. {
  53.     if streams
  54.         streams := streams . "|twitch.tv/" . A_LoopField
  55.     else
  56.         streams := "twitch.tv/" . A_LoopField
  57. }
  58.  
  59. FileRemoveDir, %variablefiledir%, 1
  60. FileCreateDir, %variablefiledir%
  61.  
  62. validstreams :=
  63. foundone := false
  64.  
  65. haystack := Clipboard
  66. needle := "^(?:https?:\/\/)?(?:www\.)?((?:(?:twitch\.tv\/)|(?:youtube\.com\/))\S+?)(?:\d\ds)?$"
  67. matched := RegExMatch(haystack, needle, URL)
  68.  
  69. if matched
  70.     streams := URL1 . "|" . streams
  71.  
  72. Loop, Parse, streams, |
  73. {
  74.     jsonfile := variablefiledir . "\templog" . A_Index . ".txt"
  75.     Run %comspec% /c livestreamer -j %A_LoopField% best > "%jsonfile%" ,,Hide, PID%A_Index%
  76. }
  77.  
  78. Loop, Parse, streams, |
  79. {
  80.     jsonfile := variablefiledir . "\templog" . A_Index . ".txt"
  81.     Process, WaitClose, % PID%A_Index%
  82.     FileRead, Contents, %jsonfile%
  83.     if not ErrorLevel
  84.     {
  85.         j := JSON.parse(Contents)
  86.         if not j.error
  87.             if %1%
  88.             {
  89.                 Run %comspec% /c livestreamer %A_LoopField% best,,Hide
  90.                 foundone := true
  91.                 break
  92.             }
  93.             else if validstreams
  94.                 validstreams := validstreams . "|" . A_LoopField
  95.             else
  96.                 validstreams := A_LoopField
  97.     }
  98. }
  99.  
  100. FileRemoveDir, %variablefiledir%, 1
  101.  
  102. if validstreams
  103. {
  104.     Gui, Add, DropDownList, x43 y57 w280 h21 r10 vselectedstream +Choose1, %validstreams%
  105.     Gui, Add, Text, x43 y17 w280 h30 , Select stream to open.
  106.     Gui, Add, Button, x108 y107 w150 h30 , Launch Livestreamer
  107.     ; Generated using SmartGUI Creator 4.0
  108.     Gui, Show, h162 w371, Livestreamer GUI
  109.     Return
  110. }
  111. else if !foundone
  112. {
  113.     MsgBox, No streams found online
  114.     ExitApp
  115. }
  116.  
  117. ButtonLaunchLivestreamer:
  118.     Gui, Submit
  119.     Run %comspec% /c livestreamer %selectedstream% best,,Hide
  120.     ExitApp
  121. return
  122.  
  123. GuiClose:
  124. GuiEscape:
  125.     Gui, Destroy
  126.     ExitApp
  127. return
Add Comment
Please, Sign In to add comment