From da859e570e5689c29e244ca51b5c5e65a09d4ca2 Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Sun, 10 Apr 2022 23:19:22 +0300 Subject: [PATCH] Merge functions download tracks to playlist and select avalaible --- README.md | 2 +- funkwhale-cli.sh | 47 ++++++++--------------------------------------- 2 files changed, 9 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index bc798a9..8be7e15 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Just for fun. Simple "player" API script for FunkWhale instances. Features: -* Download tracks url's in playlist per page +* Select and listen tracks * Select and listen albums * Select and listen artists * Select and listen podcasts diff --git a/funkwhale-cli.sh b/funkwhale-cli.sh index cf3558d..312399c 100755 --- a/funkwhale-cli.sh +++ b/funkwhale-cli.sh @@ -36,13 +36,14 @@ funkwhale_api_get_tracks() funkwhale_menu_tracks() { + sub2_menu=1 + level=1 echo 'Loading tracks...' - funkwhale_api_get_tracks 1 $1 + funkwhale_api_get_tracks $1 $2 1>> /dev/null 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) @@ -207,7 +208,7 @@ funkwhale_menu_albums_artist() if [ $count_albums -eq 0 ]; then echo 'failed: no albums, getting tracks...' sub2_menu=1 - funkwhale_menu_tracks $1 + funkwhale_menu_tracks 1 $1 return 1 fi index_type='albums' @@ -277,33 +278,6 @@ funkwhale_get_podcasts_artists() done } -load_tracks_to_playlist() -{ - echo "Loading page $1 ..." - echo '#EXTM3U\n' > playlist.m3u8 - chmod 600 playlist.m3u8 - counter_titles=0 - 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) - 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 - count_tracks_results=$(jj -i preload 'results.#') - if [ -z $count_tracks_results ] || [ $count_tracks_results -eq 0 ]; then - echo 'Error: Page empty or connection error' - else - echo "Loaded $count_tracks_results tracks" - fi -} - get_all_avalaible_count_tracks() { funkwhale_api_get_tracks 1 1>> /dev/null @@ -319,8 +293,7 @@ get_all_avalaible_count_tracks() get_all_avalaible_count_tracks -downloadtrackspls='Download tracks in playlist' -startplayer='Start player' +trackspls='Tracks' albumsmenu='Albums' artistmenu='Artists' podcasts='Podcasts' @@ -329,10 +302,10 @@ checkapilimits='Check API limits (debug)' Exit='Exit' while true; do -choice=$(echo "$downloadtrackspls\n$startplayer\n$albumsmenu\n$artistmenu\n$podcasts\n$changepod\n$checkapilimits\n$Exit" | fzy) +choice=$(echo "$trackspls\n$albumsmenu\n$artistmenu\n$podcasts\n$changepod\n$checkapilimits\n$Exit" | fzy) case "$choice" in - "$downloadtrackspls") + "$trackspls") echo 'Order by (prefix - is DESC ordering):' ordering=$(echo 'title\n-title\ncreation_date\n-creation_date\nrelease_date\n-release_date\nrandom' | fzy) export ordering @@ -344,12 +317,8 @@ case "$choice" in export tag echo 'Enter page number: ' read page - load_tracks_to_playlist $page ;; - + funkwhale_menu_tracks $page ;; - "$startplayer") - $default_player_command playlist.m3u8 ;; - "$albumsmenu") echo 'Enter page number: ' read page