anxdpanic / plugin.video.twitch

Watch your favorite gaming streams on Kodi
https://twitchaddon.page.link/forum
270 stars 80 forks source link

View past broadcasts? #30

Closed rickydeez closed 10 years ago

rickydeez commented 11 years ago

Is it possible to add the ability to view past broadcasts?

https://github.com/justintv/Twitch-API/blob/master/v3_resources/videos.md#get-channelschannelvideos

StateOfTheArt89 commented 11 years ago

This will be the next new feature to the Twitch-Add-on. I will create a new branch since this will require some "experiments" and I have no idea how long it will take to be done.

cr08 commented 11 years ago

I am very curious as to how far you have investigated this. Reason I ask is I have been eyeing workarounds myself to easily watch Twitch past broadcasts on my XBMC box and have noted a few bits that could possibly benefit:

1) There are a handful of web tools that all do the exact same thing and that is you enter a video URL (ie: twitch.tv/user/b/1234567890) and it'll return a list of the individual 30 minute segment FLV clips ready to download. The individual clip urls do not seem to change like some other video sites or at least not quickly enough to be a bother for sitting through and watching a good ~5-6 hour broadcast. Given there are multiple tools doing this shows to me it is easily done programmatically, killing one chunk of the issue. Sadly I haven't come across any meaningful source code to see how this is actually done beyond the manual instructions of loading up the video and doing an 'inspect element' in chrome and finding the appropriate file reference.

2) Because of the videos being split up it might be problematic for playback purposes in one solid stream. Honestly I don't know if XBMC has any provisions for stuff like this. I do know that by the nature of Hulu's own service, the XBMC plugin for Hulu handles playing multiple clips back to back mostly seamlessly. Maybe just a playlist that XBMC natively runs through? Even this I would be happy with.

3) Gathering a list of past broadcasts via Twitch's own API is 100% doable. For example this link right here does the trick for me: https://api.twitch.tv/kraken/channels/minecraftwb/videos?limit=10&broadcasts=true with the documentation here: https://github.com/justintv/Twitch-API/blob/master/v2_resources/videos.md#get-channelschannelvideos

So in essence start at (3), point to (1), and point to (2).

I definitely appreciate the work so far though and an anxiously waiting for the past broadcast support. At this point my method to get these videos to my XBMC box is using one of these web tools and throw the clip URL's into a single pastable string of wget's and run that from the shell of my XBMC box. Works, but could be better. :)

rickydeez commented 11 years ago

Any updates on this yet?

Hoping it can be added soon...

rickydeez commented 11 years ago

Guess not.

ccaspers commented 11 years ago

It can probably be added, but we don't have much spare time at our hands right. So at the moment we maintain the functionality there is, without adding new one. If you know how to code, feel free to fork the repository and send us a pull request. I would appreciate that :)

cr08 commented 10 years ago

Adding in a couple more resources to help the cause. Found this blog post which details task #1 in my previous comment and stupidly simple and something I should have honestly noticed after skimming over Twitch's API: http://blogen.glorpen.pl/2013/06/twitchtv-without-adobe-flash.html

Do a playlist style setup like the Hulu plugin (select a video to play back and it will play back the first segment, cut over to an ad, play segment 2, and so on. Not a single uniform stream but the video in question is split into segments on Hulu's servers and ads inserted in between. FWIW, I am personally fine with this setup for Twitch archives. Likely the only doable option given videos are split into 30m chunks) and voila. Past that its just the glue to put it all together.

I'd certainly take a whack at it myself if I had the free time. Sadly that has come at a steep premium these days. :| But the key bits are there for people to peruse if they desire!

StateOfTheArt89 commented 10 years ago

Added in 255081bdb0b524b06c77682a5e77205776313f5d ...but untested

rickydeez commented 10 years ago

Thanks for the work @Kr0nZ, the archives seem to be working good.

One suggestion though - can you make it so when you select on a specific Past Broadcast to play, can you load and display the list of 30 minute sections?

That way you can choose where to start and keep track of where you left off. This was how the archives used to work in the old plugin. Hopefully it can work the same with the new API.

MrSprigster commented 10 years ago

@rickydeez: Once you've loaded a past broadcast you can select any of the thirty minute segments from the "Now Playing" menu in XBMC as each of the segments are added to the playlist individually.

Sprig

rickydeez commented 10 years ago

Never noticed that, thanks!

Will it keep track of played items and continue where others are left off?

MrSprigster commented 10 years ago

No worries, I'm glad to help.

Unfortunately not, when you play a past broadcast, the playlist containing the individual 30 minute segments is generated on the fly in memory and is overwritten when you play something else.

I had hoped that XBMC's resume feature would provide this functionality in the event that the playlist was saved to and loaded from disk however after a few quick tests it seems that XBMC doesn't give the option to resume from a position when loading a playlist file that has been previously played :-1:

Furthermore, it looks as though the encoding which Twitch uses for past broadcasts causes seeking to a specific time within a segment to take an unacceptably long time (upwards of a minute to process a 10 minute skip on a 120mbit connection, although I'm not sure if this wait time would be increased on a slower connection. I am however under the assumption that connection will be a factor as I believe when seeking to a certain point, the wait time is due to the player downloading all of the video up until the seek point before playback is resumed).

Sprig

Kr0nZ commented 10 years ago

I actually might have a solution to not being able to seek within a segment, when you request a video file chunk from twitch if you add a url paramater of say '?start=67203252' twitch will start the download of the file at 5mins 16 Seconds in, but I haven't tested this within XBMC yet, only through my browser. Though I'm not exactly sure what kind of measurement unit the '67203252' represents.

If this does work within XBMC, it could also be a workaround to getting video highlights to work, atleast getting them to start where the highlight is in the main video file.

Kr0nZ commented 10 years ago

OK Ive been looking into it a bit more (I decompiled the twitch player swf) and it looks like the value of the start parameter is a byte offset. The player gets this info by first making a request for only the headers of the file it wants, then it divides the 'Content-Length', in the returned header, by the total length of the video. Video lengths are given prior in the json where you get the list of video chunks. This gives you how many bytes equal 1 second, then just multiple this by how many seconds in you want the video to start.

Now I'll look into getting something with this to work inside XBMC.

EDIT: Cant get it to work, skipping the beginning of the file like this corrupts the video, because its skipping important information in the file header, I imagine the twitch flash player does something like grab a bit of the main file then starts streaming at the offset