Youtube-Video on the fly nach ogg wandeln

Aus Siduction Wiki DE
Wechseln zu: Navigation, Suche

Das Script lädt das gewünschte Video von youtube, kodiert es als ogg/theora oder mp3 und löscht danach die .flv Datei. D.h., man ruft es einfach mit der youtube-URL als Parameter auf und bekommt ein fertiges .ogv bzw mp3.

Es braucht youtube-dl und ffmpeg2theora (bzw. ffmpeg für youtube2mp3):

apt-get install youtube-dl ffmpeg2theora ffmpeg

Hier die Scripte

youtube2theora

#!/bin/bash
#make working dir
TMP="$(mktemp -d -p /tmp/ youtube2theora.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".ogv"
        ffmpeg2theora -v 10 -a 10 -optimize -C 0.9 -S 0 -o $OUTPUT $VIDEO
done
#move video to Desktop
mv *.ogv ~/Desktop
#clean-up
rm -rf $TMP

youtube2mp3

#!/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="${VIDEO%-*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."

thx to zulu