From 31770dfe37e0d5c38a125e5bbfc427f3336c6bb2 Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Mon, 18 Apr 2022 11:51:05 +0300 Subject: [PATCH] Add feature: Download selected track --- .gitignore | 1 + config.json | 1 + funkwhale-cli.sh | 32 +++++++++++++++++++++++++++----- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 5f49724..008ce79 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ tags_db +music_dl playlist.m3u8 preload instance.hist diff --git a/config.json b/config.json index 7007197..0926725 100644 --- a/config.json +++ b/config.json @@ -1,5 +1,6 @@ { "instance": "sound.redeyes.club", + "download_selected_track": false, "tags": [ "8bit", "Alternative", diff --git a/funkwhale-cli.sh b/funkwhale-cli.sh index c19b8d6..4041f07 100755 --- a/funkwhale-cli.sh +++ b/funkwhale-cli.sh @@ -5,6 +5,7 @@ instance_hist='instance.hist' ordering='title' default_player_command='mpv --no-vid --no-ytdl --network-timeout=30' instance_point="https://$instance/api/v1" +download_selected_track=$(jj -i config.json download_selected_track) touch .auth.json chmod 600 .auth.json @@ -60,6 +61,26 @@ funkwhale_api_get_tracks() 2>&1 | tee preload } +play_or_download_selected() +{ + mkdir -p music_dl + if [ -n "$auth" ]; then + if [ "$download_selected_track" = 'true' ]; then + default_curl_opt --tcp-fastopen --output - --url "https://$instance$download_track&token=$listen_token" | \ + tee "music_dl/$artist_name - $title.$download_ext" | $default_player_command - + else + $default_player_command "https://$instance$play_track?token=$listen_token" + fi + else + if [ "$download_selected_track" = 'true' ]; then + default_curl_opt --tcp-fastopen --output - --url "https://$instance$download_track" | \ + tee "music_dl/$artist_name - $title.$download_ext" | $default_player_command - + else + $default_player_command "https://$instance$play_track" + fi + fi +} + funkwhale_menu_tracks() { sub2_menu=1 @@ -105,11 +126,12 @@ funkwhale_menu_tracks() *) index=$(echo $menu_album_tracks_choice | cut -f 1 -d:) play_track=$(jj -i preload results.$index.listen_url) - if [ -n "$auth" ]; then - $default_player_command "https://$instance$play_track?token=$listen_token" - else - $default_player_command "https://$instance$play_track" - fi ;; + download_track=$(jj -i preload results.$index.uploads.0.listen_url) + download_ext=$(jj -i preload results.$index.uploads.0.extension) + title=$(jj -i preload results.$index.title) + artist_name=$(jj -i preload results.$index.artist.name) + play_or_download_selected + ;; esac done }