views:

112

answers:

2

Hello all,

I'm writing a CLI for a music-media-platform. One of the features is going to be that you can directly play YouTube videos from the CLI. I don't really have an idea to do it but this one sounded the most reasonable:

I'm going to use of those sites where you can download music from YouTube, e.g. http://keepvid.com/ - then I directly stream & play this -- but I have one problem. Is there any Python library capable of doing this and if so, do you have any concrete examples? I've been looking but found nothing, even not with gstreamer.

Thanks,

William van Doorn

A: 

It appears that KeepVid is simply a javascript bookmarklet that links you to a KeepVid download page where you can then download the YouTube video in any one of a variety of formats. So, unless you want to figure out how to stream the file that it links you to, it's not easily doable. You'd have to scrape the page returned and figure out which URL you wanted to download, and then you'd have to stream from that URL (and some of the formats may or may not be streamable anyway).

And as an aside, even though they don't have a Terms of Service specified, I'd imagine that since they appear to be mostly ad-supported that abusing their functionality by going around their ad-supported webpage would be ethically questionable.

Daniel DiPaolo
Well, I was just reffering to KeepVid as an example, if there's any better sites I would be happy to hear that.
wvd
+1  A: 

You need two things to be able to download a youtube video, the video id, which is represented by the v= section of the url, and a hidden field t= which is present in the page source. I have no idea what this t value is, but it's what you need :)

You can then download the video using an url in the format;

http://www.youtube.com/get_video?video_id=*******&t=*******

Where the stars represent the values obtained.

I'm guessing you can ask for the video id from user input, as it's straightforward to obtain. Your program would then download the html source for that video, parse the source for the t value, then download the video using the newly constructed url.

For example if you open this link in your browser it should download the video, or you can use a downloading program such as wget;

http://www.youtube.com/get_video?video_id=3HrSN7176XI&t=vjVQa1PpcFNM4c8MbEhsnGaNvYKoYERIJ-hK7ErLpUI=

Jivings
I'm pretty sure YouTube blocked this way of getting their videos, also did you try to example you gave yourself?
wvd
Yes. It worked fine for me last night, but now doesn't work. I guess the location of the video changed....
Jivings
Where do you exactly find the "t=***" in a source file of the website? I tried searching it but didn't really found anything which looked like that.
wvd
Jivings