Go
Not registered? Sign up!

[Solution]Youtube Get Video [Part 2]

Google Translate
57 posts | return to the General Chat forum | get the rss feed for this thread

Aug. 30, 2009Bouke Regnerus

This is Part 2 of the YouTube Downloader & Streamer, all information on how to use this script can be found on this page. Only read the previous part for reference, do not use any of the old scripts on that page because they don't work anymore
YouTube Downloader & Streamer
Because some people didn't know what script or code to use from the old tread, and because it was getting far to long. I created a new tread with all information to download and use the YouTube Downloader & Streamer.
http://bit.ly/Yf0jF
Download and Install
# To download the script please go to: http://bit.ly/Yf0jF, and click on download.
# Then choose some options, like if you want to download the FLV or MP4 format. And click on the download button.
# After 5 seconds a zip folder should start downloading.
# After the download is complete, unpack the files. And click on the readme shortcut.
# Upload your files to your server, and read the readme page to configure the script.

Problems and Errors
If you get an error, you can read the readme file to find out what the error means. And maybe fix it your self. If the script doesn't work at all, please try agian, send me an email (bouke.regnerus@gmail.com) or post your problem here in this tread.

Rules
# Please don't spam in this tread.
# Do not post really long pages of code. If you need to post a really long script or code send me an email (bouke.regnerus@gmail.com).
# Use the code tags, if you need to post code.

