Add dzadd script

This commit is contained in:
lelgenio 2023-04-11 14:43:38 -03:00
parent 76855bedf9
commit 62bd9e6676
5 changed files with 188 additions and 0 deletions

View file

@ -41,6 +41,8 @@ create_scripts
volumesh = [ pulseaudio libnotify ];
pulse_sink = [ pulseaudio pamixer final.wdmenu ];
color_picker = [ grim slurp wl-clipboard libnotify imagemagick ];
dzadd = [ procps libnotify final.wdmenu jq mpv pqiv python3Packages.deemix mpc-cli final.mpdDup ];
mpdDup = [ mpc-cli perl ];
} // lib.mapAttrs import_script {
wdmenu = ./wdmenu.nix;
wlauncher = ./wlauncher.nix;

176
scripts/dzadd Executable file
View file

@ -0,0 +1,176 @@
#!/bin/sh
set -ex
tmpf=$(mktemp /tmp/dzadd.XXXXXX)
clean() {
test "$?" -eq "0" ||
notify-send "Exiting with error"
set +e
kill "$mpvPid"
rm -f "$tmpf"
}
trap clean EXIT
main() {
sType=$(printf "Track\nAlbum\nArtist" | wdmenu | tr '[:upper:]' '[:lower:]')
test -n "$sType" || exit 1
query=$(echo -n | wdmenu | sed 's/[^ a-z0-9]//g;s/ /+/g')
test -n "$query" || exit 1
case "$sType" in
track)
deezer_category="track"
jqFilter='.data[]| "\(.title) - \(.album.title) - \(.artist.name) |\(.id)"'
;;
album)
deezer_category="album"
jqFilter='.data[]| "\(.nb_tracks) - \(.title) - \(.artist.name) |\(.id)"'
;;
artist)
deezer_category="artist"
jqFilter='.data[]| "\(.nb_fan) - \(.name) |\(.id)"'
;;
top50)
deezer_category="artist"
jqFilter='.data[]| "\(.nb_fan) - \(.name) |\(.id)"'
;;
*)
exit 1
;;
esac
curl -m30 -s "api.deezer.com/search/${deezer_category}?q=${query}" |
sed 's/|//g' |
jq -r "$jqFilter" >"$tmpf"
pick_song
}
pick_song() {
choice=$(cat "$tmpf" | cut -d\| -f1 | wdmenu)
choice=$(grep "$choice" "$tmpf" | head -n 1)
choiceId=$(printf "%s" "$choice" | cut -d\| -f2)
case "$sType" in
top50)
choiceUrl="http://deezer.com/${deezer_category}/${choiceId}/top?=limit=50"
;;
*)
choiceUrl="http://deezer.com/${deezer_category}/${choiceId}"
;;
esac
pick_action "$choiceUrl"
}
pick_action() {
choiceUrl="$1"
COMMON_CHOISES="View Image\nDownload\nCopy URL\nAnother"
choice=$(printf "Preview\n${COMMON_CHOISES}" | wdmenu)
case "$choice" in
"Preview")
common_preview
;;
"View Image")
common_art
;;
"Download")
common_download
;;
"Copy URL")
wl-copy
;;
"Another")
pick_song
;;
*)
exit 1
;;
esac
}
common_preview() {
case "$sType" in
track)
;;
album)
preview_suffix=tracks
;;
artist)
preview_suffix=top
;;
top50)
preview_suffix=top
;;
*)
exit 1
;;
esac
choicePreview=$(
curl -m30 -s "http://api.deezer.com/${deezer_category}/${choiceId}/${preview_suffix}" |
jq -r '.preview, .data[0].preview | select(. != null)'
)
mpv --quiet --volume=50 --no-resume-playback "$choicePreview" &
mpvPid="$!"
choice=$(printf "$COMMON_CHOISES" | wdmenu -p 'Download?')
kill "$mpvPid" || true
}
common_art() {
case "$sType" in
track)
image_filter='.album.cover_big'
;;
album)
image_filter='.cover_big'
;;
artist)
image_filter='.picture_big'
;;
top50)
image_filter='.picture_big'
;;
*)
exit 1
;;
esac
curl -m30 -s "api.deezer.com/${deezer_category}/${choiceId}" |
jq -r "$image_filter" |
xargs curl -m30 -s |
pqiv -
pick_action
}
common_download() {
notify-send "Starting Download"
deemix "$choiceUrl" </dev/null &&
notify-send "Download Successful" ||
notify-send "Download Failed"
mpc add /
mpdDup
}
main

5
scripts/mpdDup Executable file
View file

@ -0,0 +1,5 @@
#!/bin/sh
mpc playlist -f '%position%\t%file%' |
sort -k 2 |
perl -ne 'm/(.*)\t(.*)/; print "$1\n" if $2 eq $prev; $prev=$2' |
mpc del

View file

@ -20,5 +20,8 @@
};
home.packages = with pkgs; [
musmenu
python3Packages.deemix
dzadd
mpdDup
];
}

View file

@ -35,6 +35,8 @@ in
"d" = "exec ${pkgs.musmenu}/bin/musmenu delete";
"f" = "exec ${pkgs.musmenu}/bin/musmenu search";
"a" = "exec ${pkgs.dzadd}/bin/dzadd";
"Shift+y" = "exec ${pkgs.musmenu}/bin/musmenu yank";
"Ctrl+a" = "exec ${pkgs.musmenu}/bin/musmenu padd";
"Ctrl+s" = "exec ${pkgs.musmenu}/bin/musmenu psave";