Add feature: Download selected track

This commit is contained in:
localhost_frssoft 2022-04-18 11:51:05 +03:00
parent 431ce8e1a5
commit 31770dfe37
3 changed files with 29 additions and 5 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
tags_db
music_dl
playlist.m3u8
preload
instance.hist

View File

@ -1,5 +1,6 @@
{
"instance": "sound.redeyes.club",
"download_selected_track": false,
"tags": [
"8bit",
"Alternative",

View File

@ -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
}