First ever question:
Im quite new to this scripting business but I've been trying to automate downloading and renaming youtube videos using youtube-dl. I'm really just doing this as a technical exercise to learn a bit more about bash scripting.
The command I'm using is:
youtube-dl -il "<Youtube URL>" --extract-audio --audio-format "mp3" --audio-quality "192k"
(which will download individual videos or take a playlist and download all files) and this creates a file with the following format (example):
Zedd - Spectrum (feat. Matthew Koma) (Culture_Code_Remix)-LCNwQVRN34.mp3
Where the last reference part of the youtube URL is on the end.
I have written a script to mass-rename all the files which works and is as follows:
#!/bin/bash
for i in *.mp3 ; do
j=`echo $i | awk -F"-" '{print $1 "-" $2}'`
mv "$i" "$j"
done
basically it just cuts off the last piece, my question is how could I put this in a different format so that I can either pipe it on the end or incorporate it and the first command in to a single script so I can automate the whole process?
Thanks in advance.
You can just pass another file name template to youtube-dl with the -o
option:
youtube-dl -i "<Youtube URL>" -o "%(title)s.%(ext)s" \
--extract-audio --audio-format "mp3" --audio-quality "192k"