Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**************************************************************
- * Twitch.xys 2.0
- * Released: 06/01/2014
- *
- * For all information read the forum thread:
- * http://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=9307
- *
- * 40k
- **************************************************************/
- "_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);
- global $g_BufferFileLivestreamer;
- $g_BufferFileLivestreamer = "<xyscripts>\Twitch.buf";
- delete ('0', '0', $g_BufferFileLivestreamer);
- // Configuration keys
- global $g_ScriptVersion;
- $g_ScriptVersion = '1.4';
- global $g_Vlc;
- global $g_Livestreamer;
- global $g_User;
- global $g_MaxGames;
- global $g_MaxChannels;
- if (exists($g_ConfigurationFile) == '1' && $g_ScriptVersion == getkey('ScriptVersion', 'Configuration', $g_ConfigurationFile, )){
- // Load keys
- $g_Vlc = getkey('Vlc', 'Configuration', $g_ConfigurationFile, );
- $g_Livestreamer = getkey('Livestreamer', 'Configuration', $g_ConfigurationFile, );
- $g_User = getkey('User', 'Configuration', $g_ConfigurationFile, );
- $g_MaxGames = getkey('MaxGames', 'Options', $g_ConfigurationFile, );
- $g_MaxChannels = getkey('MaxChannels', 'Options', $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 livestreamer.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_Livestreamer;
- global $g_User;
- $g_Vlc = inputfile('C:\', 'exe', 'Select vlc.exe');
- $g_Livestreamer = inputfile('C:\', 'exe', 'Select livestreamer.exe');
- $g_User = input('Enter your Twitch.tv user name');
- // Write configuration to disk
- $Configuration = <<<#
- [Configuration]
- ScriptVersion=$g_ScriptVersion
- Vlc=$g_Vlc
- Livestreamer=$g_Livestreamer
- User=$g_User
- [Options]
- MaxGames=50
- MaxChannels=100
- [RecentlyWatched]
- Count=0
- #;
- writefile($g_ConfigurationFile, $Configuration, o, t);
- msg <<<#
- Configuration completed.
- #;
- }
- "Popular Games"
- {
- global $g_Games;
- sub "_API-Games-Get";
- global $g_SelectedGame;
- $g_SelectedGame = inputselect('Popular Games based on viewer numbers', $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', );
- sub "_LIVESTREAMER-Get-Qualities";
- global $g_Qualities;
- global $g_SelectedQuality;
- $g_SelectedQuality = inputselect($g_SelectedChannel, $g_Qualities, '|', '0', , '200', '500', );
- sub "_LIVESTREAMER-PARSE-Construct";
- }
- "Popular Channels"
- {
- global $g_Channels;
- global $g_SelectedChannel;
- sub "_API-Channels-Get";
- $g_SelectedChannel = inputselect("Popular Channels<crlf>Channels are listed based on viewer count", $g_Channels, '|', '0', , '200', '500', );
- sub "_LIVESTREAMER-Get-Qualities";
- global $g_Qualities;
- global $g_SelectedQuality;
- $g_SelectedQuality = inputselect($g_SelectedChannel, $g_Qualities, '|', '0', , '200', '500', );
- sub "_LIVESTREAMER-PARSE-Construct";
- sub "_Add-Recently-Played";
- }
- "Featured Channels"
- {
- global $g_Channels;
- global $g_SelectedChannel;
- global $g_User;
- sub "_API-Channels-Get-Featured";
- $g_SelectedChannel = inputselect("Twitch.tv Featured spotlight channels<crlf>Channels are listed based on viewer count", $g_Channels, '|', '0', , '200', '500', );
- sub "_LIVESTREAMER-Get-Qualities";
- global $g_Qualities;
- global $g_SelectedQuality;
- $g_SelectedQuality = inputselect($g_SelectedChannel, $g_Qualities, '|', '0', , '200', '500', );
- sub "_LIVESTREAMER-PARSE-Construct";
- sub "_Add-Recently-Played";
- }
- "My Followed Channels"
- {
- global $g_Channels;
- global $g_SelectedChannel;
- global $g_User;
- sub "_API-Channels-Get-Followed";
- sub "_API-Channels-Get-Status";
- $g_SelectedChannel = inputselect("User: $g_User<crlf>Channels are listed based on viewer count", $g_Channels, '|', '0', , '200', '500', );
- sub "_LIVESTREAMER-Get-Qualities";
- global $g_Qualities;
- global $g_SelectedQuality;
- $g_SelectedQuality = inputselect($g_SelectedChannel, $g_Qualities, '|', '0', , '200', '500', );
- sub "_LIVESTREAMER-PARSE-Construct";
- sub "_Add-Recently-Played";
- }
- "My Recently Watched"
- {
- global $g_ConfigurationFile;
- global $g_Channels;
- global $g_User;
- $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("User: $g_User<crlf><crlf>Channels are listed based on viewer count", $g_Channels, '|', '0', , '200', '500', );
- sub "_LIVESTREAMER-Get-Qualities";
- global $g_Qualities;
- global $g_SelectedQuality;
- $g_SelectedQuality = inputselect($g_SelectedChannel, $g_Qualities, '|', '0', , '200', '500', );
- sub "_LIVESTREAMER-PARSE-Construct";
- 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', , , );
- sub "_LIVESTREAMER-Get-Qualities";
- global $g_Qualities;
- global $g_SelectedQuality;
- $g_SelectedQuality = inputselect($g_SelectedChannel, $g_Qualities, '|', '0', , '200', '500', );
- sub "_LIVESTREAMER-PARSE-Construct";
- sub "_Add-Recently-Played";
- }
- "Edit Configuration"
- {
- global $g_ConfigurationFile;
- run ('notepad "'.$g_ConfigurationFile.'"', , '0', '1');
- }
- "_API-Games-Get"
- {
- global $g_Games;
- global $g_MaxGames;
- $Limit = '50';
- $Offset = '0';
- while($Limit+$Offset <= $g_MaxGames){
- $Url = "https://api.twitch.tv/kraken/games/top?limit=$Limit&offset=$Offset";
- $APIGames = $APIGames.readurl($Url, '0', '0', );
- $Offset = $Offset + '50';
- }
- $RegEx = '["][A-Z0-9][^"]*["]';
- $g_Games = regexmatches($APIGames, $RegEx, '|', '1');
- $g_Games = formatlist($g_Games, 'u', '|', );
- }
- "_API-Channels-Get"
- {
- global $g_Channels;
- global $g_MaxChannels;
- $Limit = '100';
- $Offset = '0';
- while($Limit+$Offset <= $g_MaxChannels){
- $Url = "https://api.twitch.tv/kraken/streams?limit=$Limit&offset=$Offset";
- $APIChannels = $APIChannels.readurl($Url, '0', '0', );
- $Offset = $Offset + '100';
- }
- $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-Game"
- {
- global $g_SelectedGame;
- global $g_Channels;
- $g_SelectedGame = urlencode($g_SelectedGame, '1');
- $g_SelectedGame = replace($g_SelectedGame, ':', '%3A', , );
- $Url = "https://api.twitch.tv/kraken/streams?game=$g_SelectedGame";
- $APIChannels = readurl($Url, '0', '0', );
- $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;
- $Url = "https://api.twitch.tv/kraken/users/$g_User/follows/channels?limit=50";
- $APIChannels = readurl($Url, '0', '0', );
- $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-Featured"
- {
- global $g_Channels;
- $Url = 'https://api.twitch.tv/kraken/streams/featured?limit=100';
- $APIChannels = readurl($Url, '0', '0', );
- $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;
- //$g_Channels is passed from "_API-Channels-Get-Followed" and contains all channels $g_User follows.
- //$ChannelsQuery replaces delimiter '|' with ',' and queries the Twitch server for which channels in the list are currently live.
- $ChannelsQuery = replace($g_Channels, '|', ',', 0, , );
- $Url = "https://api.twitch.tv/kraken/streams?limit=100&channel=$ChannelsQuery";
- $ChannelsQuery = readurl($Url, '0', '0', );
- $RegEx = '["]url["]:["][^"]+["]';
- $ChannelsQuery = regexmatches ($ChannelsQuery, $RegEx, '|', '0');
- $ChannelsQuery = formatlist ($ChannelsQuery, 'u', '|', );
- $ChannelsQuery = replace ($ChannelsQuery, 'url":"http://www.twitch.tv/', , , );
- //$g_Channels now contains all LIVE channels that $g_User follows.
- $g_Channels = $ChannelsQuery;
- }
- "_USHER-XML-Get"
- {
- global $g_SelectedChannel;
- global $g_UsherXml;
- $Url = "http://usher.twitch.tv/find/$g_SelectedChannel.xml?type=any";
- $g_UsherXml = readurl($Url, '0', '0', );
- }
- "_USHER-XML-Get-Qualities"
- {
- global $g_UsherXml;
- global $g_Qualities;
- $RegEx = '<live>|<1080p>|<720p>|<480p>|<360p>|<240p>|<high>|<medium>|<low>';
- $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');
- }
- "_LIVESTREAMER-Get-Qualities"
- {
- global $g_Vlc;
- global $g_Livestreamer;
- global $g_ExecutionFile;
- global $g_BufferFileLivestreamer;
- global $g_SelectedChannel;
- $LivestreamerCommand = '"'.$g_Livestreamer.'" -p "'.$g_Vlc.'" twitch.tv/'.$g_SelectedChannel.' > "'.$g_BufferFileLivestreamer.'"';
- writefile($g_ExecutionFile, $LivestreamerCommand, 'o', 't');
- run($g_ExecutionFile, , '1', '0');
- $LivestreamerReturn = readfile($g_BufferFileLivestreamer);
- delete ('0', '0', $g_BufferFileLivestreamer);
- delete('0', '0', $g_ExecutionFile);
- global $g_Qualities;
- $RegEx = 'source|high|medium|low|mobile';
- $g_Qualities = regexmatches($LivestreamerReturn, $RegEx, '|', '0');
- }
- "_LIVESTREAMER-PARSE-Construct"
- {
- global $g_Vlc;
- global $g_Livestreamer;
- global $g_ExecutionFile;
- global $g_SelectedChannel;
- global $g_SelectedQuality;
- $LivestreamerCommand = '"'.$g_Livestreamer.'" -p "'.$g_Vlc.'" twitch.tv/'.$g_SelectedChannel.' '.$g_SelectedQuality;
- writefile($g_ExecutionFile, $LivestreamerCommand, 'o', 't');
- run($g_ExecutionFile, , '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