Donation
You could donate a few bucks for me on PayPal by clicking the Donate button on this page (http://bit.ly/Yf0jF).
I would also love to see people using this script on their website, post your links here or send me an email (bouke.regnerus@gmail.com).

License
If you use this script, I would love to see an attribution link to the script. But it isn't required. You can use this script for any project. If you use this script for a commercial project I would love to see a donation.

Click on this link to go to the download page:
http://bit.ly/Yf0jF
YouTube Downloader & Streamer by Bouke Regnerus

Aug. 30, 2009Sykoi

I've been using this code for a project of mine and it seems to work well, however I've noticed various videos just don't download. I'm currently tracking down the bug, however I thought I would share the debug information with everyone.

I've put it on pastebin to keep this thread clean.
http://pastebin.com/m635944df


All debug information was gotten by putting print "<pre>". print_r(array($i, $video_id, $video), 1) ."</pre>";
Above the return in the video() function.


Edit:
Fixed it: http://pastebin.com/f64c7859e

Aug. 31, 2009Bouke Regnerus

@Sykoi, thanks! I will test this tomorrow (sorry no time today). And if it works, i will add it.

Aug. 31, 2009wil

Hi,,what this fix do??

Aug. 31, 2009Bouke Regnerus

Im not shure what it fixes, but i will test it tomorrow. Maybe @sykoi knows...

Aug. 31, 2009Sykoi

The new code is just a better way of getting the highest quality download for .flv files from youtube. The old code (Sorry I modified it a bit to fit my standards, but it's the same code, without the error.flv) failed on certain videos. If I had to guess why it failed, I would have to say because if quality 34 and quality 6 did not exist in the fmt_url array, it would assume there was only one quality level to be used - which wasn't always the case, sometimes there would be 18 and 5 or something along those lines.

I look forward to hearing your opinion, Bouke, as I didn't look into the problem as much as I could - I took a shot in the dark for fixing what I thought -may- have been the problem and it worked. Looking at the old code, it doesn't seem like my code should fix the issue I described above any better than yours, but who knows - it works, so I'm not complaining.

Sep. 01, 2009Bouke Regnerus

@Sykoi Your code works, but i can't find a real difference between this and the old code? Can you give me an example?

Im testing it here.
http://1.leefjedichter.nl/yt/parameters.php?v=[Video_ID]

NEW is your code, OLD my original one.

Sep. 01, 2009Sykoi

That's odd, it must have been the servers I tested on that did not work correctly... Sorry for the false alarm I guess :P

Sep. 02, 2009Bouke Regnerus

@Sykoi, im still going to replace my code with yours. I can't really find a real big difference between the two, but I just have a feeling it is more reliable then mine xD.

Sep. 03, 2009Nick

Is there a change I can make to force this code to specifically get the fmt=22 HD video for use with videos where I know it exists and that's the format I want?

Anyhow excellent work and thanks for sharing it!

Sep. 03, 2009Bouke Regnerus

@Nick, just download the MP4 version of this script. If the fmt 22 format is available the script will get that.

Sep. 04, 2009Nick

Hi Bouke,

I haven't been able to get it to pull in the HD video in my tests:

Here on youtube you can see the video in HD:
http://www.youtube.com/watch?v=BuSBWEqSPJk&fmt=22

but in my test you only seem to get the high quality video:
http://silktricky.com/outbreak_youtube/

Its very noticeable in the titles there which aren't crisp compared to the video on youtube, which shows its not pulling in the same HD video. Thanks for any advice you can give.

Sep. 06, 2009wil

why this video not play? http://www.youtube.com/watch?v=8c0wqoj3lEM

groeten

Sep. 06, 2009Bouke Regnerus

@wil, maybe a temporary problem with YouTube's servers? Because it just plays here.

Sep. 06, 2009Bouke Regnerus

I've created a google code project, for the download files. So you can subscribe on the feeds, and get the newest files when they come out.

http://code.google.com/p/yts/

You can also post your issues here.

PS. I have added a token to the demo script (the token changes every day), so people can't use the script from the demo site anymore but have to download it.

I will create a script, for people who don't have a server with php support or can't host the script, later....

Sep. 07, 2009jane

Hi,

I am unable to make it work from my local host with php enabled. It always play a error video "This video is not available". In fact the video is available at youtube.

<div id="player"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</div>
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
var s1 = new SWFObject("player4.5.swf","mpl","470","320","9");
s1.addParam("allowfullscreen","true");
s1.addParam("allowscriptaccess","always");
s1.addParam("menu","false");
s1.addParam('flashvars','&file=http://127.0.0.1/test/youtube/latest/11110/video/index.php%3Fv%3DLnhMLYQl2Rk&type=video');

s1.write("player");

</script>
</div>


Unable to locate the issue. Please help me. Thanx in advance.

Sep. 07, 2009Bouke Regnerus

@jane Sorry I don't see a problem, the videos works just fine here. Maybe an online example?

PS. You can also post you're problems here, so this tread stays clean. (I have added yours)
http://code.google.com/p/yts/issues/list

Sep. 12, 2009wil

@bouke,

Your script stop working?

groeten

Sep. 12, 2009Bouke Regnerus

@wil you mean on the website? Sorry I was working on that today, it didn't work today because I changed some things on the website (like a new navigation bar). Everything works again right now.

Sep. 13, 2009LA

hi, why have you now have put a custom youtube logo on top of your website's video examples?

Sep. 13, 2009Bouke Regnerus

@LA, Its just for the examples. You don't have to put the youtube logo on your website.

Sep. 15, 2009ebookict

I can't get video from youtube
plz help me

demo: http://ebookict.com/test/

Sep. 15, 2009Bouke Regnerus

@ebookict can you give me an example of your error? because you have lots of files in that dir. so I can't really see where the error is.

Sep. 15, 2009ebookict

http://ebookict.com/test/download-flv.php

i can't get video from youtube

Download URL
Failure: cannot get download url...

source: http://ebookict.com/test.zip

Sep. 15, 2009Bouke Regnerus

@ebookict, lol you don't use my script but phptube. This doesn't work anymore.

To get your website work, download my script here: http://bit.ly/Yf0jF, download the files and put it on your website...

Sep. 15, 2009ebookict

Bouke Regnerus

Thanks for the support

Sep. 17, 2009Fletch

Warning: file_get_contents(http://youtube.com/get_video_info?video_id=wdk_ySGIE3w) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 402 Payment Required in /usr/home/tester/public_html/index.php on line 43

Take this error. Dont work your script for me.

Sep. 18, 2009Bouke Regnerus

@Fletch sorry you can not use the script, because you need support for "file_get_contents", you can search for webhosting that does support "file_get_contents" there are lots of free ones out there too....

Sep. 18, 2009cenourinha

Hi there,

Take a look at this:
http://code.google.com/p/yts/issues/detail?id=2
:)

Sep. 23, 2009winkkk

Thank Bouke Regenerus
Your script work fine for me for a fews day.
But now I got the same error as Fletch(sep 17 2009)

I think youtube check where video request come from? I mean they block ours host/ip.
My Http respound from youtube as error 402 Payment required.
I think the problem is my website has alot of traffic and alot if video request about 10,000 uip/day.

So that why your script not work for Fletch and me and some other in later soon..

I wonder is there any way or any how to hide ip or referer hosting when your script request data from youtube?!?
Please help.. I'm looking for solve the problem.
Sorry for my bad in english.
Thank.

Sep. 23, 2009Bouke Regnerus

@winkkk, yes it could be youtube blocking individual sites. Just like they did with techcrunch's download streamer. (http://bit.ly/Gh14W).
I don't know if an anonymous proxy would help, because it's just a matter of time and youtube will block that one too.

Sep. 23, 2009xssc

Amanda Lear - Enigma (give a bit of hmm to me)

Sep. 25, 2009Bouke Regnerus

I will be updating the script soon, this update will NOT fix the "402 error". But it will send information about every video that is played to me, this way I can investigate the "402 error" and maybe other errors in the future.

This will also allow me to create some sort of API in the future (to show how many views a video has or something).

Sep. 26, 2009Bouke Regnerus

#UPDATE

Please redownload the script, I released a new version.

This version includes new features like:
- An online Cache file, so no cache.xml included anymore.
- Error reporting, if any error (like "402 Payment required") occurs the error is sent back to me.

I will release an API in the near future, so you can keep track of the views of an video.

Sep. 27, 2009winkkk

Thank Bouke
I wonder why Clipnabber.com still work on some clip that not work on your script.
If youtube block ours ip/host,I think clipnabber should blocked for a long time but it's never!?! Alway work fine for me.

Is that relate to how to sending player parameter like..
iv_load_policy or cc_load_policy.

http://code.google.com/intl/th/apis/youtube/player_parameters.html

Sep. 29, 2009bun

ill donate 20 on Wednesday

Sep. 30, 2009Bouke Regnerus

@bun tnx!


I see a lot of people mess with the error submission, Please don't, I do not save any personal information. It is just to spot any errors, so I can fix them.

Sep. 30, 2009Bouke Regnerus

the error submission showed this 4 videos all have the same error: HTTP Error 415 - Unsupported media type (http://www.checkupdown.com/status/E415.html)


http://www.youtube.com/watch?v=OqKrWXgTSu4
http://www.youtube.com/watch?v=bqZauhidT1w
http://www.youtube.com/watch?v=lytwbcBrkjA
http://www.youtube.com/watch?v=c0gDqDXpUW0


But I can't really figure out why... does anybody know?

Oct. 06, 2009Steve

Thanks Bouke - nice

Do you know if YouTube ever changes the URLS in the fmt_url_map, or are they static once a video is published?

Thanks
Steve

Oct. 08, 2009Bouke Regnerus

@mp3drug.com please don't spam here... do it somewhere else.

Don't click on the links from mp3drug.com, he just wants more visitors on his site. He still uses the old get video method that doesn't work anymore for an year or so... and the second link where he is "giving away" tje code doesn't work.

Oct. 09, 2009Bouke Regnerus

@Steve i'm not sure but i think the fmt_url changes after some time... just like the tokens.

Oct. 16, 2009wil

Bouke your script stop working??yesterday and today no success.

groeten

Oct. 16, 2009Bouke Regnerus

@wil, the script it self still works fine... but if your host is "ipod1.livebuster.com" you have the HTTP 402 error (Payment Required). I still don't know how to fix this...

Oct. 20, 2009Rob

Longtail is now supporting mp4 format if we rename the file to flv! I get the video format not available error more often for the new videos, I think it would be good if you add a script to download the mp4 one if the flv wasn't available.

Oct. 20, 2009Bouke Regnerus

@Rob the script allready downloads the mp4 if flv is not abailable....

Nov. 05, 2009winkkk

Any update?? Some clip still not work with your script but work fine with clipnabber.com
Hope you can do better than them...
best wishes..
thank

Nov. 06, 2009Bouke Regnerus

@winkkk sorry there is allready an update for those vidoes... but I forgot to upload it, I will do that soon. But the fix is easy:

go to line 55 or something, and replace with this one (the current line is allmost the same):

$matches = str_replace('", "','&',str_replace('": "','=',$matches[1][9])); parse_str(str_replace(array('{','}'),'',$matches),$i);

Nov. 07, 2009Bouke Regnerus

#UPDATE

Version 2.2.1 is online!, this one fixes the problems with the "disabled for embedding" videos.

Download it now:
http://bit.ly/26mkA3

Nov. 07, 2009wil

http://www.youtube.com/watch?v=TrKNYtyT1LA

tis video i not getting to work,,on your site too bourke,,can you try?

groeten

Nov. 07, 2009Bouke Regnerus

@wil download de nieuwste versie, dan zou deze video ook moeten werken wink . Mijn site is nog niet geupdate.

Translation: Try then newest version, this video should work then wink My website has not been updated yet.

Nov. 07, 2009Calvin

Thanks to everyone who has worked this problem and posted their solutions. The following is a ruby function that works similarly to the PHP solutions: It makes one call to get_video_info to get the token, before re-assembling the url. Available formats can be checked through a similar approach. This solution requires Hpricot.

def ytURL(key, fmt)
if doc = open("http://youtube.com/get_video_info?video_id="+key) { |f| Hpricot(f) }
@t = doc.to_s.split(/&/).map{ |i| i.split(/=/) }
for t in @t
if t[0] == "token"
@token = t[1]
end
end
if(@token != "")
@url = @ytURL = "http://www.youtube.com/get_video.php?video_id=#{key}&vq=2&fmt=#{fmt}&t=#{@token}"
end
return @videoHD;
end
end

Bottom line: It works locally- beautifully. But online, it fails miserably. Leading me to the following conclusion:

Youtube Tokens are encoded IP Addresses.

Perhaps a hash of the datetime, the user's IP address and some secret salt. Maybe even the content ID. When a user makes a request to get_video_info, the request IP is encoded into a token. When the user makes a request for the content with the token, the token is decoded and the token IP is matched against the content request IP. I wouldn't doubt this token check also uses the datetime to determine if the token has expired. Who knows, maybe they are logging all this into a database - Although the overhead would be tremendous. It seems to me it would be easier to check this dynamically.

Can anyone confirm this? Has anyone been able to devise a solution that works as well online, as it does locally?

Nov. 08, 2009Bouke Regnerus

@Calvin YouTube tokens are NOT encoded IP addresses, because they change all the time. It is possible some timestamp is included in the token. But you can never find out what the token will be.

Nov. 15, 2009Bouke Regnerus

People waiting on more features like the API; im still working on it, but it's not coming any time soon. I am using hosting space from a friend, and her contract will expire next year. So I need to find new server space by March...

When I have my own server space I will add more features.

PS. Anyone knows good, cheap webhosting? Because I don't have a lot of money (im only 15 as some of you may know). Or a good method to turn an old computer into a server...

Nov. 16, 2009Rob

I think it would be great if you write a script to ping the domain of the server and replace it with the IP address. I did this and it worked. it makes it impossible to find out that the video is loading from youtube servers.

Nov. 18, 2009Bouke Regnerus

@Rob how can I do this?

PS. im not saying I'm going too

Nov. 19, 2009just me

bouke you know a damn lot for a tender age of 15. wooooow.

but ok when i was 15 there was neither internet nor cell phones, and the berlin wall came down, been also a nice event wink

Nov. 20, 2009Bouke Regnerus

@just me, I think half of all 15 year olds know as much as I do... wink

Add a reaction

You can also return to the category or try this search for related threads.


 

Search the Forums

Go

Support

Support Here are some helpful links to learn more about the JW Player™:

Monetize Your Video

Monetize Your Video Earn money with ads from LongTail's AdSolution. Watch our demos and sign up now!

Why Buy a License?

Why Buy a License? If you don’t buy a commercial license, you cannot use a JW Player™ on (i) a site that has ads; (ii) a corporate site; or a (iii) CMS. Our licenses are very inexpensive, so what are you waiting for? Buy a license today.