This repository has been archived on 2024-04-07. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/dotfiles/scripts/dzadd

72 lines
1.7 KiB
Bash
Executable File

#!/bin/sh
set -ex
tmpf=$(mktemp)
choose(){
choice=$(grep "$(cat $tmpf | cut -d\| -f1| wdmenu)" $tmpf)
choiceId="$(echo $choice| cut -d\| -f2)"
choiceUrl=http://deezer.com/$sType/$choiceId
choicePreview=$( curl -s "api.deezer.com/$sType/$choiceId/$preview_suffix" |
jq -r '.preview, .data[0].preview | select(. != null)' )
choice=$( printf "Preview\nDownload\nCopy URL" | wdmenu )
if [ "$choice" = Preview ]
then
mpv --quiet "$choicePreview" &
mpvPid=$!
choice=$(printf "Download\nAnother" | wdmenu -p 'Download?')
kill $mpvPid
if test "$choice" = "Another"
then
choose
return
fi
fi
if [ "$choice" = Download ]
then
notify-send "Starting Download"
deemix "$choiceUrl" &&
notify-send "Download Successful" ||
notify-send "Download Failed"
mpc add /
mpdDup
fi
if [ "$choice" = "Copy URL" ]
then
wl-copy "$choiceUrl"
fi
}
clean(){
set +e
kill "$mpvPid"
rm -f $tmpf
}
trap clean EXIT
sType=$(printf "Track\nAlbum\nArtist" | wdmenu | tr [:upper:] [:lower:] )
query=$(echo -n | wdmenu | sed 's/[^ a-z]//g;s/ /+/g')
case "$sType" in
track)
jqFilter='.data[]|.title+" - "+.album.title+" - "+.artist.name+"|"+( .id | tostring ) '
;;
album)
jqFilter='.data[]| ( .nb_tracks | tostring ) +" - "+.title+" - "+.artist.name+"|"+ ( .id | tostring ) '
preview_suffix=tracks
;;
artist)
jqFilter='.data[]| ( .nb_fan | tostring ) +" - "+.name+"|"+ ( .id | tostring ) '
preview_suffix=top
;;
esac
curl -s "api.deezer.com/search/$sType?q=${query}" |
jq -r "$jqFilter" > $tmpf
choose