From 60edd9f52e6524f5b5ad55f3c1904e4c2ea847be Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Thu, 31 Mar 2022 19:23:14 +0300 Subject: [PATCH] Added podcasts section --- .gitignore | 1 + funkwhale-cli.sh | 43 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 125a1b0..335639f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ playlist.m3u8 +podcast.m3u8 preload diff --git a/funkwhale-cli.sh b/funkwhale-cli.sh index 51f33a2..52c8d83 100755 --- a/funkwhale-cli.sh +++ b/funkwhale-cli.sh @@ -1,8 +1,8 @@ #!/bin/sh instance=$(jj -i config.json instance) -default_player=mpv ordering='title' +default_player_command='mpv --no-vid --no-ytdl' funkwhale_api_check_api_limits() { @@ -15,9 +15,37 @@ funkwhale_api_get_tracks() jj -i preload -l 'results.#.uploads.0.listen_url' | sed 's/"//g' } -funkwhale_api_get_albums() +funkwhale_api_get_tracks_from_channel() { - curl -s https://$instance/api/v1/albums/ | jj -p results + track_list=$(curl -s "https://$instance/api/v1/tracks?channel=$1&playable=true&include_channels=true") + echo "Loaded $(echo $track_list | jj count) podcasts" + echo $track_list | jj -l results.#.title + listen_urls=$(echo $track_list | jj -l results.#.listen_url | sed 's/"//g') + echo > podcast.m3u8 + for i in $listen_urls; do + echo "https://$instance$i\n" >> podcast.m3u8 + done + $default_player_command podcast.m3u8 +} + +funkwhale_get_podcasts_artists() +{ + echo 'Loading podcast artists...' + curl -s --output preload "https://$instance/api/v1/artists?ordering=-creation_date&playable=true&include_channels=true&content_category=podcast&page=$1" + counter=0 + count_artists=$(jj -i preload count) + echo "$count_artists avalaible" + artist_channels=$(jj -i preload -l 'results.#.channel.uuid' | sed 's/"//g') + artist_names=$(mktemp) + temp_artists=$(mktemp) + for i in $artist_channels; do + jj -i preload results."$counter".name | sed 's/\./_/g' >> $artist_names + jj -i $temp_artists -v "$i" -o $temp_artists "$(jj -i preload results.$counter.name | sed 's/\./_/g')" + counter=$(expr $counter + 1) + done + menu_artist_choice=$(cat $artist_names | fzy) + channel_uuid=$(jj -i $temp_artists "$menu_artist_choice") + funkwhale_api_get_tracks_from_channel $channel_uuid } load_tracks_to_playlist() @@ -50,12 +78,13 @@ get_all_avalaible_count_tracks downloadtrackspls='Download tracks in playlist' startplayer='Start player' +podcasts='Podcasts' changepod='Switch instance' checkapilimits='Check API limits (debug)' Exit='Exit' while true; do -choice=$(echo "$downloadtrackspls\n$startplayer\n$changepod\n$checkapilimits\n$Exit" | fzy) +choice=$(echo "$downloadtrackspls\n$startplayer\n$podcasts\n$changepod\n$checkapilimits\n$Exit" | fzy) if [ "$choice" = "$downloadtrackspls" ]; then echo 'Order by (prefix - is DESC ordering):' @@ -65,7 +94,11 @@ if [ "$choice" = "$downloadtrackspls" ]; then read page load_tracks_to_playlist $page elif [ "$choice" = "$startplayer" ]; then - $default_player --no-vid --no-ytdl playlist.m3u8 + $default_player_command playlist.m3u8 +elif [ "$choice" = "$podcasts" ]; then + echo 'Enter page number: ' + read page + funkwhale_get_podcasts_artists $page elif [ "$choice" = "$changepod" ]; then echo "Type instance (ex. $instance):" read instance