Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**************************************************************
- * Twitch.xys 1.2
- * Released: 05/07/2013
- *
- * For all information check the forum thread:
- * http://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=9307
- **************************************************************/
- "_Initialize"
- {
- // Configuration .ini file
- global $g_ConfigurationFile;
- $g_ConfigurationFile = "<xyscripts>\Twitch.ini";
- // Execution and buffer files
- global $g_ExecutionFile;
- $g_ExecutionFile = "<xyscripts>\Twitch.bat";
- delete (0, 0, $g_ExecutionFile);
- global $g_ExecutionFileVBS;
- $g_ExecutionFileVBS = "<xyscripts>\Twitch.vbs";
- delete (0, 0, $g_ExecutionFileVBS);
- global $g_LocationFileSWF;
- $g_LocationFileSWF = "<xyscripts>\Twitch.swf";
- delete (0, 0, $g_LocationFileSWF);
- // Configuration keys
- global $g_ScriptVersion;
- $g_ScriptVersion = '1.2';
- global $g_Vlc;
- global $g_Rtmp;
- global $g_User;
- if (exists($g_ConfigurationFile) == '1' && $g_ScriptVersion == getkey('ScriptVersion', 'Configuration', $g_ConfigurationFile, )){
- // Load keys
- $g_Vlc = getkey ('Vlc', 'Configuration', $g_ConfigurationFile, );
- $g_Rtmp = getkey ('Rtmp', 'Configuration', $g_ConfigurationFile, );
- $g_User = getkey ('User', 'Configuration', $g_ConfigurationFile, );
- } else {
- msg <<<#
- Script is not configured.
- The configuration wizard will assist you.
- #;
- sub "_Configure";
- }
- }
- "_Configure"
- {
- global $g_ConfigurationFile;
- msg <<<#
- 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.
- The configuration file is located at:
- $g_ConfigurationFile
- Steps:
- 1. Select vlc.exe
- 2. Select rtmpdump.exe
- 3. Enter your Twitch user name (Leave blank if none)
- Done!
- #;
- // Delete old configuration file
- delete (0, 0, $g_ConfigurationFile);
- // Define parameters
- global $g_ScriptVersion;
- global $g_Vlc;
- global $g_Rtmp;
- global $g_User;
- $g_Vlc = inputfile ('C:\', 'exe', 'Select vlc.exe');
- $g_Rtmp = inputfile ('C:\', 'exe', 'Select rtmp.exe');
- $g_User = input ('Enter your Twitch.tv user name');
- // Write configuration to disk
- $Configuration = <<<#
- [Configuration]
- ScriptVersion=$g_ScriptVersion
- Vlc=$g_Vlc
- Rtmp=$g_Rtmp
- User=$g_User
- [RecentlyWatched]
- Count=0
- #;
- writefile ($g_ConfigurationFile, $Configuration, o, t);
- msg <<<#
- Configuration completed.
- #;
- }
- "Show 50 Top Games"
- {
- global $g_Games;
- sub "_API-Games-Get-Top";
- global $g_SelectedGame;
- $g_SelectedGame = inputselect('Games are listed based on viewer count', $g_Games, |, 0, , 200, 500, );
- global $g_Channels;
- global $g_SelectedChannel;
- sub "_API-Channels-Get-Game";
- $g_SelectedGame = urldecode ($g_SelectedGame, 0);
- $g_SelectedChannel = inputselect("$g_SelectedGame<crlf>Channels are listed based on viewer count", $g_Channels, |, 0, , 200, 500, );
- global $g_UsherXml;
- sub "_USHER-XML-Get";
- global $g_Qualities;
- global $g_SelectedQuality;
- sub "_USHER-XML-Get-Qualities";
- $g_SelectedQuality = inputselect($g_SelectedChannel, $g_Qualities, |, 0, , 200, 500, );
- global $g_Connect;
- global $g_Play;
- global $g_Token;
- sub "_USHER-Qualities-Param";
- global $g_RunCmd;
- sub "_PARSE-Construct";
- global $g_ExecutionFile;
- writefile ($g_ExecutionFile, "$g_RunCmd<crlf>".'del "'.$g_ExecutionFile.'"', o, t);
- run ($g_ExecutionFile, , 0, 1);
- sub "_Add-Recently-Played";
- }
- "Show 100 Top Channels"
- {
- global $g_Channels;
- global $g_SelectedChannel;
- sub "_API-Channels-Get-All";
- $g_SelectedChannel = inputselect('Channels are listed based on viewer count', $g_Channels, |, 0, , 200, 500, );
- global $g_UsherXml;
- sub "_USHER-XML-Get";
- global $g_Qualities;
- global $g_SelectedQuality;
- sub "_USHER-XML-Get-Qualities";
- $g_SelectedQuality = inputselect($g_SelectedChannel, $g_Qualities, |, 0, , 200, 500, );
- global $g_Connect;
- global $g_Play;
- global $g_Token;
- sub "_USHER-Qualities-Param";
- global $g_RunCmd;
- sub "_PARSE-Construct";
- global $g_ExecutionFile;
- writefile ($g_ExecutionFile, "$g_RunCmd<crlf>".'del "'.$g_ExecutionFile.'"', o, t);
- run ($g_ExecutionFile, , 0, 1);
- sub "_Add-Recently-Played";
- }
- "Show Followed Channels"
- {
- global $g_Channels;
- global $g_SelectedChannel;
- sub "_API-Channels-Get-Followed";
- sub "_API-Channels-Get-Status";
- $g_SelectedChannel = inputselect('Channels that you follow and are currently LIVE', $g_Channels, |, 0, , 200, 500, );
- global $g_UsherXml;
- sub "_USHER-XML-Get";
- global $g_Qualities;
- global $g_SelectedQuality;
- sub "_USHER-XML-Get-Qualities";
- $g_SelectedQuality = inputselect($g_SelectedChannel, $g_Qualities, |, 0, , 200, 500, );
- global $g_Connect;
- global $g_Play;
- global $g_Token;
- sub "_USHER-Qualities-Param";
- global $g_RunCmd;
- sub "_PARSE-Construct";
- global $g_ExecutionFile;
- writefile ($g_ExecutionFile, "$g_RunCmd<crlf>".'del "'.$g_ExecutionFile, o, t);
- run ($g_ExecutionFile, , 0, 1);
- sub "_Add-Recently-Played";
- }
- "Show Recently Watched"
- {
- global $g_ConfigurationFile;
- global $g_Channels;
- $Count = getkey ('Count', 'RecentlyWatched', $g_ConfigurationFile, );
- $a = '1';
- $g_Channels = '';
- while ($a <= $Count){
- $g_Channels = $g_Channels.getkey ($a, 'RecentlyWatched', $g_ConfigurationFile, ).'|';
- $a++;
- }
- // Copy variable with channels in most recent sorting before we send variable to status checker
- // Status checker changes $g_Channels value
- $g_Channels = formatlist ($g_Channels, dev, |, );
- $ChannelsMostRecent = $g_Channels;
- sub "_API-Channels-Get-Status";
- $g_Channels = regexmatches ($ChannelsMostRecent, $g_Channels, |, 0);
- global $g_SelectedChannel;
- $g_SelectedChannel = inputselect('Channels are listed based on most recently viewed.', $g_Channels, |, 0, , 200, 500, );
- global $g_UsherXml;
- sub "_USHER-XML-Get";
- global $g_Qualities;
- global $g_SelectedQuality;
- sub "_USHER-XML-Get-Qualities";
- $g_SelectedQuality = inputselect("$g_SelectedChannel", "$g_Qualities", "|", "0", , "200", "500", );
- global $g_Connect;
- global $g_Play;
- global $g_Token;
- sub "_USHER-Qualities-Param";
- global $g_RunCmd;
- sub "_PARSE-Construct";
- global $g_ExecutionFile;
- writefile ($g_ExecutionFile, "$g_RunCmd<crlf>".'del "'.$g_ExecutionFile, o, t);
- run ($g_ExecutionFile, , 0, 1);
- sub "_Add-Recently-Played";
- }
- "Enter Channel Name"
- {
- global $g_SelectedChannel;
- $g_SelectedChannel = input ("Type the channel name as it appears in the Twitch.tv URL", , "towelliee", "s", , , );
- global $g_UsherXml;
- sub "_USHER-XML-Get";
- global $g_Qualities;
- global $g_SelectedQuality;
- sub "_USHER-XML-Get-Qualities";
- $g_SelectedQuality = inputselect("$g_SelectedChannel", "$g_Qualities", "|", "0", , "200", "500", );
- global $g_Connect;
- global $g_Play;
- global $g_Token;
- sub "_USHER-Qualities-Param";
- global $g_RunCmd;
- sub "_PARSE-Construct";
- global $g_ExecutionFile;
- writefile ($g_ExecutionFile, "$g_RunCmd<crlf>".'del "'.$g_ExecutionFile, o, t);
- run ("$g_ExecutionFile", , 0, 1);
- sub "_Add-Recently-Played";
- }
- "Edit Configuration"
- {
- global $g_ConfigurationFile;
- run ('notepad "'.$g_ConfigurationFile.'"', , '0', '1');
- }
- "_API-Games-Get-Top"
- {
- global $g_Games;
- global $g_Url;
- global $g_Return;
- $g_Url = 'https://api.twitch.tv/kraken/games/top?limit=50';
- sub "_ReadUrl-Loop";
- $APIGames = $g_Return;
- $RegEx = '["][A-Z0-9][^"]*["]';
- $g_Games = regexmatches($APIGames, $RegEx, |, 1);
- $g_Games = formatlist ($g_Games, u, |, );
- }
- "_API-Channels-Get-Game"
- {
- global $g_SelectedGame;
- global $g_Channels;
- global $g_Url;
- global $g_Return;
- $g_SelectedGame = urlencode ($g_SelectedGame, 1);
- $g_SelectedGame = replace ($g_SelectedGame, ':', '%3A', , );
- $g_Url = "https://api.twitch.tv/kraken/streams?game=$g_SelectedGame";
- sub "_ReadUrl-Loop";
- $APIChannels = $g_Return;
- $RegEx = '["]url["]:["][^"]+["]';
- $g_Channels = regexmatches ($APIChannels, $RegEx, |, 0);
- $g_Channels = formatlist ($g_Channels, u, |, );
- $g_Channels = replace ($g_Channels, 'url":"http://www.twitch.tv/', , , );
- }
- "_API-Channels-Get-All"
- {
- global $g_Channels;
- global $g_Url;
- global $g_Return;
- $g_Url = 'https://api.twitch.tv/kraken/streams?limit=100';
- sub "_ReadUrl-Loop";
- $APIChannels = $g_Return;
- $RegEx = '["]url["]:["][^"]+["]';
- $g_Channels = regexmatches ($APIChannels, $RegEx, |, 0);
- $g_Channels = formatlist ($g_Channels, u, |, );
- $g_Channels = replace ($g_Channels, 'url":"http://www.twitch.tv/', , , );
- }
- "_API-Channels-Get-Followed"
- {
- global $g_User;
- global $g_Channels;
- global $g_Url;
- global $g_Return;
- $g_Url = "https://api.twitch.tv/kraken/users/$g_User/follows/channels?limit=50";
- sub "_ReadUrl-Loop";
- //$APIChannels contains all channels the user follows. Online and Offline
- $APIChannels = $g_Return;
- $RegEx = '["]url["]:["][^"]+["]';
- $g_Channels = regexmatches ($APIChannels, $RegEx, |, 0);
- $g_Channels = formatlist ($g_Channels, u, |, );
- $g_Channels = replace ($g_Channels, 'url":"http://www.twitch.tv/', , , );
- }
- "_API-Channels-Get-Status"
- {
- global $g_Channels;
- global $g_Url;
- global $g_Return;
- $ChannelsQuery = replace ($g_Channels, '|', ',', 0, , );
- $g_Url = "https://api.twitch.tv/kraken/streams?limit=100&channel=$ChannelsQuery";
- sub "_ReadUrl-Loop";
- $ChannelsQuery = $g_Return;
- $RegEx = '["]url["]:["][^"]+["]';
- $ChannelsQuery = regexmatches ($ChannelsQuery, $RegEx, |, 0);
- $ChannelsQuery = formatlist ($ChannelsQuery, u, |, );
- $ChannelsQuery = replace ($ChannelsQuery, 'url":"http://www.twitch.tv/', , , );
- $g_Channels = $ChannelsQuery;
- }
- "_USHER-XML-Get"
- {
- global $g_SelectedChannel;
- global $g_UsherXml;
- global $g_Url;
- global $g_Return;
- $g_Url = "http://usher.twitch.tv/find/$g_SelectedChannel.xml?type=any";
- sub "_ReadUrl-Loop";
- $g_UsherXml = $g_Return;
- }
- "_USHER-XML-Get-Qualities"
- {
- global $g_UsherXml;
- global $g_Qualities;
- $RegEx = '<live>|<1080p>|<720p>|<480p>|<360p>|<240p>|<144p>';
- $g_Qualities = regexmatches ($g_UsherXml, $RegEx, |, 0);
- $g_Qualities = replacelist ($g_Qualities, '<>');
- }
- "_USHER-Qualities-Param"
- {
- global $g_UsherXml;
- global $g_Qualities;
- global $g_SelectedQuality;
- global $g_Connect;
- global $g_Play;
- global $g_Token;
- $RegEx = "<$g_SelectedQuality>.+<\/$g_SelectedQuality>";
- $Data = regexmatches ($g_UsherXml, $RegEx, |, 0);
- $RegEx = "<connect>.+<\/connect>";
- $g_Connect = regexmatches ($Data, $RegEx, |, 0);
- $g_Connect = replacelist ($g_Connect, "<connect>,</connect>", , ',');
- $RegEx = "<play>.+<\/play>";
- $g_Play = regexmatches ($Data, $RegEx, |, 0);
- $g_Play = replacelist ($g_Play, "<play>,</play>", , ',');
- $RegEx = "<token>.+<\/token>";
- $g_Token = regexmatches ($Data, $RegEx, |, 0);
- $g_Token = replacelist ($g_Token, '<token>|</token>|"', '||\"', |, 0);
- }
- "_PARSE-Construct"
- {
- global $g_Rtmp;
- global $g_Vlc;
- global $g_SelectedChannel;
- global $g_Connect;
- global $g_Play;
- global $g_Token;
- global $g_SelectedChannel;
- global $g_RunCmd;
- global $g_ExecutionFileVBS;
- global $g_LocationFileSWF;
- $VisualBasicScript = <<<#
- Dim req
- Set req = CreateObject("WinHttp.WinHttpRequest.5.1")
- req.Option(6) = False ' No redirects'
- req.open "GET", "http://www-cdn.jtvnw.net/widgets/live_embed_player.swf", False
- req.send
- Set fs = CreateObject("Scripting.FileSystemObject")
- Set a = fs.CreateTextFile("$g_LocationFileSWF", True)
- a.WriteLine(req.getResponseHeader("Location"))
- a.Close
- #;
- writefile ($g_ExecutionFileVBS, $VisualBasicScript, o, t);
- run ('cscript "'.$g_ExecutionFileVBS.'"', , 2, 0);
- $Swf = readfile ($g_LocationFileSWF, t, , , );
- $Swf = regexmatches ($Swf, 'http(.+).swf', |, 0);
- $Swf = $Swf."?channel=$g_SelectedChannel";
- delete (0, 0, $g_LocationFileSWF);
- delete (0, 0, $g_ExecutionFileVBS);
- if (regexmatches($g_Connect, '//(\d+[.]?)+/app', |, 0)){
- $g_RunCmd = '"'.$g_Rtmp.'" -r "'.$g_Connect.'/'.$g_Play.'" -j "'.$g_Token.'" --swfVfy "'.$Swf.'" -v -o - | "'.$g_Vlc.'" -';
- } else {
- $g_RunCmd = '"'.$g_Rtmp.'" -r "'.$g_Connect.'/'.$g_Play.'" --swfVfy "'.$Swf.'" -v -o - | "'.$g_Vlc.'" -';
- }
- }
- "_ReadUrl-Loop"
- {
- global $g_Url;
- global $g_Return;
- $g_Return = readurl($g_Url, 0, 0, );
- }
- "_Add-Recently-Played"
- {
- global $g_ConfigurationFile;
- global $g_SelectedChannel;
- $Count = getkey ('Count', 'RecentlyWatched', $g_ConfigurationFile, );
- $Count++;
- setkey ($Count, Count, 'RecentlyWatched', $g_ConfigurationFile, );
- setkey ($g_SelectedChannel, $Count, 'RecentlyWatched', $g_ConfigurationFile, );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement