Advertisement
AnarchyOnline

Twitch.xys 1.2

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