| Author |
Message |
|
|
Post subject: script: download from youtube and encode to ogg or mp3
Posted: Sep 29, 2007 - 12:35 AM
|
|

Joined: Nov 30, 2006
Posts: 775
Location: Germany
Status: Offline
|
|
|
|
|
 |
|
|
Post subject: RE: my first script: download from youtube and encode to ogg
Posted: Sep 29, 2007 - 02:00 AM
|
|

Joined: Dec 01, 2006
Posts: 751
Status: Offline
|
|
| wow, thats pretty neat, i'll try it when i actually need to archive something like this |
_________________ "Cool was never cool until the cool guys at Cool industries developed a cool new product: Cool."
|
| |
|
|
|
 |
|
|
Post subject: RE: my first script: download from youtube and encode to ogg
Posted: Sep 29, 2007 - 02:14 AM
|
|

Joined: Nov 30, 2006
Posts: 775
Location: Germany
Status: Offline
|
|
| I am still experimenting with some options of ffmpeg2theora to improve quality and avoid unsynched video/audio. Also currently it is not possible to run multiple instance of the script in the same parent dir because the two instances would use the same workdir which will bork both jobs. |
_________________ http://sidux.wordpress.com/ inoffizielles sidux-Blog
|
| |
|
|
|
 |
|
|
Post subject: RE: my first script: download from youtube and encode to ogg
Posted: Sep 29, 2007 - 03:54 AM
|
|

Joined: Dec 02, 2006
Posts: 1045
Location: East Coast
Status: Offline
|
|
|
|
|
 |
|
|
Post subject: RE: my first script: download from youtube and encode to ogg
Posted: Sep 29, 2007 - 06:41 AM
|
|
Joined: Nov 26, 2006
Posts: 357
Status: Offline
|
|
|
|
|
 |
|
|
Post subject: RE: my first script: download from youtube and encode to ogg
Posted: Aug 21, 2008 - 07:35 PM
|
|

Joined: Nov 30, 2006
Posts: 775
Location: Germany
Status: Offline
|
|
new script: gets only audio and encodes it to mp3:
youtube2mp3
Code:
#!/bin/bash
#make working dir
TMP="$(mktemp -d -p /tmp/ youtube2mp3.XXXXXX || exit 1)"
cd $TMP
#download video(s)
for URL in $*; do
youtube-dl -t $URL
done
#convert
for VIDEO in *.flv; do
OUTPUT=$VIDEO".mp3"
ffmpeg -i $VIDEO -ab 128k -ar 44100 $OUTPUT
done
#move video to Desktop
mv *.mp3 ~/Desktop
#clean-up
rm -rf $TMP
|
_________________ http://sidux.wordpress.com/ inoffizielles sidux-Blog
Last edited by zulu9 on Oct 20, 2008 - 11:14 PM; edited 1 time in total
|
| |
|
|
|
 |
|
|
Post subject: RE: my first script: download from youtube and encode to ogg
Posted: Aug 23, 2008 - 02:16 AM
|
|

Joined: Dec 02, 2006
Posts: 1045
Location: East Coast
Status: Offline
|
|
|
|
|
 |
|
|
Post subject: Re: RE: my first script: download from youtube and encode to
Posted: Aug 26, 2008 - 11:17 PM
|
|

Joined: Nov 30, 2006
Posts: 775
Location: Germany
Status: Offline
|
|
|
|
|
 |
|
|
Post subject: RE: Re: RE: my first script: download from youtube and encod
Posted: Oct 20, 2008 - 11:03 PM
|
|
Joined: Jul 03, 2008
Posts: 17
Status: Offline
|
|
zulu9 thx a bunch for the 2 scripts
one quick comment. the second script needs a k after 128 to set the bitrate to 128 bit/s
Code:
ffmpeg -i $VIDEO -ab 128k -ar 44100 $OUTPUT
|
_________________ New unofficial greek sidux forum
|
| |
|
|
|
 |
|
|
Post subject: RE: Re: RE: my first script: download from youtube and encod
Posted: Oct 20, 2008 - 11:15 PM
|
|

Joined: Nov 30, 2006
Posts: 775
Location: Germany
Status: Offline
|
|
|
|
|
 |
|
|
Post subject:
Posted: Nov 06, 2008 - 02:26 AM
|
|
Joined: Aug 09, 2007
Posts: 41
Location: Auckland, New Zealand
Status: Offline
|
|
zulu9 I like your scripts and they work well. Well done.
As a matter of personal taste, I would change some of the format of the script, and also use a friendly looking sed. The following is just my opinions/suggestions, so ignore anything you want:
Code:
#!/bin/bash
basename=$(basename $0) # ie this is the name of the script that's being called
TMP="$(mktemp -d -p /tmp/ $basename.XXXXXX || exit 1)"
cd $TMP
#I like to print out what the script is doing:
echo
echo "======= Working directory is $TMP ======="
echo
#download video(s)
# using "$@" (list of arguments) instead of $* (line of arguments) is a good habit to get into,
# as some arguments don't get passed properly using $*, eg if the arguments have spaces
# (although that doesn't apply for this script). "$@" is the 'proper' way of doing it.
for URL in "$@"; do
echo
echo "======= Downloading $URL======="
echo
# note that I always use double quotes so that spaces and special chars are passed correctly
# (again it probably doesn't matter with this script)
youtube-dl -t "$URL"
done
#convert
for VIDEO in *.flv; do
# change the CRAP.flv to .mp3 for the OUTPUT file (and I use double quotes again):
OUTPUT=`echo "$VIDEO" | sed 's/-\w\+\.flv/.mp3/'`
echo
echo "======= Creating $OUTPUT ======="
echo
# (and I use double quotes again):
ffmpeg -i "$VIDEO" -ab 128k -ar 44100 "$OUTPUT"
done
echo
echo "======= Moving to Desktop ======="
echo
mv *.mp3 ~/Desktop
echo
echo "======= Cleaning up ======="
echo
rm -rf $TMP
echo
echo "Done."
echo
|
|
|
| |
|
|
|
 |
|
|
Post subject:
Posted: Nov 06, 2008 - 03:56 AM
|
|

Joined: Jan 07, 2008
Posts: 297
Status: Offline
|
|
If you want to change FILE.flv to FILE.mp3, bash parameter expansion can do some magic:
Code:
VIDEO="example.flv"
OUTPUT="${VIDEO/%flv/mp3}"
|
|
|
| |
|
|
|
 |
|
|
Post subject:
Posted: Nov 06, 2008 - 05:38 AM
|
|
Joined: Aug 09, 2007
Posts: 41
Location: Auckland, New Zealand
Status: Offline
|
|
|
ModestUser wrote:
If you want to change FILE.flv to FILE.mp3, bash parameter expansion can do some magic:
Code:
VIDEO="example.flv"
OUTPUT="${VIDEO/%flv/mp3}"
Nice.
BTW - the sed way changes "thisvideoblah-JFlA3pVTHEkM.flv" to "thisvideoblah.mp3". How would this be done with parameter expansion if we don't know the "CRAP" to remove? |
|
|
| |
|
|
|
 |
|
|
Post subject:
Posted: Nov 06, 2008 - 02:21 PM
|
|

Joined: Jan 07, 2008
Posts: 297
Status: Offline
|
|
|
Code:
OUTPUT="${VIDEO%-*flv}.mp3"
See "man bash". |
|
|
| |
|
|
|
 |
|
|
Post subject:
Posted: Nov 06, 2008 - 05:46 PM
|
|

Joined: Nov 30, 2006
Posts: 775
Location: Germany
Status: Offline
|
|
thanks guys!
I like to see this small thing improving by the community.
I made some .debs for it tho you can really just put it anywhere.
Please check if I missed some contributor in the copyright-file
the new version is yet untestet. I applied the changes from Swynndla and ModestUser. |
_________________ http://sidux.wordpress.com/ inoffizielles sidux-Blog
|
| |
|
|
|
 |
|
|