Advertisement
AnarchyOnline

Twitch.xys 0.5.5

Jun 6th, 2013
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 10.01 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.  // Configuration keys
  12.  global $g_ScriptVersion;
  13.  $g_ScriptVersion = '0.6';
  14.  
  15.  global $g_Vlc;
  16.  global $g_Rtmp;
  17.  global $g_User;
  18.  
  19.  if (exists("$g_ConfigurationFile") == '1' && $g_ScriptVersion == getkey('ScriptVersion', 'Configuration', "$g_ConfigurationFile", )){
  20.  
  21.   // Load keys
  22.   $g_Vlc = getkey ('Vlc', 'Configuration', "$g_ConfigurationFile", );
  23.   $g_Rtmp = getkey ('Rtmp', 'Configuration', "$g_ConfigurationFile", );
  24.   $g_User = getkey ('User', 'Configuration', "$g_ConfigurationFile", );
  25.  
  26.  } else {
  27.   msg <<<#
  28. Script is not configured.
  29. The configuration wizard will assist you.
  30. #;
  31.  
  32.  sub "_Configure";
  33.  }
  34.  }
  35.  
  36. "_Configure"
  37.  {
  38.  global $g_ConfigurationFile;
  39.  
  40.  msg <<<#
  41. 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.
  42.  
  43. The configuration file is located at:
  44.  
  45. $g_ConfigurationFile
  46. #;
  47.  
  48.  // Delete old configuration file
  49.  delete (0, 0, "$g_ConfigurationFile");
  50.  
  51.  // Define parameters
  52.  global $g_ScriptVersion;
  53.  global $g_Vlc;
  54.  global $g_Downloads;
  55.  
  56.  $g_Vlc = inputfile ('C:\', 'exe', 'Select vlc.exe');
  57. $g_Rtmp = inputfile ('C:\', 'exe', 'Select rtmp.exe');
  58. $g_User = input ('Enter your Twitch.tv user name');
  59.  
  60. // Write configuration to disk
  61. $Configuration = <<<#
  62. [Configuration]
  63. ScriptVersion=$g_ScriptVersion
  64. Vlc=$g_Vlc
  65. Rtmp=$g_Rtmp
  66. User=$g_User
  67.  
  68. [RecentlyWatched]
  69. Count=0
  70. #;
  71.  
  72. writefile ("$g_ConfigurationFile", "$Configuration", o, t);
  73.  
  74. msg <<<#
  75. Configuration completed.
  76. #;
  77. }
  78.  
  79. "Show 50 Top Games"
  80. {
  81. global $g_A;
  82.  
  83. global $g_Games;
  84. sub "_API-Games-Get-Top";
  85.  
  86. global $g_SelectedGame;
  87. $g_SelectedGame = inputselect("[$g_A] Games are listed based on viewer count", "$g_Games", "|", "0", , "200","500", );
  88.  
  89. global $g_Channels;
  90. global $g_SelectedChannel;
  91. sub "_API-Channels-Get-Game";
  92. $g_SelectedChannel = inputselect("[$g_A] Channels are listed based on viewer count", "$g_Channels", "|", "0", , "200", "500", );
  93.  
  94. global $g_UsherXml;
  95. sub "_USHER-XML-Get";
  96.  
  97. global $g_Qualities;
  98. global $g_SelectedQuality;
  99. sub "_USHER-XML-Get-Qualities";
  100. $g_SelectedQuality = inputselect("[$g_A] $g_SelectedChannel", "$g_Qualities", "|", "0", , "200", "500", );
  101.  
  102. global $g_Connect;
  103. global $g_Play;
  104. global $g_Token;
  105. sub "_USHER-Qualities-Param";
  106.  
  107. global $g_RunCmd;
  108. sub "_PARSE-Construct";
  109.  
  110. writefile ("<xyscripts>\TwitchTV.bat", "$g_RunCmd<crlf>del ""<xyscripts>\TwitchTV.bat""", "o", "t");
  111. run ("<xyscripts>\TwitchTV.bat", , 0, 0);
  112.  
  113. sub "_Add-Recently-Played";
  114. }
  115.  
  116. "Show 100 Top Channels"
  117. {
  118. global $g_A;
  119.  
  120. global $g_Channels;
  121. global $g_SelectedChannel;
  122. sub "_API-Channels-Get-All";
  123. $g_SelectedChannel = inputselect("[$g_A] Channels are listed based on viewer count", "$g_Channels", "|", "0", , "200", "500", );
  124.  
  125. global $g_UsherXml;
  126. sub "_USHER-XML-Get";
  127.  
  128. global $g_Qualities;
  129. global $g_SelectedQuality;
  130. sub "_USHER-XML-Get-Qualities";
  131. $g_SelectedQuality = inputselect("[$g_A] $g_SelectedChannel", "$g_Qualities", "|", "0", , "200", "500", );
  132.  
  133. global $g_Connect;
  134. global $g_Play;
  135. global $g_Token;
  136. sub "_USHER-Qualities-Param";
  137.  
  138. global $g_RunCmd;
  139. sub "_PARSE-Construct";
  140.  
  141. writefile ("<xyscripts>\TwitchTV.bat", "$g_RunCmd<crlf>del ""<xyscripts>\TwitchTV.bat""", "o", "t");
  142. run ("<xyscripts>\TwitchTV.bat", , 0, 0);  
  143.  
  144. sub "_Add-Recently-Played";
  145. }
  146.  
  147. "Show Followed Channels"
  148. {
  149. global $g_A;
  150.  
  151. global $g_Channels;
  152. global $g_SelectedChannel;
  153. sub "_API-Channels-Get-Followed";
  154. //sub "_API-Channels-Get-Followed-Status";
  155.  
  156. $g_SelectedChannel = inputselect("[$g_A] Channels are listed randomly", "$g_Channels", "|", "0", , "200", "500", );
  157.  
  158. global $g_UsherXml;
  159. sub "_USHER-XML-Get";
  160.  
  161. global $g_Qualities;
  162. global $g_SelectedQuality;
  163. sub "_USHER-XML-Get-Qualities";
  164. $g_SelectedQuality = inputselect("[$g_A] $g_SelectedChannel", "$g_Qualities", "|", "0", , "200", "500", );
  165.  
  166. global $g_Connect;
  167. global $g_Play;
  168. global $g_Token;
  169. sub "_USHER-Qualities-Param";
  170.  
  171. global $g_RunCmd;
  172. sub "_PARSE-Construct";
  173.  
  174. writefile ("<xyscripts>\TwitchTV.bat", "$g_RunCmd<crlf>del ""<xyscripts>\TwitchTV.bat""", "o", "t");
  175. run ("<xyscripts>\TwitchTV.bat", , 0, 0);  
  176.  
  177. sub "_Add-Recently-Played";
  178. }
  179.  
  180. "Enter Channel Name"
  181. {
  182. global $g_A;
  183.  
  184. global $g_SelectedChannel;
  185. $g_SelectedChannel = input ("Type the channel name as it appears in the Twitch.tv URL", , "towelliee", "s", , , );
  186.  
  187. global $g_UsherXml;
  188. sub "_USHER-XML-Get";
  189.  
  190. global $g_Qualities;
  191. global $g_SelectedQuality;
  192. sub "_USHER-XML-Get-Qualities";
  193. $g_SelectedQuality = inputselect("[$g_A] $g_SelectedChannel", "$g_Qualities", "|", "0", , "200", "500", );
  194.  
  195. global $g_Connect;
  196. global $g_Play;
  197. global $g_Token;
  198. sub "_USHER-Qualities-Param";
  199.  
  200. global $g_RunCmd;
  201. sub "_PARSE-Construct";
  202.  
  203. writefile ("<xyscripts>\TwitchTV.bat", "$g_RunCmd<crlf>del ""<xyscripts>\TwitchTV.bat""", o, t);
  204. run ("<xyscripts>\TwitchTV.bat", , 0, 0);
  205.  
  206. sub "_Add-Recently-Played";
  207. }
  208.  
  209. "_API-Games-Get-Top"
  210. {
  211. global $g_Games;
  212.  
  213. global $g_A;
  214. global $g_Url;
  215. global $g_Return;
  216.  
  217. $g_Url = 'https://api.twitch.tv/kraken/games/top?limit=50';
  218.  sub "_ReadUrl-Loop";
  219.  $APIGames = $g_Return;
  220.  
  221.  $RegEx = '["][A-Z0-9][^"]*["]';
  222.  $g_Games = regexmatches($APIGames, $RegEx, '|', 1);
  223.  $g_Games = formatlist ($g_Games, 'u', '|', );
  224.  }
  225.  
  226. "_API-Channels-Get-Game"
  227.  {
  228.  global $g_SelectedGame;
  229.  global $g_Channels;
  230.  
  231.  global $g_A;
  232.  global $g_Url;
  233.  global $g_Return;
  234.  
  235.  $g_SelectedGame = urlencode ($g_SelectedGame, 1);
  236.  $g_SelectedGame = replace ($g_SelectedGame, ':', '%3A', , );
  237.  
  238.  $g_Url = "https://api.twitch.tv/kraken/streams?game=$g_SelectedGame";
  239.  sub "_ReadUrl-Loop";
  240.  $APIChannels = $g_Return;
  241.  
  242.  $RegEx = '["]url["]:["][^"]+["]';
  243.  $g_Channels = regexmatches ($APIChannels, $RegEx, |, 0);
  244.  $g_Channels = formatlist ($g_Channels, 'u', '|', );  
  245.  $g_Channels = replace ($g_Channels, 'url":"http://www.twitch.tv/', , , );
  246.  }
  247.  
  248. "_API-Channels-Get-All"
  249.  {
  250.  global $g_Channels;
  251.  
  252.  global $g_A;
  253.  global $g_Url;
  254.  global $g_Return;
  255.  
  256.  $g_Url = 'https://api.twitch.tv/kraken/streams';
  257.  sub "_ReadUrl-Loop";
  258.  $APIChannels = $g_Return;
  259.  
  260.  $RegEx = '["]url["]:["][^"]+["]';
  261.  $g_Channels = regexmatches ($APIChannels, $RegEx, |, 0);
  262.  $g_Channels = formatlist ($g_Channels, u, |, );  
  263.  $g_Channels = replace ($g_Channels, 'url":"http://www.twitch.tv/', , , );
  264.  }
  265.  
  266. "_API-Channels-Get-Followed"
  267.  {
  268.  global $g_User;
  269.  global $g_Channels;
  270.  
  271.  global $g_A;
  272.  global $g_Url;
  273.  global $g_Return;
  274.  
  275.  $g_Url = "https://api.twitch.tv/kraken/users/$g_User/follows/channels?limit=50";
  276.  sub "_ReadUrl-Loop";
  277.  $APIChannels = $g_Return;
  278.  
  279.  $regEx = "[""]url[""]:[""][^""]+[""]";
  280.  $g_Channels = regexmatches ($APIChannels, $regEx, "|", "1");
  281.  $g_Channels = formatlist ($g_Channels, "u", "|", );  
  282.  $g_Channels = replace ($g_Channels, 'url":"http://www.twitch.tv/', , , );
  283.  }
  284.  
  285. "_API-Channels-Get-Followed-Status"
  286.  {
  287.  global $g_Channels;
  288.  $List = '';
  289.  
  290.  foreach ($Channel, $g_Channels, "|"){
  291.   $g_Url = "https://api.twitch.tv/kraken/streams/$Channel";
  292.   sub "_ReadUrl-Loop";
  293.   $Data = $g_Return;
  294.    if (regexmatches($Data, '"stream":null,', "", "0")){
  295.    } else {$List = $List.$Channel."|";}
  296.  }
  297.  $g_Channels = $List;
  298.  formatlist ($g_Channels, e, |, );
  299.  }
  300.  
  301. "_USHER-XML-Get"
  302.  {
  303.  global $g_SelectedChannel;
  304.  global $g_UsherXml;
  305.  
  306.  global $g_A;
  307.  global $g_Url;
  308.  global $g_Return;
  309.  
  310.  $g_Url = "http://usher.twitch.tv/find/$g_SelectedChannel.xml?type=any";
  311.  sub "_ReadUrl-Loop";
  312.  $g_UsherXml = $g_Return;  
  313.  }
  314.  
  315. "_USHER-XML-Get-Qualities"
  316.  {
  317.  global $g_UsherXml;
  318.  global $g_Qualities;
  319.    
  320.  $RegEx = '<live>|<1080p>|<720p>|<480p>|<360p>|<iphonehigh>|<iphonelow>';
  321.  $g_Qualities = regexmatches ($g_UsherXml, $RegEx, |, 0);
  322.  $g_Qualities = replacelist ($g_Qualities, '<>');
  323.  }
  324.  
  325. "_USHER-Qualities-Param"
  326.  {
  327.  global $g_UsherXml;
  328.  global $g_Qualities;
  329.  global $g_SelectedQuality;
  330.  
  331.  global $g_Connect;
  332.  global $g_Play;
  333.  global $g_Token;
  334.  
  335.  $RegEx = "<$g_SelectedQuality>.+<\/$g_SelectedQuality>";
  336.  $Data = regexmatches ($g_UsherXml, $RegEx, |, 0);
  337.  
  338.  $RegEx = "<connect>.+<\/connect>";
  339.  $g_Connect = regexmatches ($Data, $RegEx, |, 0);
  340.  $g_Connect = replacelist ($g_Connect, "<connect>,</connect>", , ',');
  341.  
  342.  $RegEx = "<play>.+<\/play>";
  343.  $g_Play = regexmatches ($Data, $RegEx, |, 0);
  344.  $g_Play = replacelist ($g_Play, "<play>,</play>", , ',');
  345.  
  346.  $RegEx = "<token>.+<\/token>";
  347.  $g_Token = regexmatches ($Data, $RegEx, |, 0);
  348.  $g_Token = replacelist ($g_Token, "<token>,</token>", , ',');  
  349.  }
  350.  
  351. "_PARSE-Construct"
  352.  {
  353.  global $g_Rtmp;
  354.  global $g_Vlc;
  355.  global $g_SelectedChannel;
  356.  
  357.  global $g_Connect;
  358.  global $g_Play;
  359.  global $g_Token;
  360.  
  361.  global $g_RunCmd;
  362.  
  363.  $Swf = "http://www-cdn.jtvnw.net/widgets/live_embed_player.r0115b78b21bb98fce53f2221edac6932395f8a59.swf?channel=$g_SelectedChannel&referer=&userAgent=&channel=$g_SelectedChannel";
  364.  $g_Token = replace ($g_Token, '"', '\"', , );
  365.  
  366.  //$g_RunCmd = """$g_Rtmp"" -r ""$g_Connect/$g_Play"" -j ""$g_Token"" --swfVfy ""$Swf"" -v -o - | ""$g_Vlc"" -";
  367.  $g_RunCmd = """$g_Rtmp"" -r ""$g_Connect/$g_Play"" --swfVfy ""$Swf"" -v -o - | ""$g_Vlc"" -";
  368.  }
  369.  
  370. "_ReadUrl-Loop"
  371.  {
  372.  global $g_A;
  373.  global $g_Url;
  374.  global $g_Return;
  375.  
  376.  $g_A = '0';
  377.  $g_Return = '';
  378.  
  379.  while(strlen($g_Return) < '25'){
  380.   $g_Return = readurl($g_Url, 0, 0, );
  381.   $g_A++;
  382.   if(strlen($g_Return) > '25'){
  383.    break;
  384.   }
  385.  }
  386.  }
  387.  
  388. "_Add-Recently-Played"
  389.  {
  390.  global $g_ConfigurationFile;
  391.  global $g_SelectedChannel;
  392.  
  393.  $Count = getkey ('Count', 'RecentlyWatched', $g_ConfigurationFile, );
  394.  $Count++;
  395.  setkey ($Count, Count, 'RecentlyWatched', $g_ConfigurationFile, );
  396.  setkey ($g_SelectedChannel, $Count, 'RecentlyWatched', $g_ConfigurationFile, );
  397.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement