From d0f5d41a7063baef37e746b217e102e505ae232d Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Sun, 10 Apr 2022 22:55:20 +0300 Subject: [PATCH] Directly load tracks if artist not have albums --- funkwhale-cli.sh | 71 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 66 insertions(+), 5 deletions(-) diff --git a/funkwhale-cli.sh b/funkwhale-cli.sh index 1505f81..cf3558d 100755 --- a/funkwhale-cli.sh +++ b/funkwhale-cli.sh @@ -29,8 +29,62 @@ funkwhale_api_check_api_limits() funkwhale_api_get_tracks() { - get_json=$(default_curl_opt "$instance_point/tracks?ordering=$ordering&playable=true&page=$1&tag=$tag" 2>&1 | tee preload) - jj -i preload -l 'results.#.uploads.0.listen_url' | sed 's/"//g' + default_curl_opt \ + "$instance_point/tracks?ordering=$ordering&playable=true&page=$1&tag=$tag&artist=$2" \ + 2>&1 | tee preload +} + +funkwhale_menu_tracks() +{ + echo 'Loading tracks...' + funkwhale_api_get_tracks 1 $1 + count_tracks_results=$(jj -i preload 'results.#') + echo '#EXTM3U\n' > playlist.m3u8 + chmod 600 playlist.m3u8 + counter_titles=0 + level=1 + + while [ $sub2_menu -eq $level ]; do + titles=$(jj -i preload -l results.#.title | nl -s: -v0 -w1) + playlist=$(jj -i preload -l results.#.listen_url | sed 's/"//g') + menu_album_tracks_choice=$(echo "Back\nMain menu\nListen all\n$titles" | fzy) + case $menu_album_tracks_choice in + "Back") + if [ $sub2_menu -eq 2 ]; then + sub2_menu=1 + else + sub2_menu=0 + fi ;; + "Main menu") sub2_menu=0 && sub_menu=0 ;; + + "Listen all") + echo > playlist.m3u8 + chmod 600 playlist.m3u8 + tracks_for_playlist=$(jj -i preload -l 'results.#.uploads.0.listen_url' | sed 's/"//g') + for i in $tracks_for_playlist; do + title=$(jj -i preload results."$counter_titles".title) + artist_name=$(jj -i preload results."$counter_titles".artist.name) + duration=$(jj -i preload results."$counter_titles".uploads.0.duration) + echo "#EXTINF:$duration, $artist_name - $title" >> playlist.m3u8 + counter_titles=$(expr $counter_titles + 1) + if [ -n "$auth" ]; then + echo "https://$instance$i&token=$listen_token\n" >> playlist.m3u8 + else + echo "https://$instance$i\n" >> playlist.m3u8 + fi + done + $default_player_command playlist.m3u8 ;; + + *) + 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 ;; + esac + done } funkwhale_api_get_albums() @@ -149,9 +203,15 @@ funkwhale_menu_albums_artist() echo 'Loading albums...' albums_a=$(funkwhale_api_get_artist $1) standart_albums='albums.#.title' - count_type='albums.#' + count_albums=$(echo $albums_a | jj albums.\#) + if [ $count_albums -eq 0 ]; then + echo 'failed: no albums, getting tracks...' + sub2_menu=1 + funkwhale_menu_tracks $1 + return 1 + fi index_type='albums' - echo "Avalaible $(echo $albums_a | jj $count_type) albums" + echo "Avalaible $count_albums albums" sub2_menu=1 while [ $sub2_menu -eq 1 ]; do titles=$(echo $albums_a | jj -l $standart_albums | nl -s: -v0 -w1) @@ -223,7 +283,8 @@ load_tracks_to_playlist() echo '#EXTM3U\n' > playlist.m3u8 chmod 600 playlist.m3u8 counter_titles=0 - for i in $(funkwhale_api_get_tracks $1); do + funkwhale_api_get_tracks $1 + for i in $(jj -i preload -l 'results.#.uploads.0.listen_url' | sed 's/"//g'); do title=$(jj -i preload results."$counter_titles".title) artist_name=$(jj -i preload results."$counter_titles".artist.name) duration=$(jj -i preload results."$counter_titles".uploads.0.duration)