Page 1 of 2

Twitch.tv VLC 2.0 06/1/14: Twitch.tv HLS revamp

Posted: 20 Feb 2013 18:37
by 40k
Twitch.tv VLC 2.0
Twitch 2.0.xys
(12.8 KiB) Downloaded 310 times
Get TwitchTV.xys 2.0 from Pastebin

Requirements:
1. Xyplorer 12.0 or better. Previous version may work but were not tested.
2. LIVESTREAMER 1.7.2 - https://github.com/chrippa/livestreamer ... tag/v1.7.2
3. VLC.exe 2.0.0 or better. - http://www.videolan.org/vlc/

How to run this script:
1. Place Twitch 2.0.xys into the <xypath>\Data\Scripts folder.
2. Create a catalog entry or custom toolbar button to start script
For catalog entry use -> ::load Twitch 2.0
3. Complete the configuration wizard. This appears on your first launch of script

CURRENT VERSION: 2.0

Code: Select all

Twitch.xys 2.0 Changelog:
+ Twitch service now uses HLS http streaming for video distribution. This is supported now though livestreamer
+ You need to install livestreamer (portable app, just like rtmpdump)
+ Delete your twitch.ini and launch the script. Configuration wizard works as usual
+ Supports Source, High, Medium, Low, and Mobile resolutions just like the website or iOS and Android apps.
- RTMPdump is no longer used

Code: Select all

Twitch.xys 2.0 Known Issues:
> If you get error: "Can not find file: $g_LocationFileSWF", Delete Twitch.ini in your <xyscripts> folder and run the script again. The configuration wizard will appear and after you configure the script again it will work.

UPDATE:: 1.4 - 26

Code: Select all

Twitch.xys 1.4 Changelog:
+ Added support for new Twitch quality settings: Source (Live), High (720p), Medium (360p), and Low (192p).
UPDATE: 1.3 - 26

Code: Select all

Twitch.xys 1.3 Changelog:
+ NEW: "List Featured Streams" allows you to pick a stream that is featured by Twitch.tv
+ NEW: Configuration options in section [Options] of Twitch.ini
  > OPTIONS:
  > ShowRtmpConsole=[1] // Set value to 1 to display Rtmpdump command line window. Set value to 0 to hide window
  > MaxGames=50 // Set value to multiple of 50 (E.g. 150, 300). Defines amount of games retrieved by "List Top Games" function
  > MaxChannels=100 // Set value to multiple of 100 (E.g. 400). Defines amount of channels retrieved by "List Top Channels" function
  > Use "Edit Configuration" to launch notepad and edit the ini file
  > !!!WARNING!!!: Increasing these values above the default can drastically increase the time the script needs to retrieve your data.
    This depends on the speed of your internet connection and the actual load on the Twitch server.
* Changed script function names from "Show..." to "List..."
* Implemented correct code quoting syntax, see forum discussion here: http://www.xyplorer.com/xyfc/viewtopic.php?f=2&t=9942
- Removed deprecated/bloat code
- Removed support for 144p resolution. This was due to confusion with Youtube, Twitch simply has no 144p stream.

Code: Select all

Twitch.xys 1.3 functions:
1. List Top Games
   - Shows a list of the current top Games on Twitch. Select a game to see the current streamers.
   - Amount of games shown is determined by the MaxGames option
2. List Top Channels
   - Shows list of the currently most viewed channels on Twitch
   - Amount of channels shown is determined by the MaxChannels options
3. List Featured Channels
   - Shows a list with the currently featured streams on Twitch
4. List Followed Channels
   - If you entered your username during the configuration wizard, this shows a list of channels you are following and are currently LIVE
   - Unintended side-effect: Enter the channel name of any streamer on Twitch to see a list of channels THEY are following
5. List Recently Watched
   - Shows list of channels you have recently watched and are currently LIVE
6. Enter Channel Name
   - Enter a channel name to watch it immediately
7. Edit Configuration
   - Opens the configuration file in notepad
   - Use this function to edit the script Options directly
UPDATE: 1.2

Code: Select all

Twitch.xys 1.2 Changelog:
+ Added support for 240p and 144p resolutions
+ !!!Followed Channels and Recently Watched channels now only show channels that are currently LIVE!!!
* Fixed problem where rtmpdump would indicate Twitch server sent error
* Cleaned up code syntax to give code a uniform look
* Fixed issue where bad quoting caused rtmpdump to quit
- Removed support for iphonehigh and iphonelow resolutions
  Mobile platform resolutions are no longer supported by Twitch through their regular content delivery network
UPDATE: 1.1
After a couple of months Twitch.xys has reached 1.1! I have implemented a few major improvements, the biggest one being the script will now work indefinitely whereas previous versions stopped working after a few weeks for a reason that has only recently been cleared up.
In all previous versions I used a hardcoded Flash URL that leads to the Twitch.tv embedded flash player. This URL is required by Rtmpdump.exe to authenticate with the Twitch video server. I did not know that these Flash URLs expired after "x" amount of uses!. This explains why the script would work fine for a week or two and then suddenly stopped working. We basically ran out of uses on the hardcoded Flash link.
1.1 contains new code that automatically retrieves a new Flash link for the script. This means the script should now run without time limitation!
Unfortunately, I found I was running into the limits of what Xy could do scripting-wise. because of this, the script will actually create a small VBS script to retrieve this Flash link and return it to Xy. The VBS code is posted below for clarity and can be found in the "_ParseConstruct" sub routine of the script. The VBS code works using Windows resources and requires no input from you as user at all.

