1
1
Fork 0

renamed youtube2mp3 to youtube_converter.sh and released v0.3 with audio and video convertion

This commit is contained in:
David Starzengruber 2011-01-02 17:19:03 +01:00
parent 0a37b70f9b
commit 20bfc4a131
2 changed files with 131 additions and 96 deletions

View File

@ -1,96 +0,0 @@
#!/bin/bash
# # # # # # # # # # # # # # # # # # # # #
# # To rip a Youtube file just run
# YouTube to MP3 Contvertion Tool # this script and with the youtube
# # link as option. If you don't use
# Author: david@socialnerds.org # the link as option the script will
# Version: v0.1 # ask you for the link during run.
# # the mp3 file will be placed in the
# # working directory.
# # # # # # # # # # # # # # # # # # # # #
# checking dependencies
if [[ $(aptitude search ffmpeg | grep multimedia | awk '{print $1}') = "i" && $(aptitude search lame | grep frontend | awk '{print $1}') = "i" && $(aptitude search curl | grep "Get a file" | awk '{print $1}') = "i" ]]; then
echo "info: everything found"
else
if [ $(whoami) = "root" ]; then
echo "info: trying to insall missing dependencies"
apt-get install -y ffmpeg curl lame
else
echo "error: permission denied"
echo "info: install dependencies or run this scrip as superuser"
exit 1
fi
fi
# skip read if link is already first option
if [ -z $1 ]; then
echo "Insert YouTube Link here:"
read link
else
link=$1
fi
# getting filename
file=$(ls -l /tmp | grep Flash | awk '{print $8}')
secondfile=$(echo $file | awk '{print $2}')
if [ -z "$file" ]; then
echo "info: there is no open youtube window, trying to start browser"
#chromium-browser $link
firefox $link &
sleep 6
file=$(ls -l /tmp | grep Flash | awk '{print $8}')
secondfile=$(echo $file | awk '{print $2}')
fi
# checking if there is a second flash file in /tmp
if [ -z $secondfile ]; then
i="doitagain"
oldsize="0"
while [ $i = "doitagain" ]; do
size=$(ls -l /tmp | grep $file | awk '{print $5}')
if [ $size -gt $oldsize ];then
echo "info: download not finished yet. waiting 5 seconds.."
oldsize=$size
sleep 5
else
echo "info: download finished."
i="goforit"
fi
done
else
echo "error: there should just be one open video window"
exit 1
fi
# parse link for title
curl "$link" --output tmp.txt
rawtitle=$(cat tmp.txt | w3m -dump -T text/html | sed -n '5p')
title=$rawtitle
#rawtitle=$(cat tmp.txt | grep 'meta name="title"')
rm tmp.txt
#count=${#rawtitle}
#length=$(($count-36))
#title=${rawtitle:34:$length}
echo
echo "Parsed videotitle = $title"
echo
# here starts the actual convertion
echo "starting convertion of $title @ $link"
ffmpeg -i /tmp/$file -vn temp.wav
lame --preset 128 temp.wav "$title.mp3"
rm temp.wav
wd=$(pwd)
echo
echo "you will find the just created file in $wd"
echo "filename = $title.mp3"
echo
exit 0

131
youtube_converter.sh Executable file
View File

@ -0,0 +1,131 @@
#!/bin/bash
# # # # # # # # # # # # # # # # # # # # #
# #
# YouTube Contvertion Tool #
# #
# Author: david@socialnerds.org #
# Version: v0.3 #
# #
# #
# # # # # # # # # # # # # # # # # # # # #
# help text
if [[ $1 == "-h" || $1 == "--help" ]]; then
echo "
# # # # # # # # # # # # # # # # # # # # #
# #
# YouTube Contvertion Tool #
# #
# Author: david@socialnerds.org #
# Version: v0.3 #
# #
# #
# # # # # # # # # # # # # # # # # # # # #"
echo
echo "usage: ./youtube_converter <mp3/mpeg> <youtube-link>"
echo
exit 0
fi
# checking dependencies (except browser, i use chromium here)
if [[ $(aptitude search ffmpeg | grep multimedia | awk '{print $1}') = "i" && $(aptitude search lame | grep frontend | awk '{print $1}') = "i" && $(aptitude search curl | grep "Get a file" | awk '{print $1}') = "i" ]]; then
#echo "info: all dependencies found"
:
else
if [ $(whoami) = "root" ]; then
echo "info: trying to insall missing dependencies"
apt-get install -y ffmpeg curl lame
else
echo "error: permission denied"
echo "info: install dependencies or run this scrip as superuser"
exit 1
fi
fi
# check if entered link or given link option a youtube link
while [[ ${link:0:31} != "http://www.youtube.com/watch?v=" && ${2:0:31} != "http://www.youtube.com/watch?v=" ]]; do
echo "enter youtube link:"
read link
done
if [ -z $link ]; then
link=$2
fi
# do you want a mp3 or a mpeg
if [[ $1 = "mp3" || $1 = "mpeg" ]]; then
mediatype=$1
else
while [[ $mediatype != "mp3" && $mediatype != "mpeg" ]]; do
echo 'Do you want an audio or video file? mp3/mpeg[default is mp3].'
read mediatype
if [ -z $mediatype ]; then
mediatype="mp3"
fi
done
fi
# getting flash filename
file=$(ls -l /tmp | grep Flash | awk '{print $8}')
secondfile=$(echo $file | awk '{print $2}')
if [ -z "$file" ]; then
echo "info: there is no open youtube window, trying to start browser"
chromium-browser $link
#firefox $link &
sleep 6
file=$(ls -l /tmp | grep Flash | awk '{print $8}')
secondfile=$(echo $file | awk '{print $2}')
fi
# checking if there is a second flash file in /tmp
if [ -z $secondfile ]; then
i="doitagain"
oldsize=$(ls -l /tmp | grep $file | awk '{print $5}')
sleep 5
while [ $i = "doitagain" ]; do
size=$(ls -l /tmp | grep $file | awk '{print $5}')
if [ $size -gt $oldsize ];then
echo "info: download not finished yet. waiting 5 seconds.."
oldsize=$size
sleep 5
else
echo "info: download finished."
i="goforit"
fi
done
else
echo "error: there should just be one open video window"
exit 1
fi
# parse link for title
curl "$link" --output tmp.txt
rawtitle=$(cat tmp.txt | w3m -dump -T text/html | sed -n '5p')
title=$rawtitle
#rawtitle=$(cat tmp.txt | grep 'meta name="title"')
rm tmp.txt
#count=${#rawtitle}
#length=$(($count-36))
#title=${rawtitle:34:$length}
# here starts the actual convertion
echo "starting convertion of $title @ $link"
if [ $mediatype != "mpeg" ]; then
ffmpeg -i /tmp/$file -vn temp.wav
lame --preset 128 temp.wav "$title.mp3"
rm temp.wav
title="$title.mp3"
else
ffmpeg -i /tmp/$file -sameq -ab 192k "$title.mpeg"
title="$title.mpeg"
fi
wd=$(pwd)
echo
echo "Output file $wd/$title"
echo
exit 0