BashScripts.org
http://bashscripts.org/forum/

youtube.com video ripper
http://bashscripts.org/forum/viewtopic.php?f=7&t=210
Page 1 of 2

Author:  crouse [ Tue Jul 11, 2006 1:43 pm ]
Post subject:  youtube.com video ripper

youtube.com video ripper

Code:
#!/bin/bash
# by Crouse
# Program name ytr = YouTube.com Ripper

baseurl="http://youtube.com/get_video.php?"

mkdir -p ~/YouTube ;
read -p "What is the youtube.com url you want to rip ? " urltorip ;
read -p "What would you like to name the video (no spaces in the name) ? " nameofvideo ;
cd ~/YouTube ;
wget ${urltorip} -O urlsource.txt ;
grep "player2.swf" urlsource.txt > url.info ;
rm urlsource.txt

cut -d? -f2 url.info > url;
rm url.info

cut -d\" -f1 url > videoid;
rm url

videourl=`cat videoid`
rm videoid

fullurl=${baseurl}${videourl}
echo ${fullurl}
wget ${fullurl}

echo "Now converting the file to mpeg ... this can take awhile, please be patient" ;
ffmpeg -i *.flv -ab 56 -ar 22050 -b 500 -s 320x240 ${nameofvideo}.mpg
rm *.flv
rm -f gmon.out
exit

Author:  crouse [ Tue Jul 11, 2006 3:37 pm ]
Post subject: 

Newer / better version.........

Code:
#!/bin/bash
# by Crouse
# Program name ytr = YouTube.com Ripper
baseurl="http://youtube.com/get_video.php?"
mkdir -p ~/YouTube ;
mkdir -p ~/YouTube/tmp ;
cd ~/YouTube/tmp ;
read -p "What is the youtube.com url you want to rip ? " urltorip ;
read -p "What would you like to name the video (no spaces in the name) ? " nameofvideo ;
wget ${urltorip} -O urlsource.txt ;
grep "player2.swf" urlsource.txt > url.info ;
cut -d? -f2 url.info > url;
cut -d\" -f1 url > videoid;
videourl=`cat videoid`
fullurl=${baseurl}${videourl}
echo ${fullurl}
rm *
wget ${fullurl}
mv * *.flv
echo "Now converting the file to mpeg ... this can take awhile, please be patient" ;
ffmpeg -i *.flv -ab 56 -ar 22050 -b 500 -s 320x240 ${nameofvideo}.mpg
mv *.mpg ../
rm -Rf ~/YouTube/tmp
exit

Author:  crouse [ Tue Jul 11, 2006 4:09 pm ]
Post subject: 

Code:
#!/bin/bash
# by Crouse
# Program name ytr = YouTube.com Ripper
baseurl="http://youtube.com/get_video.php?"
mkdir -p ~/YouTube ;
mkdir -p ~/YouTube/tmp ;
cd ~/YouTube/tmp ;
read -p "What is the youtube.com url you want to rip ? " urltorip ;
read -p "What would you like to name the video (no spaces in the name) ? " nameofvideo ;
wget ${urltorip} -O urlsource.txt ;
grep "player2.swf" urlsource.txt > url.info ;
cut -d? -f2 url.info > url;
cut -d\" -f1 url > videoid;
videourl=`cat videoid`
fullurl=${baseurl}${videourl}
echo ${fullurl}
rm *
wget "${fullurl}" -O temp.flv
# mv * temp.flv
echo "Now converting the file to mpeg ... this can take awhile, please be patient" ;
ffmpeg -i temp.flv -ab 56 -ar 22050 -b 500 -s 320x240 ${nameofvideo}.mpg
# mv *.mpg ../
mv ${nameofvideo}.mpg ../
rm -Rf ~/YouTube/tmp
exit


Quote:
17:05 < crouse> http://www.youtube.com/watch?v=rdzQ35kh3Gw
17:05 < crouse> weird
17:06 < crouse> lol
17:06 <@jbsnake> hmm
17:06 < crouse> just grabbed one at random
17:09 <@jbsnake> i get a 404 on that one
17:09 < crouse> hmmmm
17:13 <@jbsnake> you need quotes man
17:13 < crouse> maybe it's just the url then...
17:13 <@jbsnake> nah
17:13 < crouse> well.... heading home....
17:13 <@jbsnake> you need quotes
17:13 < crouse> ahhhhhhh
17:13 < crouse> where ?
17:13 <@jbsnake> wget "http://youtube.com/get_video.php?video_id=VZ7EDg30670&l=39&t=OEgsToPDskLxiezO0ZpVFOP_IsF1ZKFR"
17:13 <@jbsnake> that works
17:13 <@jbsnake> without the quotes doesn't
17:13 < crouse> ahhhh
17:13 <@jbsnake> so... on the last wget line
17:14 < crouse> wget "${fullurl}"
17:14 <@jbsnake> or really... any wget line... just to be safe
17:14 <@jbsnake> ya
17:14 < crouse> k
17:14 <@jbsnake> try that
17:14 <@jbsnake> and... couldn't you do
17:14 <@jbsnake> wget "${fullurl}" -O flash.flv
17:15 <@jbsnake> or some such so you can save the name some way so you don't have to use the *
17:15 < crouse> ahhhhhhhhhh even BETTER ;)
17:15 < crouse> yeah



Author:  crouse [ Tue Jul 11, 2006 8:53 pm ]
Post subject: 

Code:
[email protected]:~/Scripts> sh ytr.sh
What is the youtube.com url you want to rip ? http://youtube.com/watch?v=7agPOt1XZz8
What would you like to name the video (no spaces in the name) ? test1
--21:47:51--  http://youtube.com/watch?v=7agPOt1XZz8
           => `urlsource.txt'
Resolving youtube.com... 208.65.153.245, 208.65.153.240, 208.65.153.242, ...
Connecting to youtube.com|208.65.153.245|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]

    [   <=>                                                             ] 58,796       103.34K/s

21:47:52 (103.08 KB/s) - `urlsource.txt' saved [58796]

http://youtube.com/get_video.php?video_id=7agPOt1XZz8&l=236&t=OEgsToPDskKXxh5iBY7DxxYPXWcki4Ks
--21:47:53--  http://youtube.com/get_video.php?video_id=7agPOt1XZz8&l=236&t=OEgsToPDskKXxh5iBY7DxxYPXWcki4Ks
           => `temp.flv'
Resolving youtube.com... 208.65.153.245, 208.65.153.240, 208.65.153.242, ...
Connecting to youtube.com|208.65.153.245|:80... connected.
HTTP request sent, awaiting response... 303 See Other
Location: http://sjl-v93.sjl.youtube.com/get_video?video_id=7agPOt1XZz8 [following]
--21:47:53--  http://sjl-v93.sjl.youtube.com/get_video?video_id=7agPOt1XZz8
           => `temp.flv'
Resolving sjl-v93.sjl.youtube.com... 64.15.120.100
Connecting to sjl-v93.sjl.youtube.com|64.15.120.100|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9,132,067 (8.7M) [video/flv]

33% [=====================>                                   

Author:  jbsnake [ Wed Jul 12, 2006 7:27 am ]
Post subject: 

i have a small suggestion for this script... maybe a way to kill some of the headache its causing... remove the following lines..
Code:
grep "player2.swf" urlsource.txt > url.info ;
cut -d? -f2 url.info > url;
cut -d\" -f1 url > videoid;
videourl=`cat videoid`
fullurl=${baseurl}${videourl}

replace with this line (you may want to copy and paste)...
Code:
fullurl=${baseurl}`grep player2.swf urlsource.txt | cut -d? -f2 | cut -d\" -f1`

Author:  crouse [ Wed Jul 12, 2006 10:22 am ]
Post subject: 

actually the issue was mostly with this line.....

Code:
mv ${nameofvideo}.mpg ../
but that's sorted, so it seems to work just fine now....

FWIW, I like the cleanness of your code, but I like mine for ease of understanding.... if the url stuff changes at a later date, I feel mine would be easier (for me at least) to understand..... but since I have this archived here forever.... I will use your code as it makes the program even smaller and cleaner looking ;)

Author:  crouse [ Wed Jul 12, 2006 10:36 am ]
Post subject: 

Code:
#!bin/bash
# by Crouse - Program name ytr = YouTube.com Ripper
clear; baseurl="http://youtube.com/get_video.php?";
mkdir -p ~/YouTube ; mkdir -p ~/YouTube/tmp ; cd ~/YouTube/tmp ; echo " ";
read -p "What is the youtube.com url you want to rip ? " urltorip ;
read -p "What would you like to name the video (no spaces in the name) ? " nameofvideo ;
wget ${urltorip} -O urlsource.txt ; fullurl=${baseurl}`grep player2.swf urlsource.txt | cut -d? -f2 | cut -d\" -f1` ;
rm * ; wget "${fullurl}" -O temp.flv ; ffmpeg -i temp.flv -ab 56 -ar 22050 -b 500 -s 320x240 ${nameofvideo}.mpg ;
mv ${nameofvideo}.mpg ../ ; rm -Rf ~/YouTube/tmp ; exit


should be 9 lines ;)

Author:  crouse [ Wed Jul 12, 2006 10:45 am ]
Post subject: 

Code:
#!/bin/bash
clear;baseurl="http://youtube.com/get_video.php?";mkdir -p ~/YouTube;mkdir -p ~/YouTube/tmp;cd ~/YouTube/tmp;echo " ";
read -p "Enter youtube.com url: " urltorip;read -p "Name the video (no spaces in the name) ? " nameofvideo;
wget ${urltorip} -O urlsource.txt;fullurl=${baseurl}`grep player2.swf urlsource.txt | cut -d? -f2 | cut -d\" -f1`;
wget "${fullurl}" -O temp.flv;ffmpeg -i temp.flv -ab 56 -ar 22050 -b 500 -s 320x240 ${nameofvideo}.mpg;mv ${nameofvideo}.mpg ../;
rm -Rf ~/YouTube/tmp;exit


Down to 6 lines

Author:  crouse [ Wed Jul 12, 2006 1:32 pm ]
Post subject: 

Code:
#!/bin/bash
bu="http://youtube.com/get_video.php?";mkdir -p ~/YouTube;cd ~/YouTube;read -p "YouTube url? " ur;read -p "Name? " nv
wget ${ur} -O /tmp/y1;uf=${bu}`grep player2.swf /tmp/y1 | cut -d? -f2 | cut -d\" -f1`;wget "${uf}" -O /tmp/y.flv
ffmpeg -i /tmp/y.flv -ab 56 -ar 22050 -b 500 -s 320x240 ${nv}.mpg;rm /tmp/y.flv; rm /tmp/y1;rm gmon.out; exit


4 Lines !!!! :)

Author:  magesor [ Fri Jul 21, 2006 9:25 am ]
Post subject: 

crouse wrote:
Code:
#!/bin/bash
bu="http://youtube.com/get_video.php?";mkdir -p ~/YouTube;cd ~/YouTube;read -p "YouTube url? " ur;read -p "Name? " nv
wget ${ur} -O /tmp/y1;uf=${bu}`grep player2.swf /tmp/y1 | cut -d? -f2 | cut -d" -f1`;wget "${uf}" -O /tmp/y.flv
ffmpeg -i /tmp/y.flv -ab 56 -ar 22050 -b 500 -s 320x240 ${nv}.mpg;rm /tmp/y.flv; rm /tmp/y1;rm gmon.out; exit


4 Lines !!!! :)
3 lines =))
Code:
#!/bin/bash

BASEURL="http://youtube.com/get_video.php?" ; read -p "YouTube URL? " ORIGURL ; read -p "Desired path/filename? " OUTFILE

wget -c -S -O ${OUTFILE}.flv ${BASEURL}`curl -s ${ORIGURL} | grep player2.swf | cut -f2 -d? | cut -f1 -d"` && ffmpeg -i ${OUTFILE}.flv -ab 56 -ar 22050 -b 500 -s 320x240 ${OUTFILE}.mpg && exit 0
:D

Author:  wily [ Sun Jul 30, 2006 6:50 pm ]
Post subject:  Who uses read?

:? Who still uses read? What if I want to call this from a script, say, in Firefox (which I do)?

Let's try this:

Code:
#!/bin/bash
wget -c -S -O $2.flv http://youtube.com/get_video.php\?`curl -s $1 | grep player2.swf | cut -f2 -d? | cut -f1 -d\"` && ffmpeg -i $2.flv -ab 56 -ar 22050 -b 500 -s 320x240 $2.mpg && exit 0


2 lines. :)

Called thus: ./youtube.sh {YouTube URL} {filename}

Or, even better, Triffid_Hunter wrote this one:

Code:
#!/usr/bin/perl -w
use LWP::Simple;LWP::Simple::get(shift) =~ /<title>YouTube - (.*?)<\/title>.*player2.swf\?(video_id=([0-9a-z]+).+?)\"/is && exec "wget -c -S -O $3.flv \"http://youtube.com/get_video.php?$2\" && ffmpeg -i $3.flv -ab 56 -ar 22050 -b 500 -s 320x240 \"".(@ARGV?shift:"$1.mpg")."\" && echo && echo YouTube:$3 saved as \\\"$1.mpg\\\""


2 lines. :)

Even though it's (ugly) Perl and thus technically not a "bash script," it is really nifty as it shows a good combination of dirt and trickery in order to save the file as the TITLE of the video.

Called thus: ./youtube.pl {YouTube URL}

Enjoy.

Author:  crouse [ Mon Jul 31, 2006 12:01 am ]
Post subject: 

Very interesting..... (well.....not the perl to me anyway), but the first script was. As for using read, I use it all the time actually, as it allows me to write bash scripts for the bash-challanged ;) IE: my son ....so he can save the video's he wanted ;)

Author:  magesor [ Thu Aug 03, 2006 7:40 am ]
Post subject:  Re: Who uses read?

wily wrote:
:? Who still uses read? What if I want to call this from a script, say, in Firefox (which I do)?

Let's try this:

Code:
#!/bin/bash
wget -c -S -O $2.flv http://youtube.com/get_video.php\?`curl -s $1 | grep player2.swf | cut -f2 -d? | cut -f1 -d"` && ffmpeg -i $2.flv -ab 56 -ar 22050 -b 500 -s 320x240 $2.mpg && exit 0


2 lines. :)

Called thus: ./youtube.sh {YouTube URL} {filename}
<...>
Enjoy.
Without read, you have to cycle through more of checking `if/else' or `case' routines to bring $* parameters to the appropriate number of two.
Plus "youtube.sh {YouTube URL} {filename}" help line would be desired here as well.
So in the end it's going to get more that 2 lines =)

p.s. Sorry for my ugly English, I'm not a native... :(

Author:  wily [ Wed Aug 09, 2006 7:02 am ]
Post subject: 

crouse wrote:
Very interesting..... (well.....not the perl to me anyway),

Perl rocks. Convert. That script works so damn beautifully, and I assure you there is very little in Perl that cannot be achieved in one line. :) With the addition of CPAN and one of the greatest communities I've ever seen, Perl is definitely worth a deeper look.
crouse wrote:
but the first script was. As for using read, I use it all the time actually, as it allows me to write bash scripts for the bash-challanged ;) IE: my son ....so he can save the video's he wanted ;)

That's cool, let's call this a power user script. 8)

And as for the next post, why do you need instructions? Real geeks look at the code. And, technically it's one line without the #!/bin/bash, which should be default anyhow. ;)

Author:  crouse [ Wed Aug 09, 2006 8:11 am ]
Post subject: 

Well..... ANY script in bash can be ONE line too ;) Just add lots of ";" to the mix, and it can be as long as you want ......

I can write some perl, some python, still deciding on if i want to do anything more, as you can tell, i prefer bash.... it's just more "readable" than perl or python to me.

Author:  wily [ Fri Aug 11, 2006 3:19 pm ]
Post subject: 

crouse wrote:
i prefer bash.... it's just more "readable" than perl or python to me.


Just as crime writers with simple plots are more "readable" than Twain or Dostoyevsky?

Hehe seriously man, horses for courses, bash scripts are great and fun for things like this, although hardly a match for Perl in the real world. :)

</zeolotry>

Author:  crouse [ Sat Aug 12, 2006 2:26 pm ]
Post subject: 

I wouldn't say that..... ;)

I mean.. you HAVE checked out how many shell scripts are in a standard linux distrobution haven't you ;)

fwiw, i AM learning perl now.... i just still prefer bash.

Author:  wily [ Thu Aug 17, 2006 4:39 pm ]
Post subject: 

crouse wrote:
I wouldn't say that..... ;)

I mean.. you HAVE checked out how many shell scripts are in a standard linux distrobution haven't you ;)


Well if anyone running Gentoo can be bothered:

Code:
grep -R \#\!/bin/bash / | wc -l


If only I had the patience to unmount all my network mounts! :)


crouse wrote:
fwiw, i AM learning perl now.... i just still prefer bash.


Cool, don't forget http://perlmonks.org/ and of course, http://perl.org/ -- especially http://cpan.perl.org/.

perldoc is your friend! Have fun!

--
wily

Author:  jessejoedotcom [ Fri Aug 18, 2006 6:57 am ]
Post subject: 

Hey crouse great script! However it doesn't work with all links. For instance if I use this youtube link http://www.youtube.com/watch?v=8ff3F0cysQU I get this error:

Quote:
Input #0, flv, from '/tmp/y.flv':
Duration: N/A, bitrate: N/A
Stream #0.0: Audio: mp3, 22050 Hz, mono
Stream #0.1: Video: flv, yuv420p, 320x240, 1000.00 fps
Output #0, mpeg, to 'top_10_unsportmanlike_plays.mpg':
Stream #0.0: Video: mpeg1video, yuv420p, 320x240, 15.00 fps, q=2-31, 500 kb/s
Stream #0.1: Audio: mp2, 22050 Hz, mono, 56 kb/s
Stream mapping:
Stream #0.1 -> #0.0
Stream #0.0 -> #0.1
[mpeg1video @ 0x8336308]MPEG1/2 does not support 15/1 fps
Error while opening codec for output stream #0.0 - maybe incorrect parameters such as bit_rate, rate, width or height

rm: cannot remove `gmon.out': No such file or directory


I was planning on making a nice little front end with zenity, but I thought I would get the bugs out first. Any idea how to detect what type of video before encoding?

Also I did not need the "rm gmon.out".

Author:  mmrtnt [ Mon Sep 04, 2006 12:32 pm ]
Post subject: 

jessejoedotcom wrote:
Hey crouse great script! However it doesn't work
...
[mpeg1video @ 0x8336308]MPEG1/2 does not support 15/1 fps
Error while opening codec for output stream #0.0 - maybe incorrect parameters such as bit_rate, rate, width or height

rm: cannot remove `gmon.out': No such file or directory


I was planning on making a nice little front end with zenity, but I thought I would get the bugs out first. Any idea how to detect what type of video before encoding?

I used this workaround to get to dvd writable mpg:
ffmpeg -i how_not_to_ride.flv -aspect 4:3 -ab 56 -ar 22050 -b 500 -s 320x240 -y how_not_to_ride.avi
ffmpeg -i how_not_to_ride.avi -y -target ntsc-dvd -sameq -aspect 4:3 how_not_to_ride.mpg

Cheers,

MjM

Author:  mixacha [ Thu Nov 16, 2006 5:28 am ]
Post subject: 

