summaryrefslogtreecommitdiffstats
path: root/.bin/_music
diff options
context:
space:
mode:
authorRomain Gonçalves <me@rgoncalves.se>2022-10-08 12:40:19 +0200
committerRomain Gonçalves <me@rgoncalves.se>2022-10-08 12:40:19 +0200
commitce6be946d024aa55a15d576388d05f90be671cf2 (patch)
treefa1053446a3fb06daee8438c1ff664cb36c0abcb /.bin/_music
parent703ed1915c69911a95cab6e1fb6524629c976800 (diff)
downloaddots-ce6be946d024aa55a15d576388d05f90be671cf2.tar.gz
Sat Oct 8 12:40:19 PM CEST 2022
Diffstat (limited to '.bin/_music')
-rwxr-xr-x.bin/_music70
1 files changed, 70 insertions, 0 deletions
diff --git a/.bin/_music b/.bin/_music
new file mode 100755
index 0000000..6ef5ef8
--- /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"
+
+ yt-dlp --rm-cache-dir >/dev/null
+ yt-dlp \
+ --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 ${@}
remember that computers suck.