Take the 2-minute tour ×
Web Applications Stack Exchange is a question and answer site for power users of web applications. It's 100% free, no registration required.

I am trying to download all available files that are different qualities of a single video using the YouTube API, but every URL I follow to download the video results in a 403.

Script:

#!/bin/bash

_video_info=$(wget -qO- -- "http://www.youtube.com/get_video_info?&video_id=$1&el=detailpage&ps=default&eurl=&gl=US&hl=en")
_video_urls=$(sed -e 's|%25|%|g' -e 's|%25|%|g' -e 's|%3A|:|g' -e 's|%2F|/|g' -e 's|%26|\&|g' -e 's|%3D|=|g' -e 's|%3F|?|g' -e 's|%2C|,|g' -e 's|%2B|+|g' -e 's|%3B|;|g' -e 's|%22|"|g' -e 's|.*url_encoded_fmt_stream_map=url=\(.*&itag=[0-9]*\).*|\1|' -e 's|,url=|\n|g' <<< "${_video_info}")
_video_formats=$(sed 's|.*fmt_list=\([^\&]*\)\&.*|\1|' <<< "${_video_info}")

while read -r _video_download_url; do
    wget "${_video_download_url}"
done <<< "${_video_urls}"

Output:

$ ./ytdl 5_xCfrpif4Q
--2011-08-19 00:14:21--  http://o-o.preferred.mil01s10.v1.lscache5.c.youtube.com/videoplayback?sparams=id,expire,ip,ipbits,itag,ratebypass&fexp=907312,904535,913501,906918&itag=43&ip=93.0.0.0&signature=32944F059B26E01072437068EAC6449FCD975383.2272568B833A7A706A82236297B6D6B8D900D330&sver=3&ratebypass=yes&expire=1313733600&key=yt1&ipbits=8&id=e7fc427eba627f84&quality=medium&fallback_host=tc.v1.cache5.c.youtube.com&type=video/webm;+codecs=%22vp8.0,+vorbis%22&itag=43
Resolving o-o.preferred.mil01s10.v1.lscache5.c.youtube.com... 173.194.2.38, 2a00:1450:4002:3::6
Connecting to o-o.preferred.mil01s10.v1.lscache5.c.youtube.com|173.194.2.38|:80... connected.
HTTP request sent, awaiting response... 403 Forbidden
2011-08-19 00:14:22 ERROR 403: Forbidden.

--2011-08-19 00:14:22--  http://o-o.preferred.mil01s10.v15.lscache6.c.youtube.com/videoplayback?sparams=id,expire,ip,ipbits,itag,algorithm,burst,factor&fexp=907312,904535,913501,906918&algorithm=throttle-factor&itag=34&ip=93.0.0.0&burst=40&sver=3&signature=C623D3002F9BC919B8D83666DB1274D9E37F9B63.A6FF45792995744504C9DF39EDEE8326D74450C5&expire=1313733600&key=yt1&ipbits=8&factor=1.25&id=e7fc427eba627f84&quality=medium&fallback_host=tc.v15.cache6.c.youtube.com&type=video/x-flv&itag=34
Resolving o-o.preferred.mil01s10.v15.lscache6.c.youtube.com... 173.194.2.56, 2a00:1450:4002:3::18
Connecting to o-o.preferred.mil01s10.v15.lscache6.c.youtube.com|173.194.2.56|:80... connected.
HTTP request sent, awaiting response... 403 Forbidden
2011-08-19 00:14:22 ERROR 403: Forbidden.

--2011-08-19 00:14:22--  http://o-o.preferred.mil01s10.v13.lscache5.c.youtube.com/videoplayback?sparams=id,expire,ip,ipbits,itag,ratebypass&fexp=907312,904535,913501,906918&itag=18&ip=93.0.0.0&signature=88D969809C0625D2B7AC600C0D0C127F7AD72022.CA5355DAEF26B2AADBD6AAFF1726A331C54850C0&sver=3&ratebypass=yes&expire=1313733600&key=yt1&ipbits=8&id=e7fc427eba627f84&quality=medium&fallback_host=tc.v13.cache5.c.youtube.com&type=video/mp4;+codecs=%22avc1.42001E,+mp4a.40.2%22&itag=18
Resolving o-o.preferred.mil01s10.v13.lscache5.c.youtube.com... 173.194.2.48, 2a00:1450:4002:3::10
Connecting to o-o.preferred.mil01s10.v13.lscache5.c.youtube.com|173.194.2.48|:80... connected.
HTTP request sent, awaiting response... 403 Forbidden
2011-08-19 00:14:22 ERROR 403: Forbidden.

--2011-08-19 00:14:22--  http://o-o.preferred.mil01s10.v1.lscache8.c.youtube.com/videoplayback?sparams=id,expire,ip,ipbits,itag,algorithm,burst,factor&fexp=907312,904535,913501,906918&algorithm=throttle-factor&itag=5&ip=93.0.0.0&burst=40&sver=3&signature=2D1C0BD8F7B617691F9905E79502E1FFFFF86611.C19F9CC435873BBC955C5FF82F60F7B90D140AFD&expire=1313733600&key=yt1&ipbits=8&factor=1.25&id=e7fc427eba627f84&quality=small&fallback_host=tc.v1.cache8.c.youtube.com&type=video/x-flv&itag=5
Resolving o-o.preferred.mil01s10.v1.lscache8.c.youtube.com... 173.194.2.38, 2a00:1450:4002:3::6
Connecting to o-o.preferred.mil01s10.v1.lscache8.c.youtube.com|173.194.2.38|:80... connected.
HTTP request sent, awaiting response... 403 Forbidden
2011-08-19 00:14:22 ERROR 403: Forbidden.

As you can see from the wget output, the URLs seem syntactically correct, but the servers always return a 403. This happens no matter which video I try.

I am trying to download the files from the same IP address and computer that I generated the links with. Any ideas?

share|improve this question
    
Have you tried downloading videos that your channel has uploaded? Are you attempting to use an authenticated connection with Youtube? –  Dez Mar 6 '12 at 20:55
add comment

2 Answers 2

I think you have to study this webpage carefully.

Don't forget that Youtube is a product invented by Google. Just like Google Map, you have got to obtain the API Key first

share|improve this answer
add comment

You're likely getting a 403 error due to not being authenticated via your wget command. Youtube only allows downloading videos that you own. For that you'll have to be authenticated.

Youtube TOS

Youtube downloading Support

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.