mmrtnt wrote:
jessejoedotcom wrote:
Hey crouse great script! However it doesn't work
...
[mpeg1video @ 0x8336308]MPEG1/2 does not support 15/1 fps
Error while opening codec for output stream #0.0 - maybe incorrect parameters such as bit_rate, rate, width or height

rm: cannot remove `gmon.out': No such file or directory


I was planning on making a nice little front end with zenity, but I thought I would get the bugs out first. Any idea how to detect what type of video before encoding?

I used this workaround to get to dvd writable mpg:
ffmpeg -i how_not_to_ride.flv -aspect 4:3 -ab 56 -ar 22050 -b 500 -s 320x240 -y how_not_to_ride.avi
ffmpeg -i how_not_to_ride.avi -y -target ntsc-dvd -sameq -aspect 4:3 how_not_to_ride.mpg

Cheers,

MjM


good workaround, I use it as a function:

Code:
function dvd {
ffmpeg -i how_not_to_ride.flv -aspect 4:3  -ab 56 -ar 22050 -b 500  -s 320x240 -y how_not_to_ride.avi
ffmpeg -i how_not_to_ride.avi -y -target ntsc-dvd -sameq -aspect 4:3 how_not_to_ride.mpg
}

Author:  sandinista [ Tue Aug 21, 2007 3:44 pm ]
Post subject:  the youtube bash script wont work on the following url

i have tried to use the bash script on the following url without success.

http://www.youtube.com/watch?v=0Sn7GmHHR14

this is the output

[email protected]:~$ ./youtube.sh http://www.youtube.com/watch?v=0Sn7GmHHR14 lisa
./youtube.sh: line 2: curl: command not found
--16:19:05-- http://youtube.com/get_video.php?
=> `lisa.flv'
Resolving youtube.com... 208.65.153.238, 208.65.153.251, 208.65.153.253
Connecting to youtube.com|208.65.153.238|:80... connected.
HTTP request sent, awaiting response...
HTTP/1.1 404 Not Found
Date: Tue, 21 Aug 2007 21:19:04 GMT
Server: Apache
Cache-Control: no-cache
Connection: close
Content-Type: text/html; charset=utf-8
16:19:05 ERROR 404: Not Found.

thank you.

Author:  crouse [ Thu Aug 23, 2007 8:40 am ]
Post subject: 

Quote:
./youtube.sh: line 2: curl: command not found


Install curl

HTH's ;)

Author:  yeehawjared [ Thu Aug 23, 2007 10:07 pm ]
Post subject: 

is the script broken? I believe I'm doing everything correct, and have curl installed.

script:
Code:
#!/bin/bash
wget -c -S -O $2.flv http://youtube.com/get_video.php\?`curl -s $1 | grep player2.swf | cut -f2 -d? | cut -f1 -d\"` && ffmpeg -i $2.flv -ab 56 -ar 22050 -b 500 -s 320x240 $2.mpg && exit 0


output:
Code:
[email protected]:/tmp# ./youtube.sh http://www.youtube.com/watch?v=0Sn7GmHHR14 lisa
--00:15:56--  http://youtube.com/get_video.php?v=1';
           => `lisa.flv'
Resolving youtube.com... 208.65.153.238, 208.65.153.251, 208.65.153.253
Connecting to youtube.com|208.65.153.238|:80... connected.
HTTP request sent, awaiting response...
  HTTP/1.1 404 Not Found
  Date: Fri, 24 Aug 2007 04:15:54 GMT
  Server: Apache
  Cache-Control: no-cache
  Connection: close
  Content-Type: text/html; charset=utf-8
00:15:56 ERROR 404: Not Found.

[email protected]:/tmp#




Author:  sandinista [ Sat Aug 25, 2007 1:24 pm ]
Post subject: 

it worked for me with curl and ffmpeg installed. the video output of a resized video looked horrible though from the example i gave. i believe that might have to do with the quality of the source. i am not 100% sure though that is my guess.

Page 1 of 2 All times are UTC - 6 hours
© 2000, 2002, 2005, 2007 phpBB Group • http://www.phpbb.com