Advertisement
AnarchyOnline

Twitch.xys 1.1

Jun 24th, 2013
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 11.90 KB | None | 0 0
  1. "_Initialize"
  2.  {
  3.  // Configuration .ini file
  4.  global $g_ConfigurationFile;
  5.  $g_ConfigurationFile = "<xyscripts>\Twitch.ini";
  6.  
  7.  // Execution and buffer files
  8.  global $g_ExecutionFile;
  9.  $g_ExecutionFile = "<xyscripts>\Twitch.bat";
  10.  
  11.  global $g_ExecutionFileVBS;
  12.  $g_ExecutionFileVBS = "<xyscripts>\Twitch.vbs";
  13.  
  14.  global $g_LocationFileSWF;
  15.  $g_LocationFileSWF = "<xyscripts>\Twitch.swf";
  16.  
  17.  // Configuration keys
  18.  global $g_ScriptVersion;
  19.  $g_ScriptVersion = '1.0';
  20.  
  21.  global $g_Vlc;
  22.  global $g_Rtmp;
  23.  global $g_User;
  24.  
  25.  if (exists("$g_ConfigurationFile") == '1' && $g_ScriptVersion == getkey('ScriptVersion', 'Configuration', "$g_ConfigurationFile", )){
  26.  
  27.   // Load keys
  28.   $g_Vlc = getkey ('Vlc', 'Configuration', "$g_ConfigurationFile", );
  29.   $g_Rtmp = getkey ('Rtmp', 'Configuration', "$g_ConfigurationFile", );
  30.   $g_User = getkey ('User', 'Configuration', "$g_ConfigurationFile", );
  31.  
  32.  } else {
  33.   msg <<<#
  34. Script is not configured.
  35. The configuration wizard will assist you.
  36. #;
  37.  
  38.  sub "_Configure";
  39.  }
  40.  }
  41.  
  42. "_Configure"
  43.  {
  44.  global $g_ConfigurationFile;
  45.  
  46.  msg <<<#
  47. This wizard configures the script for first use. To edit the configuration file click "Edit Configuration" after launching the script. If the configuration file is not found or you upgrade to a new version of this script the wizard will appear automatically.
  48.  
  49. The configuration file is located at:
  50.  
  51. $g_ConfigurationFile
  52.  
  53. Steps:
  54. 1. Select vlc.exe
  55. 2. Select rtmpdump.exe
  56. 3. Enter your Twitch user name (Leave blank if none)
  57.  
  58. Done!
  59. #;
  60.  
  61.  // Delete old configuration file
  62.  delete (0, 0, "$g_ConfigurationFile");
  63.  
  64.  // Define parameters
  65.  global $g_ScriptVersion;
  66.  global $g_Vlc;
  67.  global $g_Rtmp;
  68.  global $g_User;
  69.  
  70.  $g_Vlc = inputfile ('C:\', 'exe', 'Select vlc.exe');
  71. $g_Rtmp = inputfile ('C:\', 'exe', 'Select rtmp.exe');
  72. $g_User = input ('Enter your Twitch.tv user name');
  73.  
  74. // Write configuration to disk
  75. $Configuration = <<<#
  76. [Configuration]
  77. ScriptVersion=$g_ScriptVersion
  78. Vlc=$g_Vlc
  79. Rtmp=$g_Rtmp
  80. User=$g_User
  81.  
  82. [RecentlyWatched]
  83. Count=0
  84. #;
  85.  
  86. writefile ("$g_ConfigurationFile", "$Configuration", o, t);
  87.  
  88. msg <<<#
  89. Configuration completed.
  90. #;
  91. }
  92.  
  93. "Show 50 Top Games"
  94. {
  95. global $g_A;
  96.  
  97. global $g_Games;
  98. sub "_API-Games-Get-Top";
  99.  
  100. global $g_SelectedGame;
  101. $g_SelectedGame = inputselect("[$g_A] Games are listed based on viewer count", "$g_Games", "|", "0", , "200","500", );
  102.  
  103. global $g_Channels;
  104. global $g_SelectedChannel;
  105. sub "_API-Channels-Get-Game";
  106. $g_SelectedChannel = inputselect("[$g_A] Channels are listed based on viewer count", "$g_Channels", "|", "0", , "200", "500", );
  107.  
  108. global $g_UsherXml;
  109. sub "_USHER-XML-Get";
  110.  
  111. global $g_Qualities;
  112. global $g_SelectedQuality;
  113. sub "_USHER-XML-Get-Qualities";
  114. $g_SelectedQuality = inputselect("[$g_A] $g_SelectedChannel", "$g_Qualities", "|", "0", , "200", "500", );
  115.  
  116. global $g_Connect;
  117. global $g_Play;
  118. global $g_Token;
  119. sub "_USHER-Qualities-Param";
  120.  
  121. global $g_RunCmd;
  122. sub "_PARSE-Construct";
  123.  
  124. global $g_ExecutionFile;
  125. writefile ("$g_ExecutionFile", "$g_RunCmd<crlf>del ""$g_ExecutionFile""", "o", "t");
  126. run ("$g_ExecutionFile", , 0, 1);
  127.  
  128. sub "_Add-Recently-Played";
  129. }
  130.  
  131. "Show 100 Top Channels"
  132. {
  133. global $g_A;
  134.  
  135. global $g_Channels;
  136. global $g_SelectedChannel;
  137. sub "_API-Channels-Get-All";
  138. $g_SelectedChannel = inputselect("[$g_A] Channels are listed based on viewer count", "$g_Channels", "|", "0", , "200", "500", );
  139.  
  140. global $g_UsherXml;
  141. sub "_USHER-XML-Get";
  142.  
  143. global $g_Qualities;
  144. global $g_SelectedQuality;
  145. sub "_USHER-XML-Get-Qualities";
  146. $g_SelectedQuality = inputselect("[$g_A] $g_SelectedChannel", "$g_Qualities", "|", "0", , "200", "500", );
  147.  
  148. global $g_Connect;
  149. global $g_Play;
  150. global $g_Token;
  151. sub "_USHER-Qualities-Param";
  152.  
  153. global $g_RunCmd;
  154. sub "_PARSE-Construct";
  155.  
  156. global $g_ExecutionFile;
  157. writefile ("$g_ExecutionFile", "$g_RunCmd<crlf>del ""$g_ExecutionFile""", "o", "t");
  158. run ("$g_ExecutionFile", , 0, 1);
  159.  
  160. sub "_Add-Recently-Played";
  161. }
  162.  
  163. "Show Followed Channels"
  164. {
  165. global $g_A;
  166.  
  167. global $g_Channels;
  168. global $g_SelectedChannel;
  169. sub "_API-Channels-Get-Followed";
  170.  
  171. $g_SelectedChannel = inputselect("[$g_A] Channels are listed randomly", "$g_Channels", "|", "0", , "200", "500", );
  172.  
  173. global $g_UsherXml;
  174. sub "_USHER-XML-Get";
  175.  
  176. global $g_Qualities;
  177. global $g_SelectedQuality;
  178. sub "_USHER-XML-Get-Qualities";
  179. $g_SelectedQuality = inputselect("[$g_A] $g_SelectedChannel", "$g_Qualities", "|", "0", , "200", "500", );
  180.  
  181. global $g_Connect;
  182. global $g_Play;
  183. global $g_Token;
  184. sub "_USHER-Qualities-Param";
  185.  
  186. global $g_RunCmd;
  187. sub "_PARSE-Construct";
  188.  
  189. global $g_ExecutionFile;
  190. writefile ("$g_ExecutionFile", "$g_RunCmd<crlf>del ""$g_ExecutionFile""", "o", "t");
  191. run ("$g_ExecutionFile", , 0, 1);
  192.  
  193. sub "_Add-Recently-Played";
  194. }
  195.  
  196. "Show Recently Watched"
  197. {
  198. global $g_ConfigurationFile;
  199. global $g_A;
  200. global $g_Channels;
  201.  
  202. $Count = getkey ('Count', 'RecentlyWatched', $g_ConfigurationFile, );
  203.  
  204. $a = '1';
  205. $g_Channels = '';
  206.  
  207. while ($a <= $Count){
  208. $g_Channels = $g_Channels.getkey ("$a", 'RecentlyWatched', $g_ConfigurationFile, ).'|';
  209. $a++;
  210. }
  211.  
  212. $g_Channels = formatlist ("$g_Channels", 'dev', '|', );
  213.  
  214. global $g_SelectedChannel;
  215. $g_SelectedChannel = inputselect("[$g_A] Channels are listed based when you watched them before", "$g_Channels", "|", "0", , "200", "500", );
  216.  
  217. global $g_UsherXml;
  218. sub "_USHER-XML-Get";
  219.  
  220. global $g_Qualities;
  221. global $g_SelectedQuality;
  222. sub "_USHER-XML-Get-Qualities";
  223. $g_SelectedQuality = inputselect("[$g_A] $g_SelectedChannel", "$g_Qualities", "|", "0", , "200", "500", );
  224.  
  225. global $g_Connect;
  226. global $g_Play;
  227. global $g_Token;
  228. sub "_USHER-Qualities-Param";
  229.  
  230. global $g_RunCmd;
  231. sub "_PARSE-Construct";
  232.  
  233. global $g_ExecutionFile;
  234. writefile ("$g_ExecutionFile", "$g_RunCmd<crlf>del ""$g_ExecutionFile""", "o", "t");
  235. run ("$g_ExecutionFile", , 0, 1);
  236.  
  237. sub "_Add-Recently-Played";
  238. }
  239.  
  240. "Enter Channel Name"
  241. {
  242. global $g_A;
  243.  
  244. global $g_SelectedChannel;
  245. $g_SelectedChannel = input ("Type the channel name as it appears in the Twitch.tv URL", , "towelliee", "s", , , );
  246.  
  247. global $g_UsherXml;
  248. sub "_USHER-XML-Get";
  249.  
  250. global $g_Qualities;
  251. global $g_SelectedQuality;
  252. sub "_USHER-XML-Get-Qualities";
  253. $g_SelectedQuality = inputselect("[$g_A] $g_SelectedChannel", "$g_Qualities", "|", "0", , "200", "500", );
  254.  
  255. global $g_Connect;
  256. global $g_Play;
  257. global $g_Token;
  258. sub "_USHER-Qualities-Param";
  259.  
  260. global $g_RunCmd;
  261. sub "_PARSE-Construct";
  262.  
  263. global $g_ExecutionFile;
  264. writefile ("$g_ExecutionFile", "$g_RunCmd<crlf>del ""$g_ExecutionFile""", "o", "t");
  265. run ("$g_ExecutionFile", , 0, 1);
  266.  
  267. sub "_Add-Recently-Played";
  268. }
  269.  
  270. "Edit Configuration"
  271. {
  272. global $g_ConfigurationFile;
  273.  
  274. run ('notepad "'.$g_ConfigurationFile.'"', , '0', '1');
  275. }
  276.  
  277. "_API-Games-Get-Top"
  278. {
  279. global $g_Games;
  280.  
  281. global $g_A;
  282. global $g_Url;
  283. global $g_Return;
  284.  
  285. $g_Url = 'https://api.twitch.tv/kraken/games/top?limit=50';
  286.  sub "_ReadUrl-Loop";
  287.  $APIGames = $g_Return;
  288.  
  289.  $RegEx = '["][A-Z0-9][^"]*["]';
  290.  $g_Games = regexmatches($APIGames, $RegEx, '|', 1);
  291.  $g_Games = formatlist ($g_Games, 'u', '|', );
  292.  }
  293.  
  294. "_API-Channels-Get-Game"
  295.  {
  296.  global $g_SelectedGame;
  297.  global $g_Channels;
  298.  
  299.  global $g_A;
  300.  global $g_Url;
  301.  global $g_Return;
  302.  
  303.  $g_SelectedGame = urlencode ($g_SelectedGame, 1);
  304.  $g_SelectedGame = replace ($g_SelectedGame, ':', '%3A', , );
  305.  
  306.  $g_Url = "https://api.twitch.tv/kraken/streams?game=$g_SelectedGame";
  307.  sub "_ReadUrl-Loop";
  308.  $APIChannels = $g_Return;
  309.  
  310.  $RegEx = '["]url["]:["][^"]+["]';
  311.  $g_Channels = regexmatches ($APIChannels, $RegEx, |, 0);
  312.  $g_Channels = formatlist ($g_Channels, 'u', '|', );  
  313.  $g_Channels = replace ($g_Channels, 'url":"http://www.twitch.tv/', , , );
  314.  }
  315.  
  316. "_API-Channels-Get-All"
  317.  {
  318.  global $g_Channels;
  319.  
  320.  global $g_A;
  321.  global $g_Url;
  322.  global $g_Return;
  323.  
  324.  $g_Url = 'https://api.twitch.tv/kraken/streams?limit=100';
  325.  sub "_ReadUrl-Loop";
  326.  $APIChannels = $g_Return;
  327.  
  328.  $RegEx = '["]url["]:["][^"]+["]';
  329.  $g_Channels = regexmatches ($APIChannels, $RegEx, |, 0);
  330.  $g_Channels = formatlist ($g_Channels, u, |, );  
  331.  $g_Channels = replace ($g_Channels, 'url":"http://www.twitch.tv/', , , );
  332.  }
  333.  
  334. "_API-Channels-Get-Followed"
  335.  {
  336.  global $g_User;
  337.  global $g_Channels;
  338.  
  339.  global $g_A;
  340.  global $g_Url;
  341.  global $g_Return;
  342.  
  343.  $g_Url = "https://api.twitch.tv/kraken/users/$g_User/follows/channels?limit=50";
  344.  sub "_ReadUrl-Loop";
  345.  $APIChannels = $g_Return;
  346.  
  347.  $regEx = "[""]url[""]:[""][^""]+[""]";
  348.  $g_Channels = regexmatches ($APIChannels, $regEx, "|", "1");
  349.  $g_Channels = formatlist ($g_Channels, "u", "|", );  
  350.  $g_Channels = replace ($g_Channels, 'url":"http://www.twitch.tv/', , , );
  351.  }
  352.  
  353. "_API-Channels-Get-Followed-Status"
  354.  {
  355.  global $g_Channels;
  356.  $List = '';
  357.  
  358.  foreach ($Channel, $g_Channels, "|"){
  359.   $g_Url = "https://api.twitch.tv/kraken/streams/$Channel";
  360.   sub "_ReadUrl-Loop";
  361.   $Data = $g_Return;
  362.    if (regexmatches($Data, '"stream":null,', "", "0")){
  363.    } else {$List = $List.$Channel."|";}
  364.  }
  365.  $g_Channels = $List;
  366.  formatlist ($g_Channels, e, |, );
  367.  }
  368.  
  369. "_USHER-XML-Get"
  370.  {
  371.  global $g_SelectedChannel;
  372.  global $g_UsherXml;
  373.  
  374.  global $g_A;
  375.  global $g_Url;
  376.  global $g_Return;
  377.  
  378.  $g_Url = "http://usher.twitch.tv/find/$g_SelectedChannel.xml?type=any";
  379.  sub "_ReadUrl-Loop";
  380.  $g_UsherXml = $g_Return;  
  381.  }
  382.  
  383. "_USHER-XML-Get-Qualities"
  384.  {
  385.  global $g_UsherXml;
  386.  global $g_Qualities;
  387.    
  388.  $RegEx = '<live>|<1080p>|<720p>|<480p>|<360p>|<iphonehigh>|<iphonelow>';
  389.  $g_Qualities = regexmatches ($g_UsherXml, $RegEx, |, 0);
  390.  $g_Qualities = replacelist ($g_Qualities, '<>');
  391.  }
  392.  
  393. "_USHER-Qualities-Param"
  394.  {
  395.  global $g_UsherXml;
  396.  global $g_Qualities;
  397.  global $g_SelectedQuality;
  398.  
  399.  global $g_Connect;
  400.  global $g_Play;
  401.  global $g_Token;
  402.  
  403.  $RegEx = "<$g_SelectedQuality>.+<\/$g_SelectedQuality>";
  404.  $Data = regexmatches ($g_UsherXml, $RegEx, |, 0);
  405.  
  406.  $RegEx = "<connect>.+<\/connect>";
  407.  $g_Connect = regexmatches ($Data, $RegEx, |, 0);
  408.  $g_Connect = replacelist ($g_Connect, "<connect>,</connect>", , ',');
  409.  
  410.  $RegEx = "<play>.+<\/play>";
  411.  $g_Play = regexmatches ($Data, $RegEx, |, 0);
  412.  $g_Play = replacelist ($g_Play, "<play>,</play>", , ',');
  413.  
  414.  $RegEx = "<token>.+<\/token>";
  415.  $g_Token = regexmatches ($Data, $RegEx, |, 0);
  416.  $g_Token = replacelist ($g_Token, "<token>,</token>,""", ',,\"' , ',');  
  417.  }
  418.  
  419. "_PARSE-Construct"
  420.  {
  421.  global $g_Rtmp;
  422.  global $g_Vlc;
  423.  global $g_SelectedChannel;
  424.  
  425.  global $g_Connect;
  426.  global $g_Play;
  427.  global $g_Token;
  428.  
  429.  global $g_RunCmd;
  430.  global $g_ExecutionFileVBS;
  431.  global $g_LocationFileSWF;
  432.  
  433.  $VisualBasicScript = <<<#
  434.  Dim req
  435. Set req = CreateObject("WinHttp.WinHttpRequest.5.1")
  436.  
  437. req.Option(6) = False ' No redirects'
  438.  
  439. req.open "GET", "http://www-cdn.jtvnw.net/widgets/live_embed_player.swf", False
  440. req.send
  441.  
  442. Set fs = CreateObject("Scripting.FileSystemObject")
  443. Set a = fs.CreateTextFile("$g_LocationFileSWF", True)
  444. a.WriteLine(req.getResponseHeader("Location"))
  445. a.Close
  446. #;
  447.  
  448.  writefile ("$g_ExecutionFileVBS", "$VisualBasicScript", 'o', 't');
  449.  run ('cscript "'.$g_ExecutionFileVBS.'"', , '2', '0');
  450.  
  451.  $Swf = readfile ("$g_LocationFileSWF", 't', , , );
  452.  $Swf = regexmatches ("$Swf", 'http(.+).swf', '|', '0');
  453.  
  454.  delete ('0', '0', "$g_LocationFileSWF");
  455.  delete ('0', '0', "$g_ExecutionFileVBS");
  456.  
  457.  $g_RunCmd = '"'.$g_Rtmp.'" -r "'.$g_Connect.'/'.$g_Play.'" -j "'.$g_Token.'" --swfVfy "'.$Swf.'" -v -o - | "'.$g_Vlc.'" -';
  458.  }
  459.  
  460. "_ReadUrl-Loop"
  461.  {
  462.  global $g_A;
  463.  global $g_Url;
  464.  global $g_Return;
  465.  
  466.  $g_A = '0';
  467.  $g_Return = '';
  468.  
  469.  $g_Return = readurl($g_Url, 0, 0, );
  470.  }
  471.  
  472. "_Add-Recently-Played"
  473.  {
  474.  global $g_ConfigurationFile;
  475.  global $g_SelectedChannel;
  476.  
  477.  $Count = getkey ('Count', 'RecentlyWatched', $g_ConfigurationFile, );
  478.  $Count++;
  479.  setkey ($Count, Count, 'RecentlyWatched', $g_ConfigurationFile, );
  480.  setkey ($g_SelectedChannel, $Count, 'RecentlyWatched', $g_ConfigurationFile, );
  481.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement