Christmas Fun · Dec 13, 02:41 AM
I ordered a CD of Christmas music online, and wasn’t sure if it was going to turn up in time for the party season. I thought of all the music on YouTube and wondered how easy it would be to make a ‘recipe’ for a music CD based on a list of YouTube URLs. Here’s the answer…
It’s really easy, at least if you’ve got a Linux OS. Most of the work has already been done – mastering CDs (cdrecord), extracting audio (mplayer), and downloading video (youtube-dl). All you need is a list of tracks you like (you might want to search for ‘HQ audio’ ones).
The script to do all this isn’t perfect – it would be better if it checked how much space is available on the CD, or that the tracks were of high quality (or even stereo). Using the script might even have copyright issues. So I’m publishing it here for educational purposes only. Happy Christmas!
#! /bin/bash
#
#
# Merry Christmas Bash script
#
#
# by even thinking about this script the reader acknowledges that copyright
# subsists in published material and therefore this script is provided for
# educational purposes ONLY
echo -n "I would like to make a Music CD from music published online [yes]"
read answer
echo $answer
# config
ydurl=http://www.arrakis.es/~rggi3/youtube-dl/youtube-dl
deps="/usr/bin/wget /usr/bin/python /usr/bin/mplayer /usr/bin/cdrecord"
urls="http://uk.youtube.com/watch?v=qOq4S10bvHs \
http://uk.youtube.com/watch?v=tNdMi-Vw2N0 \
http://uk.youtube.com/watch?v=RMWXyEHoN88 \
http://uk.youtube.com/watch?v=shHbao_BO9Y \
http://uk.youtube.com/watch?v=vcYIHU2JjzY \
http://uk.youtube.com/watch?v=UGS8re8cIVI \
http://uk.youtube.com/watch?v=NrAwK9juhhY \
http://uk.youtube.com/watch?v=3354flS1KJs \
http://uk.youtube.com/watch?v=-8rY0Fyws20"
# check dependencies
for dep in $deps ; do
if [ ! -x $dep ] ; then
base=$(basename $dep)
echo "Sorry, I need $base - Please install it."
exit -1
fi
done
# make a temporary directory
mkdir /tmp/mycd
cd /tmp/mycd
/usr/bin/wget -nd $ydurl || (echo "Unable to wget youtube-dl" && exit -1)
chmod +x ./youtube-dl
# get the audio
for url in $urls ; do
# download
./youtube-dl -o vidfile -b $url
if [ ! -f ./vidfile ] ; then
echo "Trouble getting $url :("
else
# convert audio to wav
mplayer -vo null -ao pcm:fast:file=trk.wav vidfile
mv trk.wav $(printf trk%.2d.wav $(ls *.wav |wc -l))
rm -f vidfile
fi
done
# guess device:
devices=$(cdrecord -scanbus |grep ',')
guessdev=$(echo $devices |head -1|awk '{ print $1 }')
echo "$devices"
echo -n "Choose a CD writing device please [$guessdev]"
read answer
chosen=${answer:-$guessdev}
echo "Ensure blank disc is inserted! [hit return]"
read answer
# master/write CD
cdrecord dev=$chosen -eject speed=16 -pad -audio *.wav
# cleanup
cd ..; rm -rf mycd
<<<Controlling O2's Wireless Box · The twilight zone of firmware hacking>>>

