All this talk about deep linking to YouTube files. I've done some digging and it would appear that getting a video out of YouTube, given a video URL, is fairly simple really.
Perhaps prone to minor changes if YouTube tweak stuff, but we ought to be able to sniff out how it works afterwards?
Anybody fancy poking the YouTube application or writing a YouTube "player"? I suggest writing a new one to work around the search API not being 'known' at this time, though perhaps a perusal of the published API might help?Anyway, here are the results of my investigations.
We shall work with a rather sweet little Christmas song that is very popular in Japan. It dates from the mid-'80s. This is mostly an audio track, but the static (video) picture does change from time to time. http://www.youtube.com/watch?v=k8QsZCHhZeY
[ TATSURO YAMA[chocolate ice cream]A
- Christmas Eve
(1983) ]^^ note the "chocolate ice cream". His name is Ya-ma-shi-ta, the obscenity parser is just being a bit enthusiastic. I wonder what it would do with Scun...thorpe (a real British town).
Okay. The first thing we need to do is enquire this video. For this, we call:http://www.youtube.com/get_video_info?&video_id=k8QsZCHhZeY&el=embedded&ps=default
where the ID is extracted and placed after &video_id=
This will return an epic amount of gobbledegook, most of it is no use whatsoever to us.
Don't bother parsing the available formats, we will be forcing format 5 (old style FLV with 24 lines max and MP3 audio (frequently mono, thankfully not in this case!).
What is important to us is the "token
", perhaps to make it a little more complicated for auto-rippers.
This is in the wodge of data thrown to us by the get_video_info
call. Just search for "&token=
" and pull everything until the next '&
'. The token for this video is: vjVQa1PpcFNQoZDma1YJlw0QOdH7AMR0yfcuRp0SRdk%3D
I did this using Firefox. On the OSD, we probably need to parse "%3D
" to '=
This is then assembled into a call to retrieve the video:http://www.youtube.com/get_video?video_id=
Where the <id
> is the video ID as seen in YouTube URLs, and <token
> is the string of gibberish we just parsed out of the info file.&fmt=5
forces us to 240p mode. It is my experience that pretty much every video has a 240p (inc. those that don't claim to).
The complete URL is, thus:http://www.youtube.com/get_video?video_id=k8QsZCHhZeY&t=vjVQa1PpcFNQoZDma1YJlw0QOdH7AMR0yfcuRp0SRdk%3D&eurl=&el=&ps=&asv=&fmt=5
This will return a file called "videoplayback
" (no extension).This may not work, if you click the link above. I don't know if the token is fixed per video, or based upon the current time, or your IP address, or what.
I saved this to my harddisc, gave it an FLV extension, and it plays fine in MPlayer. The specifics of this file are as follows:
Complete name : \\Azumi\Misc\Downloads\videoplayback.flv
Format : Flash Video
File size : 4.50 MiB
Duration : 4mn 15s
Overall bit rate : 148 Kbps
httphostheader : v2.cache3.c.youtube.com
Format : H.263
Duration : 4mn 15s
Bit rate : 80.4 Kbps
Width : 320 pixels
Height : 240 pixels
Display aspect ratio : 4:3
Frame rate mode : Constant
Frame rate : 29.970 fps
Bits/(Pixel*Frame) : 0.035
Stream size : 2.45 MiB (55%)
Format : MPEG Audio
Format version : Version 2
Format profile : Layer 3
Mode : Joint stereo
Mode extension : MS Stereo
Duration : 4mn 15s
Bit rate mode : Variable
Bit rate : 58.9 Kbps
Channel(s) : 2 channels
Sampling rate : 22.05 KHz
Bit depth : 16 bits
Stream size : 1.80 MiB (40%)
Just thrown it across the LAN to the OSD. It is playing right now (as I write this).
I am starting to get irritated that I don't have a build environment running (and that I have no clue about Qt libs), for it looks like a real basic (user-provided URL) YouTube player could be built from a couple of fetches, a braindead parser, and then throwing the lot to the video playback library.
I don't know if you need to have the entire file in order to begin playback. To be honest, I would be inclined to download to the default location (USB or SD as applicable) and play back once the file is there. This will make the OSD a lot more resiliant to momentary hiccups in the download that would affect realtime playback.
Now, for verification, let's try this again. A real video this time.
The video chosen this time is: http://www.youtube.com/watch?v=GcJBFQ_2wbQ
- Secret Base
(Kimi ga kureta mono
) english subtitled.avi ]
Read the subs, it's quite a sad song even though it doesn't sound it.
The info here is:http://www.youtube.com/get_video_info?&video_id=GcJBFQ_2wbQ&el=embedded&ps=default
A bit of wetware parsing by eyeballing the file in Metapad, token is: vjVQa1PpcFNxE7455ETMDbjzBrxXVppI2hsuMHb3t4w%3D
It was supposed to take about a minute, it took nearly four as the speed kept bouncing from 200K/sec (not bad, 260 is maxing out for me) to a less impressive 30K/sec. If somebody writes this proggy, please add a K/sec calculation, it is something to look at.
" -> "zone_secretbase.flv
Tossed to the OSD.
There's an even cuter (MAKO - yes!
) version of this song (audio only, static picture) at: http://www.youtube.com/watch?v=LS0s1sUxztY
Well. It's 4.40am here. I'm off to grab a Kitkat, watch the the most recent episode of "Ore No Imouto Ga Konna Ni Kawaii Wake Ga Nai
" and then go to bed.
Hope this info is useful to somebody.