diff options
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/commands/:music-web | 5 | ||||
| -rwxr-xr-x | scripts/music/player.sh | 2 | ||||
| -rwxr-xr-x | scripts/music/yt-music.sh | 59 |
3 files changed, 60 insertions, 6 deletions
diff --git a/scripts/commands/:music-web b/scripts/commands/:music-web deleted file mode 100755 index a14afc8..0000000 --- a/scripts/commands/:music-web +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env sh - -xdg-open 'http://localhost:6680' - -# spotify diff --git a/scripts/music/player.sh b/scripts/music/player.sh index 270d02f..2c89914 100755 --- a/scripts/music/player.sh +++ b/scripts/music/player.sh @@ -2,7 +2,7 @@ MAX_CHARS=36 -player() { playerctl --player=mopidy "$@"; } +player() { playerctl --player=mpd "$@"; } # Get player state #get_play_state() { player metadata --format '{{status}}' || echo 'Stopped'; } diff --git a/scripts/music/yt-music.sh b/scripts/music/yt-music.sh new file mode 100755 index 0000000..abf2fac --- /dev/null +++ b/scripts/music/yt-music.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env sh + +set -e -o pipefail + +MUSIC_DIR="$HOME/Downloads/music" + +yt_download() { + local url="$1" + + if [ -z "$url" ]; then + url=$(echo -n "" | dmenu -p "YT music URL :: ") + fi + + if [ -z "$url" ]; then + echo "Nothing to download"; + exit 1; + fi + + if is_downloaded "$url" && [ ! "$FORCE" == "1" ]; then + echo "== already downloaded ==" + return 0; + fi + + yt-dlp -x --audio-format mp3 \ + --embed-metadata --embed-thumbnail \ + --parse-metadata "playlist_index:%(track_number)s" --add-metadata \ + -o "$MUSIC_DIR/%(artist|Others)s/%(album,playlist)s/%(playlist_index)02d - %(title)s.%(ext)s" \ + "$url" \ + && mark_as_done "$url" +} + +is_downloaded() { grep "$1" "$MUSIC_DIR/music.lock" > /dev/null 1>&2; } + +mark_as_done() { + echo "$1" >> "$MUSIC_DIR/music.lock" + sort -u "$MUSIC_DIR/music.lock" -o "$MUSIC_DIR/music.lock" +} + +library_data() { jq -r "$1" "$MUSIC_DIR/music.json"; } + +sync_library() { + library_data ".[].url" | while read url; do + yt_download "$url" || notify-send -u critical "Sync failed for $url" + done +} + +cmd="$1"; shift 1; +case "$cmd" in + yt) + yt_download "$@" \ + && notify-send "Music downloaded" \ + || notify-send -u critical "Music download failed" + ;; + sync) + sync_library && notify-send "Sync done" + ;; + *) echo "invalid cmd. (yt | sync)"; exit 1 ;; +esac + |
