#!/bin/bash # 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, starting chromium" chromium-browser $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 | 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" exit 0