This commit is contained in:
Jaroslaw Konik 2026-04-24 15:48:01 +02:00
parent 8e8382aa88
commit d43ce1ee0e

View file

@ -1,6 +1,10 @@
#!/bin/sh
query="$(playerctl -i firefox metadata --format '{{ artist }} - {{ title }}')"
query_artist="$(playerctl -i firefox metadata --format '{{ artist }}')"
query_title="$(playerctl -i firefox metadata --format '{{ title }}')"
query="$query_artist - $query_title"
tmpdir="$(mktemp -d)"
echo "Searching YouTube for:"
echo " $query"
@ -9,11 +13,8 @@ echo
yt-dlp "ytsearch1:$query" \
--print "━━━━━━━━━━━━━━━━━━━━━━━" \
--print "Title: %(title)s" \
--print "Artist: %(artist|Unknown)s" \
--print "Track: %(track|Unknown)s" \
--print "Channel: %(uploader)s" \
--print "Duration: %(duration_string)s" \
--print "Views: %(view_count)s" \
--print "URL: %(webpage_url)s" \
--print "━━━━━━━━━━━━━━━━━━━━━━━"
@ -21,9 +22,22 @@ echo
read -p "Download this? [y/N] " confirm
if [[ "$confirm" =~ ^[Yy]$ ]]; then
yt-dlp --embed-metadata -x --audio-format aac -f bestaudio \
"ytsearch1:$query" \
-o "~/Music/%(artist)s - %(title)s.%(ext)s"
yt-dlp -x --audio-format m4a -f bestaudio \
"ytsearch1:$query" \
--embed-metadata \
-o "$tmpdir/%(artist)s - %(albums)s - %(title)s.%(ext)s"
file="$(ls "$tmpdir"/* 2>/dev/null | head -n1)"
if [[ -n "$file" ]]; then
beet import --from-scratch -s "$file"
else
echo "Download failed. Even chaos has limits."
fi
rm -rf "$tmpdir"
else
echo "Aborted. You resisted entropy."
echo "Aborted."
fi
read -n 1 -s -r -p "Done. Press any key to close."