Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env bash
#set -x
trap ctrl_c INT
ctrl_c () {
rm -r "$_tmpdir"
exit 2
}
_nasdir=/mnt/nshare/Infiniti_music
_urlfile="${_nasdir}/urls.txt"
_failfile="${_nasdir}/fails.txt"
_fileformat='%(title)s.%(ext)s'
_tmpdir=$(mktemp -d)
echo "$_tmpdir"
dos2unix "$_urlfile"
mapfile -t urls < "$_urlfile"
for url in "${urls[@]}"; do
fails=0
/usr/local/bin/youtube-dl -o "${_tmpdir}/${_fileformat}" --restrict-filenames -f bestaudio "$url" >/dev/null
files=($(/usr/local/bin/youtube-dl -o "${_tmpdir}/${_fileformat}" --restrict-filenames -f bestaudio --get-filename "$url"))
for file in "${files[@]}"; do
_mp3="${_nasdir}/tmp/$(basename "${file%.*}").mp3"
ffmpeg -i "$file" -vn -ab 128k -ar 44100 -y "$_mp3"
if [[ ! -f "$_mp3" ]]; then
((fails++))
fi
done
if ((fails>0)); then
echo "$url" >> "$_failfile"
fi
done
rm -r "$_tmpdir"
echo '' > "$_urlfile"
unix2dos "$_urlfile"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment