Live Chat!

how to wget flv from youtube

1 votos Vota!!

August 1st, 2007 mysurface Posted in Network, wget | Hits: 55031 |

To strip flv from youtube links, you have to complete two steps. Firstly extract the encrypted string from a youtube link, next append to get_video.php and download through wget.

The youtube links, that people distribute around will looks something like below

http://www.youtube.com/watch?v=B6fnR--IDKc

Step one, download it and extract the encrypted strings using grep.

wget -O test http://www.youtube.com/watch?v=B6fnR--IDKc

-O is to force the output filename as specified. The case above, output filename will be ‘test’.

To extract the encrypted string, use grep

grep "player2.swf" test

Updates! Due to the changes of youtube, the grep shown above was no longer working, grep “fullscreen” instead, read the comment for more details.

The encrypted string will be in between player2.swf? and

hl=en&video_id=B6fnR--IDKc&l=34&t=OEgsToPDskIlg4F-gKjbwl_pqIP6IPeI&soff=1&sk=V7GrH18hYLfT0sz5dm7GXgC

Step two, append the string to http://www.youtube.com/get_video.php? and start download.

wget -O test.flv "http://www.youtube.com/get_video.php?hl=en&video_id=B6fnR--IDKc&l=34&t=OEgsToPDskIlg4F-gKjbwl_pqIP6IPeI&soff=1&sk=V7GrH18hYLfT0sz5dm7GXgC"

Too much manual works?
You can write a bash script to ease your download, turn all manual steps into one simple step. Let say the script is know as dltube.sh, you just need to execute this:

dltube.sh http://www.youtube.com/watch?v=B6fnR--IDKc

You will get the output filename as the_title_of_the_youtube.flv.

There are some hints , in case you are interested on creating this bash script.

1. The title of the flv, you can grep it from ‘test’ (first output file from youtube link shows above).

grep "id=\"video_title\"" test

The output will be

<h1 id="video_title">xvidcap screen capture on mplayer</h1>

2. You can extract the title from the grep string using cut.

grep "id=\"video_title\"" test | cut -d">" -f2 | cut -d"<" -f1

Check out command cut for usage examples.

Enjoy your bash scripting :D

