Guest User

Livestreamer.ahk

a guest
Feb 17th, 2014
215
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.0
  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. */
  12.  
  13.  
  14. #Include %A_ScriptDir%
  15. #Include json.ahk ;https://raw2.github.com/cocobelgica/AutoHotkey-JSON/master/JSON.ahk
  16. #Persistent
  17.  
  18. variablefiledir := A_ScriptDir . "\jsonfiles"
  19. variablefile := variablefiledir . "\stream"
  20. favoritestreams = tsm_TheOddOne|TSM_Dyrus|TSM_Reginald|TSM_Bjergsen|Trick2g|imaqtpie|PhantomL0rd|tsm_wildturtle|riotgames|DanDihn|Westrice|TSM_Xpecial
  21.  
  22. Loop, Parse, favoritestreams, |
  23. {
  24.     if streams
  25.         streams := streams . "|twitch.tv/" . A_LoopField
  26.     else
  27.         streams := "twitch.tv/" . A_LoopField
  28. }
  29.  
  30. ;Launch Livestreamer GUI with valid streams
  31. *PrintScreen::
  32. {
  33.     FileRemoveDir, %variablefiledir%, 1
  34.     FileCreateDir, %variablefiledir%
  35.     checkstreams := streams
  36.     validstreams :=
  37.     haystack := Clipboard
  38.     needle := "^(?:https?:\/\/)?(?:www\.)?((?:(?:twitch\.tv\/)|(?:youtube\.com\/))\S+?)(?:\d\ds)?$"
  39.     matched := RegExMatch(haystack, needle, URL)
  40.     if matched
  41.         checkstreams := URL1 . "|" . streams
  42.     Loop, Parse, checkstreams, |
  43.     {
  44.         jsonfile := variablefile . A_Index . ".json"
  45.         Run %comspec% /c livestreamer -j %A_LoopField% best > "%jsonfile%" ,,Hide, PID%A_Index%
  46.     }
  47.     Loop, Parse, checkstreams, |
  48.     {
  49.         jsonfile := variablefile . A_Index . ".json"
  50.         Process, WaitClose, % PID%A_Index%
  51.         FileRead, Contents, %jsonfile%
  52.         if not ErrorLevel
  53.         {
  54.             j := JSON.parse(Contents)
  55.             if not j.error
  56.                 if validstreams
  57.                     validstreams := validstreams . "|" . A_LoopField
  58.                 else
  59.                     validstreams := A_LoopField
  60.         }
  61.     }
  62.     FileRemoveDir, %variablefiledir%, 1
  63.     if validstreams
  64.     {
  65.         Gui, Add, DropDownList, x43 y57 w280 h21 r10 vselectedstream +Choose1, %validstreams%
  66.         Gui, Add, Text, x43 y17 w280 h30 , Select stream to open.
  67.         Gui, Add, Button, x108 y107 w150 h30 , Launch Livestreamer
  68.         ; Generated using SmartGUI Creator 4.0
  69.         Gui, Show, h162 w371, Livestreamer GUI
  70.         Return
  71.  
  72.         ButtonLaunchLivestreamer:
  73.             Gui, Submit
  74.             Run %comspec% /c livestreamer %selectedstream% best,,Hide
  75.         return
  76.  
  77.         GuiClose:
  78.         GuiEscape:
  79.             Gui, Destroy
  80.         return
  81.     }
  82. }
  83. return
  84.  
  85. ;Check for valid streams and launch the first valid one in our list
  86. *ScrollLock::
  87. {
  88.     FileRemoveDir, %variablefiledir%, 1
  89.     FileCreateDir, %variablefiledir%
  90.     checkstreams := streams
  91.     validstreams :=
  92.     haystack := Clipboard
  93.     needle := "^(?:https?:\/\/)?(?:www\.)?((?:(?:twitch\.tv\/)|(?:youtube\.com\/))\S+?)(?:\d\ds)?$"
  94.     matched := RegExMatch(haystack, needle, URL)
  95.     if matched
  96.         checkstreams := URL1 . "|" . streams
  97.     Loop, Parse, checkstreams, |
  98.     {
  99.         jsonfile := variablefile . A_Index . ".json"
  100.         Run %comspec% /c livestreamer -j %A_LoopField% best > "%jsonfile%" ,,Hide, PID%A_Index%
  101.     }
  102.     Loop, Parse, checkstreams, |
  103.     {
  104.         jsonfile := variablefile . A_Index . ".json"
  105.         Process, WaitClose, % PID%A_Index%
  106.         FileRead, Contents, %jsonfile%
  107.         if not ErrorLevel
  108.         {
  109.             j := JSON.parse(Contents)
  110.             if not j.error
  111.                 {
  112.                     Run %comspec% /c livestreamer %A_LoopField% best,,Hide
  113.                     break
  114.                 }
  115.         }
  116.     }
  117.     FileRemoveDir, %variablefiledir%, 1
  118. }
  119. return
Add Comment
Please, Sign In to add comment