diff --git a/funkwhale-cli.sh b/funkwhale-cli.sh index e7147ad..6593169 100755 --- a/funkwhale-cli.sh +++ b/funkwhale-cli.sh @@ -9,20 +9,27 @@ download_selected_track=$(jj -i config.json download_selected_track) touch .auth.json chmod 600 .auth.json -auth="$(jj -i .auth.json "$(echo "$instance" | sed 's/\./\\\./g')")" -if [ -n "$auth" ]; then - default_curl_opt() - { - curl -s --compressed -H "Authorization: Bearer $auth" "$@" - } - listen_token=$(default_curl_opt "$instance_point/users/me" | jj tokens.listen) - echo '+Authorized account+' -else - default_curl_opt() - { - curl -s --compressed "$@" - } -fi + +make_login() +{ + auth="$(jj -i .auth.json "$(echo "$instance" | sed 's/\./\\\./g')")" + if [ -n "$auth" ]; then + default_curl_opt() + { + curl -s --compressed -H "Authorization: Bearer $auth" "$@" + } + listen_token=$(default_curl_opt "$instance_point/users/me" | jj tokens.listen) + echo '+Authorized account+' + export listen_token + else + default_curl_opt() + { + curl -s --compressed "$@" + } + fi + export default_curl_opt +} +make_login delq() { @@ -40,11 +47,11 @@ funkwhale_api_tags() if [ ! -f "tags_db/tags_$instance.gz" ]; then tagsload=$(default_curl_opt "$instance_point/tags?playable=true") pageindex=$(echo "$tagsload" | jj next) - echo "$tagsload" | jj -l results.#.name | delq | gzip > tags_db/tags_"$instance".gz + echo "$tagsload" | jj -l 'results.#.name' | delq | gzip > tags_db/tags_"$instance".gz clear while [ -n "$pageindex" ]; do - echo "Loading... +$(echo "$tagsload" | jj results.#) tags" - echo "$tagsload" | jj -l results.#.name | delq | gzip >> tags_db/tags_"$instance".gz + echo "Loading... +$(echo "$tagsload" | jj 'results.#') tags" + echo "$tagsload" | jj -l 'results.#.name' | delq | gzip >> tags_db/tags_"$instance".gz pageindex=$(echo "$tagsload" | jj next) tagsload=$(default_curl_opt "$pageindex") sleep 1 @@ -178,8 +185,8 @@ funkwhale_menu_albums_tracks() while [ $sub2_menu -eq $level ]; do - titles=$(echo "$tracks_a" | jj -l results.#.title | nl -s: -v0 -w1) - playlist=$(echo "$tracks_a" | jj -l results.#.listen_url | delq) + titles=$(echo "$tracks_a" | jj -l 'results.#.title' | nl -s: -v0 -w1) + playlist=$(echo "$tracks_a" | jj -l 'results.#.listen_url' | delq) menu_album_tracks_choice=$(echo "Back\nMain menu\nListen all\n$titles" | fzy) case $menu_album_tracks_choice in "Back") @@ -308,7 +315,7 @@ funkwhale_get_podcasts_artists() while [ $sub_menu -eq 1 ]; do count_artists=$(jj -i preload count) echo "$count_artists avalaible" - podcast_names=$(jj -l -i preload results.#.name | nl -s: -v0 -w1) + podcast_names=$(jj -l -i preload 'results.#.name' | nl -s: -v0 -w1) menu_podcast_choice=$(echo "Main menu\n$podcast_names" | fzy) case $menu_podcast_choice in "Main menu") sub_menu=0 ;; @@ -405,8 +412,7 @@ case "$choice" in if [ $empty -eq 0 ]; then echo "$instance" >> $instance_hist cat $instance_hist | sort | uniq | tee $instance_hist 1>>/dev/null - export instance - export instance_point="https://$instance/api/v1" + instance_point="https://$instance/api/v1" conf_instance_state=$(echo 'Permanent\nTemporaly' | fzy) if [ "$conf_instance_state" = 'Permanent' ]; then jj -i config.json instance -v "$instance" -o config.json @@ -414,20 +420,7 @@ case "$choice" in echo '' fi clear - auth="$(jj -i .auth.json "$(echo "$instance" | sed 's/\./\\\./g')")" - if [ -n "$auth" ]; then - default_curl_opt() - { - curl -s --compressed -H "Authorization: Bearer $auth" "$@" - } - listen_token=$(default_curl_opt "$instance_point/users/me" | jj tokens.listen) - echo '+Authorized account+' - else - default_curl_opt() - { - curl -s --compressed "$@" - } - fi + make_login get_all_avalaible_count_tracks fi ;;