#!/usr/bin/env fish

set url $argv[1]

set folder (string collect (yt-dlp -I 1:1 --skip-download --print "%(artists.0,artist)s" $url) - (yt-dlp -I 1:1 --skip-download --print "%(album)s" $url))

mkdir "$folder"
cd "$folder"

yt-dlp \
	--parse-metadata "playlist_index:%(track_number)s" \
	--parse-metadata "%(artists.0,artist)s:%(meta_artist)s" \
	--parse-metadata "%(release_date,upload_date)s:%(meta_date)s" \
	--embed-metadata \
	--extract-audio --audio-format opus \
	-o "%(playlist_index)s - %(title)s.%(ext)s" $url

yt-dlp -I 1:0 --write-thumbnail -o "cover.jpg" $url

for file in *.opus
    opustags -i --set-cover cover.jpg $file
end

