From 0f08d04698c814955116b6bae50752e64b774d8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Gon=C3=A7alves?= Date: Thu, 23 Dec 2021 18:28:03 +0000 Subject: Thu Dec 23 06:28:03 PM UTC 2021 --- .bin/music | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100755 .bin/music (limited to '.bin/music') diff --git a/.bin/music b/.bin/music new file mode 100755 index 0000000..5498dc0 --- /dev/null +++ b/.bin/music @@ -0,0 +1,70 @@ +#!/bin/sh + + +MUSIC_DIR="${HOME}/music" +MUSIC_LIST= +MUSIC_FILE= +MUSIC_YT_OPTIONS= + +log() { + echo "[${0} ] ${@}" +} + +main() { + # arguments + while getopts "c:" arg; do + case "${arg}" in + c) + MUSIC_FILE="${OPTARG}" + ;; + h) + exit 0 + ;; + esac + done + + # ensure parameters are correct + [ ! -f "${MUSIC_FILE}" ] && exit 1 + + + while read -r line; do + + # skip comments + line=$(echo ${line} | grep -v -e "^$" -e "^#") + [ -z "${line}" ] && continue + + # retrieve playlist params + url=$(echo "${line}" | cut -d " " -f 1) + dir=$(echo "${line}" | cut -d " " -f 2) + + dir="${MUSIC_DIR}/${dir}" + + [ -d "${dir}" ] && + log "${dir}: directory already exists" && + continue + + mkdir "${dir}" + log "${dir} ${url}: download" + + youtube-dl --rm-cache-dir >/dev/null + youtube-dl \ + --extract-audio \ + --audio-format mp3 \ + --prefer-ffmpeg \ + --audio-quality 0 \ + --embed-thumbnail \ + --metadata-from-title "%(artist)s - %(title)s" \ + --no-warnings \ + --ignore-errors \ + --no-overwrites \ + --continue \ + --add-metadata \ + --user-agent "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" \ + --output "${dir}/'%(title)s.%(ext)s'" \ + "${url}" + + + done < "${MUSIC_FILE}" +} + +main ${@} -- cgit v1.2.3