This VBS code is used to retrieve the Twitch Flash Link

Code: Select all

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
Smaller code improvements include:
- Fixed a problem with Top 100 channels only showig you Top 25
- Rtmpdump command console window is now shown again. I hid it in previous version but found it is nice to have on a slow connection where the initial buffering of the video takes time. Without the window being displayed it sometimes appeared as if nothing was happening.
- Perhaps important to note: The script can not get access to streams that are behind a pay wall. These are usually only for big events such as MLG. If these events have free lower quality version available the script will however be able to let you watch those.

UPDATE: 0.5.5
- I manually hard-coded the new Flash link for Twitch.tv. The script is now fully functional. This flash link changes from time to time and I'm working on making this update automatic.

UPDATE: 0.5.1
- Implemented a fail-safe data retrieval system that keeps querying the Twitch server for stream information
until it receives a valid response. This means Empty quality lists are now fixed.
- Script files will now always be stored into your Xypath scripts folder even if you use a non-standard Xyplorer folder configuration.
- Update 0.5.1 - All games are now supported including games with a colon (:) in the title.

Known issues and bugs current version: 0.5.1
- VLC starts after you select a quality setting for your desired stream. It may take a few seconds for your stream to start playing as rtmpdump is buffering the video feed in the background. The rtmpdump window does not appear giving the impression nothing is happening. Depending on the speed of your internet connection this initial buffer can be very short or a bit longer. Please do not close VLC, your video is coming!
- The Followed Stream feature shows you the first 50 streams you are following. It does not indicate if they are online. That would take too much time querying the Twitch servers.
- If you use the "Recently Played" feature to attempt to watch a stream that is currently not live the script will get stuck into an endless loop and the only way to exit it is to end the Xyplorer.exe process. This is an unfortunate side-effect that only became apparant to me after publishing 0.5.1 BUT it will be fixed when the new Xyplorer version is released that allows for downloads without byte check. In the meantime, don't use try to watch streams that are not live, it will not work.

UPDATE 0.4.1
- Script now uses a configuration file nested in the Xyplorer scripts folder.
- Configuration wizard on first start makes it easy to configure your script
- Completely redesigned regular expressions. performance increase up to 50%.
- No more duplicate entries in stream list thanks to new regex.
- The RTMPdump command prompt is no longer shown. Only VLC will appear after you select a streamer and quality. After a few seconds the stream will begin to play!

known issues:
- I believe Twitch may be denying user requests to their API if they follow too quickly upon each other. When selecting a Channel through the script there is a lot of querying going on in the background to show you available quality levels. Sometimes the list of available quality levels will show up empty. This is NOT a script issue. You may have to try a few times before you get a response from Twitch.

Twitch has been pretty buggy lately. Well it has always been but more so in recent times. I believe they are implementing new features on their servers and are running into capacity problems. Unfortunately this means bugs will appear even after my script was tested and deemed stable. If you find anything let me know. I appreciate Twitch is a start-up company but their engineers certainly love to push out code and test later.

- Checking of online status for Followed streams can be very slow especially if you follow more than 50 channels. This bottleneck is with Twitch's API and beyond my control

UPDATE 0.3
- Rewrite of the code

UPDATE 0.2.2 (09/03/2013) - 15
- Removed orange triangles in Games and Streamer selection list

UPDATE 0.2.1 (04/03/2013)

- Small maintenance update to make script compatible with new Twitch.TV API
- Slightly faster regEx (Special thank you to forum users Highend and Marco)
- known issue: Target mode may fail for certain streams at certain qualities due to Twitch.TV using legacy API responses for some streams. This will disappear over time as all streamers are moved onto the new API system.

UPDATE 0.2 (24/02/2013)
- All files created by this script (WGET.TMP and VLC.BAT) are now deleted automatically. No more garbage
- Script now uses Xyplorer native function to download information from the Twitch API. No more wget required
- TARGET MODE implemented. Already know exactly what streamer you want to watch? Just type in the channel name and available qualities will be displayed for you automatically

Image

Image

Image

Image

Image

Image

Re: Twitch.tv to VLC script 0.1

Posted: 20 Feb 2013 18:50
by admin
40k wrote:Like all Twitch scripts it relies on RTMPdump and VLC. In addition to this my version also requires WGET for windows due to a problem within Xyplorer's download function. Don knows about this and claims this problem will be fixed in the next Xyplorer version so I expect the WGET requirement to be dropped in my next version
Should be fixed in the current version. Isn't it?

Re: Twitch.tv to VLC script 0.1

Posted: 20 Feb 2013 19:06
by Marco
1. Another option, instead of permanent variables for paths, could be an ini file (I know, not elegant)
2. Try this to catch the games names, should be faster

Code: Select all

(?<="name":").*?(?=","_links")
3. @Don: nope it still asks to download something, it doesn't show you plain code
3bis. Maybe you can retrieve that code via VBS

Re: Twitch.tv to VLC script 0.1

Posted: 20 Feb 2013 19:23
by admin
Hm, I have no time to go into this code. But if you can show me a minimal test code that demonstrates the problem I'll check it.

Re: Twitch.tv to VLC script 0.1

Posted: 24 Feb 2013 17:28
by 40k
Marco wrote:1. Another option, instead of permanent variables for paths, could be an ini file (I know, not elegant)
2. Try this to catch the games names, should be faster

Code: Select all

(?<="name":").*?(?=","_links")
3. @Don: nope it still asks to download something, it doesn't show you plain code
3bis. Maybe you can retrieve that code via VBS
Hi Marco!

Xyplorer throws an exception when I try to regexmatches your regEx.
I also tried your regEx in a regEx tester (http://regexpal.com/) and it is not returning any results there either?

Re: Twitch.tv VLC script UPDATE 0.2 (feedback requested!)

Posted: 24 Feb 2013 17:41
by Marco
Mmh, probably it's too advanced as construct. However works here http://www.myregextester.com/

Re: Twitch.tv VLC script UPDATE 0.2 (feedback requested!)

Posted: 24 Feb 2013 19:01
by highend
Don't get me wrong, but I'm too lazy to analyze the whole script to see what exactly you want to target with your regexes and what you want to get in return.

So can you do me a favor and deliver examples of what to target, your current assigned regex and the result you'd like to get?

Re: Twitch.tv VLC script UPDATE 0.2 (feedback requested!)

Posted: 28 Feb 2013 11:07
by 40k
highend wrote:Don't get me wrong, but I'm too lazy to analyze the whole script to see what exactly you want to target with your regexes and what you want to get in return.

So can you do me a favor and deliver examples of what to target, your current assigned regex and the result you'd like to get?
I basically need a regEx that can extract the text between quotes after "name":"<name of game>"
Thus far I've been using a very complicated regEx because it's the only way I know how. The issue I had is that some game titles have numbers or :-signs in them. Alternative if you could link me to some good study material on regEx that would be much appreciated.

Below is a code snippet which is a general response from the Twitch API. You can test your regEx using the response from the server using this link: https://api.twitch.tv/kraken/games/top?limit=10
Where you can adjust the amount of games returned up to a maximum of 100 titles.

Code: Select all

{"top":[{"game":{"logo":{"large":"http://static-cdn.jtvnw.net/ttv-logoart/League%20of%20Legends-240x144.jpg","medium":"http://static-cdn.jtvnw.net/ttv-logoart/League%20of%20Legends-120x72.jpg","small":"http://static-cdn.jtvnw.net/ttv-logoart/League%20of%20Legends-60x36.jpg","template":"http://static-cdn.jtvnw.net/ttv-logoart/League%20of%20Legends-{width}x{height}.jpg"},"giantbomb_id":24024,"_links":{},"box":{"large":"http://static-cdn.jtvnw.net/ttv-boxart/League%20of%20Legends-272x380.jpg","medium":"http://static-cdn.jtvnw.net/ttv-boxart/League%20of%20Legends-136x190.jpg","small":"http://static-cdn.jtvnw.net/ttv-boxart/League%20of%20Legends-52x72.jpg","template":"http://static-cdn.jtvnw.net/ttv-boxart/League%20of%20Legends-{width}x{height}.jpg"},"_id":21779,"name":"League of Legends"},"viewers":31252,"channels":386},{"game":{"logo":{"large":"http://static-cdn.jtvnw.net/ttv-logoart/StarCraft%20II%3A%20Wings%20of%20Liberty-240x144.jpg","medium":"http://static-cdn.jtvnw.net/ttv-logoart/StarCraft%20II%3A%20Wings%20of%20Liberty-120x72.jpg","small":"http://static-cdn.jtvnw.net/ttv-logoart/StarCraft%20II%3A%20Wings%20of%20Liberty-60x36.jpg","template":"http://static-cdn.jtvnw.net/ttv-logoart/StarCraft%20II%3A%20Wings%20of%20Liberty-{width}x{height}.jpg"},"giantbomb_id":20674,"_links":{},"box":{"large":"http://static-cdn.jtvnw.net/ttv-boxart/StarCraft%20II%3A%20Wings%20of%20Liberty-272x380.jpg","medium":"http://static-cdn.jtvnw.net/ttv-boxart/StarCraft%20II%3A%20Wings%20of%20Liberty-136x190.jpg","small":"http://static-cdn.jtvnw.net/ttv-boxart/StarCraft%20II%3A%20Wings%20of%20Liberty-52x72.jpg","template":"http://static-cdn.jtvnw.net/ttv-boxart/StarCraft%20II%3A%20Wings%20of%20Liberty-{width}x{height}.jpg"},"_id":18901,"name":"StarCraft II: Wings of Liberty"},"viewers":8618,"channels":45},{"game":{"logo":{"large":"http://static-cdn.jtvnw.net/ttv-logoart/Dota%202-240x144.jpg","medium":"http://static-cdn.jtvnw.net/ttv-logoart/Dota%202-120x72.jpg","small":"http://static-cdn.jtvnw.net/ttv-logoart/Dota%202-60x36.jpg","template":"http://static-cdn.jtvnw.net/ttv-logoart/Dota%202-{width}x{height}.jpg"},"giantbomb_id":32887,"_links":{},"box":{"large":"http://static-cdn.jtvnw.net/ttv-boxart/Dota%202-272x380.jpg","medium":"http://static-cdn.jtvnw.net/ttv-boxart/Dota%202-136x190.jpg","small":"http://static-cdn.jtvnw.net/ttv-boxart/Dota%202-52x72.jpg","template":"http://static-cdn.jtvnw.net/ttv-boxart/Dota%202-{width}x{height}.jpg"},"_id":29595,"name":"Dota 2"},"viewers":5861,"channels":67},{"game":{"logo":{"large":"http://static-cdn.jtvnw.net/ttv-logoart/Path%20of%20Exile-240x144.jpg","medium":"http://static-cdn.jtvnw.net/ttv-logoart/Path%20of%20Exile-120x72.jpg","small":"http://static-cdn.jtvnw.net/ttv-logoart/Path%20of%20Exile-60x36.jpg","template":"http://static-cdn.jtvnw.net/ttv-logoart/Path%20of%20Exile-{width}x{height}.jpg"},"giantbomb_id":32562,"_links":{},"box":{"large":"http://static-cdn.jtvnw.net/ttv-boxart/Path%20of%20Exile-272x380.jpg","medium":"http://static-cdn.jtvnw.net/ttv-boxart/Path%20of%20Exile-136x190.jpg","small":"http://static-cdn.jtvnw.net/ttv-boxart/Path%20of%20Exile-52x72.jpg","template":"http://static-cdn.jtvnw.net/ttv-boxart/Path%20of%20Exile-{width}x{height}.jpg"},"_id":29307,"name":"Path of Exile"},"viewers":4646,"channels":32},{"game":{"logo":{"large":"http://static-cdn.jtvnw.net/ttv-logoart/StarCraft%20II%3A%20Heart%20of%20the%20Swarm-240x144.jpg","medium":"http://static-cdn.jtvnw.net/ttv-logoart/StarCraft%20II%3A%20Heart%20of%20the%20Swarm-120x72.jpg","small":"http://static-cdn.jtvnw.net/ttv-logoart/StarCraft%20II%3A%20Heart%20of%20the%20Swarm-60x36.jpg","template":"http://static-cdn.jtvnw.net/ttv-logoart/StarCraft%20II%3A%20Heart%20of%20the%20Swarm-{width}x{height}.jpg"},"giantbomb_id":24078,"_links":{},"box":{"large":"http://static-cdn.jtvnw.net/ttv-boxart/StarCraft%20II%3A%20Heart%20of%20the%20Swarm-272x380.jpg","medium":"http://static-cdn.jtvnw.net/ttv-boxart/StarCraft%20II%3A%20Heart%20of%20the%20Swarm-136x190.jpg","small":"http://static-cdn.jtvnw.net/ttv-boxart/StarCraft%20II%3A%20Heart%20of%20the%20Swarm-52x72.jpg","template":"http://static-cdn.jtvnw.net/ttv-boxart/StarCraft%20II%3A%20Heart%20of%20the%20Swarm-{width}x{height}.jpg"},"_id":21818,"name":"StarCraft II: Heart of the Swarm"},"viewers":3291,"channels":25},{"game":{"logo":{"large":"http://static-cdn.jtvnw.net/ttv-logoart/BIT.TRIP%20Presents%3A%20Runner2%3A%20Future%20Legend%20of%20Rhythm%20Alien-240x144.jpg","medium":"http://static-cdn.jtvnw.net/ttv-logoart/BIT.TRIP%20Presents%3A%20Runner2%3A%20Future%20Legend%20of%20Rhythm%20Alien-120x72.jpg","small":"http://static-cdn.jtvnw.net/ttv-logoart/BIT.TRIP%20Presents%3A%20Runner2%3A%20Future%20Legend%20of%20Rhythm%20Alien-60x36.jpg","template":"http://static-cdn.jtvnw.net/ttv-logoart/BIT.TRIP%20Presents%3A%20Runner2%3A%20Future%20Legend%20of%20Rhythm%20Alien-{width}x{height}.jpg"},"giantbomb_id":36644,"_links":{},"box":{"large":"http://static-cdn.jtvnw.net/ttv-boxart/BIT.TRIP%20Presents%3A%20Runner2%3A%20Future%20Legend%20of%20Rhythm%20Alien-272x380.jpg","medium":"http://static-cdn.jtvnw.net/ttv-boxart/BIT.TRIP%20Presents%3A%20Runner2%3A%20Future%20Legend%20of%20Rhythm%20Alien-136x190.jpg","small":"http://static-cdn.jtvnw.net/ttv-boxart/BIT.TRIP%20Presents%3A%20Runner2%3A%20Future%20Legend%20of%20Rhythm%20Alien-52x72.jpg","template":"http://static-cdn.jtvnw.net/ttv-boxart/BIT.TRIP%20Presents%3A%20Runner2%3A%20Future%20Legend%20of%20Rhythm%20Alien-{width}x{height}.jpg"},"_id":32872,"name":"BIT.TRIP Presents: Runner2: Future Legend of Rhythm Alien"},"viewers":2703,"channels":6},{"game":{"logo":{"large":"http://static-cdn.jtvnw.net/ttv-logoart/World%20of%20Warcraft%3A%20Mists%20of%20Pandaria-240x144.jpg","medium":"http://static-cdn.jtvnw.net/ttv-logoart/World%20of%20Warcraft%3A%20Mists%20of%20Pandaria-120x72.jpg","small":"http://static-cdn.jtvnw.net/ttv-logoart/World%20of%20Warcraft%3A%20Mists%20of%20Pandaria-60x36.jpg","template":"http://static-cdn.jtvnw.net/ttv-logoart/World%20of%20Warcraft%3A%20Mists%20of%20Pandaria-{width}x{height}.jpg"},"giantbomb_id":36734,"_links":{},"box":{"large":"http://static-cdn.jtvnw.net/ttv-boxart/World%20of%20Warcraft%3A%20Mists%20of%20Pandaria-272x380.jpg","medium":"http://static-cdn.jtvnw.net/ttv-boxart/World%20of%20Warcraft%3A%20Mists%20of%20Pandaria-136x190.jpg","small":"http://static-cdn.jtvnw.net/ttv-boxart/World%20of%20Warcraft%3A%20Mists%20of%20Pandaria-52x72.jpg","template":"http://static-cdn.jtvnw.net/ttv-boxart/World%20of%20Warcraft%3A%20Mists%20of%20Pandaria-{width}x{height}.jpg"},"_id":32954,"name":"World of Warcraft: Mists of Pandaria"},"viewers":2090,"channels":100},{"game":{"logo":{"large":"http://static-cdn.jtvnw.net/ttv-logoart/Ultimate%20Marvel%20vs.%20Capcom%203-240x144.jpg","medium":"http://static-cdn.jtvnw.net/ttv-logoart/Ultimate%20Marvel%20vs.%20Capcom%203-120x72.jpg","small":"http://static-cdn.jtvnw.net/ttv-logoart/Ultimate%20Marvel%20vs.%20Capcom%203-60x36.jpg","template":"http://static-cdn.jtvnw.net/ttv-logoart/Ultimate%20Marvel%20vs.%20Capcom%203-{width}x{height}.jpg"},"giantbomb_id":35938,"_links":{},"box":{"large":"http://static-cdn.jtvnw.net/ttv-boxart/Ultimate%20Marvel%20vs.%20Capcom%203-272x380.jpg","medium":"http://static-cdn.jtvnw.net/ttv-boxart/Ultimate%20Marvel%20vs.%20Capcom%203-136x190.jpg","small":"http://static-cdn.jtvnw.net/ttv-boxart/Ultimate%20Marvel%20vs.%20Capcom%203-52x72.jpg","template":"http://static-cdn.jtvnw.net/ttv-boxart/Ultimate%20Marvel%20vs.%20Capcom%203-{width}x{height}.jpg"},"_id":32245,"name":"Ultimate Marvel vs. Capcom 3"},"viewers":1484,"channels":6},{"game":{"logo":{"large":"http://static-cdn.jtvnw.net/ttv-logoart/RuneScape-240x144.jpg","medium":"http://static-cdn.jtvnw.net/ttv-logoart/RuneScape-120x72.jpg","small":"http://static-cdn.jtvnw.net/ttv-logoart/RuneScape-60x36.jpg","template":"http://static-cdn.jtvnw.net/ttv-logoart/RuneScape-{width}x{height}.jpg"},"giantbomb_id":2268,"_links":{},"box":{"large":"http://static-cdn.jtvnw.net/ttv-boxart/RuneScape-272x380.jpg","medium":"http://static-cdn.jtvnw.net/ttv-boxart/RuneScape-136x190.jpg","small":"http://static-cdn.jtvnw.net/ttv-boxart/RuneScape-52x72.jpg","template":"http://static-cdn.jtvnw.net/ttv-boxart/RuneScape-{width}x{height}.jpg"},"_id":2083,"name":"RuneScape"},"viewers":1426,"channels":47},{"game":{"logo":{"large":"http://static-cdn.jtvnw.net/ttv-logoart/Minecraft-240x144.jpg","medium":"http://static-cdn.jtvnw.net/ttv-logoart/Minecraft-120x72.jpg","small":"http://static-cdn.jtvnw.net/ttv-logoart/Minecraft-60x36.jpg","template":"http://static-cdn.jtvnw.net/ttv-logoart/Minecraft-{width}x{height}.jpg"},"giantbomb_id":30475,"_links":{},"box":{"large":"http://static-cdn.jtvnw.net/ttv-boxart/Minecraft-272x380.jpg","medium":"http://static-cdn.jtvnw.net/ttv-boxart/Minecraft-136x190.jpg","small":"http://static-cdn.jtvnw.net/ttv-boxart/Minecraft-52x72.jpg","template":"http://static-cdn.jtvnw.net/ttv-boxart/Minecraft-{width}x{height}.jpg"},"_id":27471,"name":"Minecraft"},"viewers":1297,"channels":50}],"_links":{"next":"https://api.twitch.tv/kraken/games/top?limit=10&offset=10","self":"https://api.twitch.tv/kraken/games/top?limit=10&offset=0"},"_total":280}

Re: Twitch.tv VLC script UPDATE 0.2 (feedback requested!)

Posted: 28 Feb 2013 11:52
by Marco

Code: Select all

 $test =<<<DGVFHFHIOLJ
{"top":[{"game":{"logo":{"large":"http://static-cdn.jtvnw.net/ttv-logoart/League%20of%20Legends-240x144.jpg","medium":"http://static-cdn.jtvnw.net/ttv-logoart/League%20of%20Legends-120x72.jpg","small":"http://static-cdn.jtvnw.net/ttv-logoart/League%20of%20Legends-60x36.jpg","template":"http://static-cdn.jtvnw.net/ttv-logoart/League%20of%20Legends-{width}x{height}.jpg"},"giantbomb_id":24024,"_links":{},"box":{"large":"http://static-cdn.jtvnw.net/ttv-boxart/League%20of%20Legends-272x380.jpg","medium":"http://static-cdn.jtvnw.net/ttv-boxart/League%20of%20Legends-136x190.jpg","small":"http://static-cdn.jtvnw.net/ttv-boxart/League%20of%20Legends-52x72.jpg","template":"http://static-cdn.jtvnw.net/ttv-boxart/League%20of%20Legends-{width}x{height}.jpg"},"_id":21779,"name":"League of Legends"},"viewers":31252,"channels":386},{"game":{"logo":{"large":"http://static-cdn.jtvnw.net/ttv-logoart/StarCraft%20II%3A%20Wings%20of%20Liberty-240x144.jpg","medium":"http://static-cdn.jtvnw.net/ttv-logoart/StarCraft%20II%3A%20Wings%20of%20Liberty-120x72.jpg","small":"http://static-cdn.jtvnw.net/ttv-logoart/StarCraft%20II%3A%20Wings%20of%20Liberty-60x36.jpg","template":"http://static-cdn.jtvnw.net/ttv-logoart/StarCraft%20II%3A%20Wings%20of%20Liberty-{width}x{height}.jpg"},"giantbomb_id":20674,"_links":{},"box":{"large":"http://static-cdn.jtvnw.net/ttv-boxart/StarCraft%20II%3A%20Wings%20of%20Liberty-272x380.jpg","medium":"http://static-cdn.jtvnw.net/ttv-boxart/StarCraft%20II%3A%20Wings%20of%20Liberty-136x190.jpg","small":"http://static-cdn.jtvnw.net/ttv-boxart/StarCraft%20II%3A%20Wings%20of%20Liberty-52x72.jpg","template":"http://static-cdn.jtvnw.net/ttv-boxart/StarCraft%20II%3A%20Wings%20of%20Liberty-{width}x{height}.jpg"},"_id":18901,"name":"StarCraft II: Wings of Liberty"},"viewers":8618,"channels":45},{"game":{"logo":{"large":"http://static-cdn.jtvnw.net/ttv-logoart/Dota%202-240x144.jpg","medium":"http://static-cdn.jtvnw.net/ttv-logoart/Dota%202-120x72.jpg","small":"http://static-cdn.jtvnw.net/ttv-logoart/Dota%202-60x36.jpg","template":"http://static-cdn.jtvnw.net/ttv-logoart/Dota%202-{width}x{height}.jpg"},"giantbomb_id":32887,"_links":{},"box":{"large":"http://static-cdn.jtvnw.net/ttv-boxart/Dota%202-272x380.jpg","medium":"http://static-cdn.jtvnw.net/ttv-boxart/Dota%202-136x190.jpg","small":"http://static-cdn.jtvnw.net/ttv-boxart/Dota%202-52x72.jpg","template":"http://static-cdn.jtvnw.net/ttv-boxart/Dota%202-{width}x{height}.jpg"},"_id":29595,"name":"Dota 2"},"viewers":5861,"channels":67},{"game":{"logo":{"large":"http://static-cdn.jtvnw.net/ttv-logoart/Path%20of%20Exile-240x144.jpg","medium":"http://static-cdn.jtvnw.net/ttv-logoart/Path%20of%20Exile-120x72.jpg","small":"http://static-cdn.jtvnw.net/ttv-logoart/Path%20of%20Exile-60x36.jpg","template":"http://static-cdn.jtvnw.net/ttv-logoart/Path%20of%20Exile-{width}x{height}.jpg"},"giantbomb_id":32562,"_links":{},"box":{"large":"http://static-cdn.jtvnw.net/ttv-boxart/Path%20of%20Exile-272x380.jpg","medium":"http://static-cdn.jtvnw.net/ttv-boxart/Path%20of%20Exile-136x190.jpg","small":"http://static-cdn.jtvnw.net/ttv-boxart/Path%20of%20Exile-52x72.jpg","template":"http://static-cdn.jtvnw.net/ttv-boxart/Path%20of%20Exile-{width}x{height}.jpg"},"_id":29307,"name":"Path of Exile"},"viewers":4646,"channels":32},{"game":{"logo":{"large":"http://static-cdn.jtvnw.net/ttv-logoart/StarCraft%20II%3A%20Heart%20of%20the%20Swarm-240x144.jpg","medium":"http://static-cdn.jtvnw.net/ttv-logoart/StarCraft%20II%3A%20Heart%20of%20the%20Swarm-120x72.jpg","small":"http://static-cdn.jtvnw.net/ttv-logoart/StarCraft%20II%3A%20Heart%20of%20the%20Swarm-60x36.jpg","template":"http://static-cdn.jtvnw.net/ttv-logoart/StarCraft%20II%3A%20Heart%20of%20the%20Swarm-{width}x{height}.jpg"},"giantbomb_id":24078,"_links":{},"box":{"large":"http://static-cdn.jtvnw.net/ttv-boxart/StarCraft%20II%3A%20Heart%20of%20the%20Swarm-272x380.jpg","medium":"http://static-cdn.jtvnw.net/ttv-boxart/StarCraft%20II%3A%20Heart%20of%20the%20Swarm-136x190.jpg","small":"http://static-cdn.jtvnw.net/ttv-boxart/StarCraft%20II%3A%20Heart%20of%20the%20Swarm-52x72.jpg","template":"http://static-cdn.jtvnw.net/ttv-boxart/StarCraft%20II%3A%20Heart%20of%20the%20Swarm-{width}x{height}.jpg"},"_id":21818,"name":"StarCraft II: Heart of the Swarm"},"viewers":3291,"channels":25},{"game":{"logo":{"large":"http://static-cdn.jtvnw.net/ttv-logoart/BIT.TRIP%20Presents%3A%20Runner2%3A%20Future%20Legend%20of%20Rhythm%20Alien-240x144.jpg","medium":"http://static-cdn.jtvnw.net/ttv-logoart/BIT.TRIP%20Presents%3A%20Runner2%3A%20Future%20Legend%20of%20Rhythm%20Alien-120x72.jpg","small":"http://static-cdn.jtvnw.net/ttv-logoart/BIT.TRIP%20Presents%3A%20Runner2%3A%20Future%20Legend%20of%20Rhythm%20Alien-60x36.jpg","template":"http://static-cdn.jtvnw.net/ttv-logoart/BIT.TRIP%20Presents%3A%20Runner2%3A%20Future%20Legend%20of%20Rhythm%20Alien-{width}x{height}.jpg"},"giantbomb_id":36644,"_links":{},"box":{"large":"http://static-cdn.jtvnw.net/ttv-boxart/BIT.TRIP%20Presents%3A%20Runner2%3A%20Future%20Legend%20of%20Rhythm%20Alien-272x380.jpg","medium":"http://static-cdn.jtvnw.net/ttv-boxart/BIT.TRIP%20Presents%3A%20Runner2%3A%20Future%20Legend%20of%20Rhythm%20Alien-136x190.jpg","small":"http://static-cdn.jtvnw.net/ttv-boxart/BIT.TRIP%20Presents%3A%20Runner2%3A%20Future%20Legend%20of%20Rhythm%20Alien-52x72.jpg","template":"http://static-cdn.jtvnw.net/ttv-boxart/BIT.TRIP%20Presents%3A%20Runner2%3A%20Future%20Legend%20of%20Rhythm%20Alien-{width}x{height}.jpg"},"_id":32872,"name":"BIT.TRIP Presents: Runner2: Future Legend of Rhythm Alien"},"viewers":2703,"channels":6},{"game":{"logo":{"large":"http://static-cdn.jtvnw.net/ttv-logoart/World%20of%20Warcraft%3A%20Mists%20of%20Pandaria-240x144.jpg","medium":"http://static-cdn.jtvnw.net/ttv-logoart/World%20of%20Warcraft%3A%20Mists%20of%20Pandaria-120x72.jpg","small":"http://static-cdn.jtvnw.net/ttv-logoart/World%20of%20Warcraft%3A%20Mists%20of%20Pandaria-60x36.jpg","template":"http://static-cdn.jtvnw.net/ttv-logoart/World%20of%20Warcraft%3A%20Mists%20of%20Pandaria-{width}x{height}.jpg"},"giantbomb_id":36734,"_links":{},"box":{"large":"http://static-cdn.jtvnw.net/ttv-boxart/World%20of%20Warcraft%3A%20Mists%20of%20Pandaria-272x380.jpg","medium":"http://static-cdn.jtvnw.net/ttv-boxart/World%20of%20Warcraft%3A%20Mists%20of%20Pandaria-136x190.jpg","small":"http://static-cdn.jtvnw.net/ttv-boxart/World%20of%20Warcraft%3A%20Mists%20of%20Pandaria-52x72.jpg","template":"http://static-cdn.jtvnw.net/ttv-boxart/World%20of%20Warcraft%3A%20Mists%20of%20Pandaria-{width}x{height}.jpg"},"_id":32954,"name":"World of Warcraft: Mists of Pandaria"},"viewers":2090,"channels":100},{"game":{"logo":{"large":"http://static-cdn.jtvnw.net/ttv-logoart/Ultimate%20Marvel%20vs.%20Capcom%203-240x144.jpg","medium":"http://static-cdn.jtvnw.net/ttv-logoart/Ultimate%20Marvel%20vs.%20Capcom%203-120x72.jpg","small":"http://static-cdn.jtvnw.net/ttv-logoart/Ultimate%20Marvel%20vs.%20Capcom%203-60x36.jpg","template":"http://static-cdn.jtvnw.net/ttv-logoart/Ultimate%20Marvel%20vs.%20Capcom%203-{width}x{height}.jpg"},"giantbomb_id":35938,"_links":{},"box":{"large":"http://static-cdn.jtvnw.net/ttv-boxart/Ultimate%20Marvel%20vs.%20Capcom%203-272x380.jpg","medium":"http://static-cdn.jtvnw.net/ttv-boxart/Ultimate%20Marvel%20vs.%20Capcom%203-136x190.jpg","small":"http://static-cdn.jtvnw.net/ttv-boxart/Ultimate%20Marvel%20vs.%20Capcom%203-52x72.jpg","template":"http://static-cdn.jtvnw.net/ttv-boxart/Ultimate%20Marvel%20vs.%20Capcom%203-{width}x{height}.jpg"},"_id":32245,"name":"Ultimate Marvel vs. Capcom 3"},"viewers":1484,"channels":6},{"game":{"logo":{"large":"http://static-cdn.jtvnw.net/ttv-logoart/RuneScape-240x144.jpg","medium":"http://static-cdn.jtvnw.net/ttv-logoart/RuneScape-120x72.jpg","small":"http://static-cdn.jtvnw.net/ttv-logoart/RuneScape-60x36.jpg","template":"http://static-cdn.jtvnw.net/ttv-logoart/RuneScape-{width}x{height}.jpg"},"giantbomb_id":2268,"_links":{},"box":{"large":"http://static-cdn.jtvnw.net/ttv-boxart/RuneScape-272x380.jpg","medium":"http://static-cdn.jtvnw.net/ttv-boxart/RuneScape-136x190.jpg","small":"http://static-cdn.jtvnw.net/ttv-boxart/RuneScape-52x72.jpg","template":"http://static-cdn.jtvnw.net/ttv-boxart/RuneScape-{width}x{height}.jpg"},"_id":2083,"name":"RuneScape"},"viewers":1426,"channels":47},{"game":{"logo":{"large":"http://static-cdn.jtvnw.net/ttv-logoart/Minecraft-240x144.jpg","medium":"http://static-cdn.jtvnw.net/ttv-logoart/Minecraft-120x72.jpg","small":"http://static-cdn.jtvnw.net/ttv-logoart/Minecraft-60x36.jpg","template":"http://static-cdn.jtvnw.net/ttv-logoart/Minecraft-{width}x{height}.jpg"},"giantbomb_id":30475,"_links":{},"box":{"large":"http://static-cdn.jtvnw.net/ttv-boxart/Minecraft-272x380.jpg","medium":"http://static-cdn.jtvnw.net/ttv-boxart/Minecraft-136x190.jpg","small":"http://static-cdn.jtvnw.net/ttv-boxart/Minecraft-52x72.jpg","template":"http://static-cdn.jtvnw.net/ttv-boxart/Minecraft-{width}x{height}.jpg"},"_id":27471,"name":"Minecraft"},"viewers":1297,"channels":50}],"_links":{"next":"https://api.twitch.tv/kraken/games/top?limit=10&offset=10","self":"https://api.twitch.tv/kraken/games/top?limit=10&offset=0"},"_total":280}
DGVFHFHIOLJ;

 $regex =<<<DRTE
"name":"
DRTE;
 $result = regexreplace($test, $regex, <crlf>);

 $regex =<<<DRTE
{"top":.*
DRTE;
 $result = regexreplace($result, $regex);

 $regex =<<<DRTE
"},"viewers.*
DRTE;
 $result = regexreplace($result, $regex);

 text $result;
Indirect way. There's probably a bug in how <crlf> is handled in regex, hence the first empty line in the results.

Re: Twitch.tv VLC script UPDATE 0.2 (feedback requested!)

Posted: 28 Feb 2013 12:55
by highend
So we're looking at the following code:

Edit: Changed [A-Z] to [A-Z0-9] to match games beginning with digits

Code: Select all

 download ("https://api.twitch.tv/kraken/games/top?limit=50", "<xypath>\Swap\WGET.tmp", "o");
 $APIGames = readfile("<xypath>\Swap\WGET.tmp", "t", , , );
 delete("0", "0", "<xypath>\Swap\WGET.tmp");
 $regEx = "([""][A-Z]((\w*\s*))*[""])|([""][A-Z]((\w*\s*))*[:](\w*\s*)*[""])"; 
 $Matches = regexmatches("$APIGames", "$regEx", "|", "1");
 $g_Games = "";
 foreach($Title, $Matches, "|"){
  $g_Games = $g_Games.quote("$Title", "1")."|";
 }
 }
You can simplify it in this way:

Code: Select all

 download ("https://api.twitch.tv/kraken/games/top?limit=10", "<xypath>\Swap\WGET.tmp", "o");
 $APIGames = readfile("<xypath>\Swap\WGET.tmp", "t", , , );
 delete("0", "0", "<xypath>\Swap\WGET.tmp");
 $regEx = "([""][A-Z0-9](\w*\s*([.:])?)+[""])";
 $g_Games = replace(regexmatches("$APIGames", "$regEx", "|", "1"), chr(34));
Regarding your regex:
1. You don't need the or ("|") because you can use "(:)?" instead. It makes the existence of ":" optional. So we can delete the complete first part including the "|".
2. We can put the optional ":" inside your second backreference group, instead of repeating the full group with the ":" as a possible delimiter.
Btw, I've changed the "*" for that backreference group to "+", because a game name won't probably consist of only one char [A-Z], right?
Additionally, you should include the "." in the optional chars group, otherwise you'll miss games, that include the dot in their name.
E.g.: BIT.TRIP Presents: Runner2: Future Legend of Rhythm Alien
3. You don't need an additional foreach loop, just to unquote your items. You can do it with a simple replace on the $regEx variable. chr(34) is the quotation mark.

Regards,
Highend

Re: Twitch.tv VLC script UPDATE 0.2 (feedback requested!)

Posted: 28 Feb 2013 14:02
by Marco
Little note: the regex works because you assume games start with an upper case letter. "2 Fast 2 Furious" wouldn't be matched. [Don't even know if such game exists]
Maybe regexmatching

Code: Select all

"name":".+?"}}
yields to better results. Further processing needed.

Re: Twitch.tv VLC script UPDATE 0.2 (feedback requested!)

Posted: 28 Feb 2013 14:23
by highend
you assume games start with an upper case letter
Not my assumption, I just took the original regex.

But it's an easy change, just replace
[A-Z]

with

[A-Z0-9]

Re: Twitch.tv VLC script UPDATE 0.2 (feedback requested!)

Posted: 28 Feb 2013 15:25
by Marco
It was a generic/impersonal "you" :wink:

Re: Twitch.tv VLC 0.5.1 Update 24/04/13 - Support for ALL ga

Posted: 24 Apr 2013 13:58
by 40k
With version 0.5.1 all games, including those using a colon (:) in the title, are now supported.

Classic examples are games like Starcraft II: Heart of the Swarm and Call of Duty: Black Ops 2

Re: Twitch.tv VLC 0.5.1 Update 24/04/13 - Support for ALL ga

Posted: 26 Apr 2013 18:00
by 40k
Perhaps a silly question but does anyone else actually use this script? I write this one for myself, but it would save me the time of posting it if I just kept it local :D