AnarchyOnline

Twitch.xys 2.0

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