17 Responses to “how to wget flv from youtube”

  1. [...] Yahoo Contact the Webmaster Link to Article youtube how to wget flv from youtube » Posted at Linux By Examples - We explain every GNU/Linux command line by examples on Tuesday, July 31, 2007 To strip flv from youtube links, you have to complete two steps. Firstly extract the encrypted string from a youtube link, next append to get_video.php and download through wget. The youtube links, that people distribute around will looks … (first output file from youtube link shows above). grep “id=”video_title”" test The output View Original Article » [...]

  2. Probably the easiest way to download youtube vid is using youtube downloader from http://www.arrakis.es/~rggi3/youtube-dl with ffmpeg patch for avi conversion.

    # youtube-dl -a -o my.avi http://www.youtube.com/watch\?v=B6fnR–IDKc

    Anyway, nice tutorial on downloading flv with the use of scripting language.

  3. chfl4gs_:
    I tried that before, if my memory servers me right, it was written by python. That is cool.

  4. ドラマ見るならここ!DORAMA.COM…

    思い出のドラマや見逃してしまったドラマなどドラマを一挙公開中!!…

  5. Here is my version of the script:
    (it is a bash function that doesnt write temporary files)

    function ytdl {
    local yturl ythtml encurl flvtitle flvurl
    while [[ -n $1 ]]; do
    case $1 in
    “-r”) raw_name=true;;
    # for example http://www.youtube.com/watch?v=B6fnR–IDKc
    *) yturl=$1;;
    esac
    shift
    done
    ythtml=$(wget -O - “$yturl” 2>/dev/null)
    encurl=$(echo “$ythtml” | grep -o -E ‘player2\.swf?[^\"]+’ |
    head -n 1 | sed ’s/^player2\.swf?//g’)
    flvtitle=$(echo “$ythtml” | grep ‘id=\”video_title\”‘ |
    cut -d”>” -f2 | cut -d”\

  6. Where is encrypted string here ?
    uros@SvarogBg:~$ grep “player2.swf” rusia
    var swfUrl = ‘/player2.swf?v=1′;

    v=1 ? Do I missed something ?

  7. Uros:
    Due to the changes youtube have made, grep “player2.swf” no longer valid.

    try grep “fullscreen”

    grep "fullscreen" test -m1 | cut -d'?' -f2 | cut -d'"' -f1
  8. Quick and dirty version. Names the file after the title of the video (minus spaces and special characters).

    RAW=`wget -O - $1 | grep ‘fullscreenUrl’ | sed ’s/^.*video_id=//’`
    TITLE=`echo $RAW | sed ’s/^.*title=//’ | sed ’s/[^a-zA-Z0-9]//g’`
    ID=`echo $RAW |sed ’s/&fs.*$//’`
    wget -O $TITLE.flv “http://www.youtube.com/get_video.php?hl=en&video_id=$ID”

  9. it seems youtube have changed it yet again!
    now the only fields in the get request should be
    ‘video_id’ and ‘t’ (’sk’ and ‘l’ don’t seem to be used… )

    I’m not posting my code in the hope that fewer people do this and youtube takes longer to change it again…

    using a user-agent overrride in the wget calls may help avoid detection too.

  10. So utube has again changed. This script is not working any more :-( what will be the changes or the modification required in the script then ?

    thanks for the nice script.

  11. http://www.FreeYoutubeGrabber.com is another online tool to download videos from Youtube. You enter the url of youtube video and press “Grab and download” button, then choose a directory where to save, and download the video :)

  12. Here is a Bash script which only uses bash and wget to download the youtube video.
    http://www.xinilux.us/misc/index.html#hoovertube

  13. YouTubeRobot.com today announces YouTube Robot 2.0, a tool that enables you to download video from YouTube.com onto your PC, convert it to various formats to watch it when you are on the road on mobile devices like mobile phone, iPod, iPhone, Pocket PC, PSP, or Zune.

    YouTube Robot allows you to search for videos using keywords or browse video by category, author, channel, language, tags, etc. When you find something noteworthy, you can preview the video right in YouTube Robot and then download it onto the hard disk drive. The speed, at which you will be downloading, is very high: up to 5 times faster than other software when you download a single file and up to 4 times faster when you download multiple files at a time.

    Manual download is not the only option with YouTube Robot. You may as well schedule the download and conversion tasks to be executed automatically, even when you are not around. Downloading is followed by conversion to the format of your choice and uploading videos to a mobile device (if needed). For example, you can plug in iPod, select the video, go to bed, and when you wake up next morning, your iPod will be ready to play new YouTube videos.

    Product page: ww w.youtuberobot.com
    Direct download link: ww w.youtuberobot.com/download/utuberobot.exe
    Company web-site: w ww.youtuberobot.com

  14. Your script (posted on comment #comment-24692) works perfectly.

    I would just add the -c parameter to wget, for unstable connections mostly.

    Thanks ;)

  15. Youtube videos are now loaded in /tmp
    Just wait for Flash to load it fully, and rename it =]

  16. after runing “grep “fullscreen” test -m1 | cut -d’?’ -f2 | cut -d’”‘ -f1″
    I encounter the following in my Test file :
    –2010-01-31 18:55:21– http://www.youtube.com/watch?v=kPQR-OsH0RQ
    Resolving http://www.youtube.com... 216.239.59.101, 216.239.59.113, 216.239.59.102, …
    Connecting to http://www.youtube.com|216.239.59.101|:80… connected.
    HTTP request sent, awaiting response… 403 Forbidden
    2010-01-31 18:55:22 ERROR 403: Forbidden.

    what is the problem?

    ps:I use Tor software for bypassing filters in Iran.

Leave a Reply

Security Code: