2022-03-30 02:47:33 +03:00
|
|
|
#!/bin/sh
|
|
|
|
|
2022-03-31 01:48:53 +03:00
|
|
|
instance=$(jj -i config.json instance)
|
2022-03-30 02:47:33 +03:00
|
|
|
ordering='title'
|
2022-04-01 01:12:45 +03:00
|
|
|
default_player_command='mpv --no-vid --no-ytdl --network-timeout=30'
|
2022-03-30 02:47:33 +03:00
|
|
|
|
2022-04-02 02:26:22 +03:00
|
|
|
instance_point="https://$instance/api/v1"
|
2022-03-30 02:47:33 +03:00
|
|
|
funkwhale_api_check_api_limits()
|
|
|
|
{
|
2022-04-02 02:26:22 +03:00
|
|
|
curl -s --compressed "$instance_point/rate-limit/" | jj -p
|
2022-03-30 02:47:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
funkwhale_api_get_tracks()
|
|
|
|
{
|
2022-04-02 02:26:22 +03:00
|
|
|
get_json=$(curl -s --compressed "$instance_point/tracks?ordering=$ordering&playable=true&page=$1&tag=$tag" 2>&1 | tee preload)
|
2022-03-31 14:15:43 +03:00
|
|
|
jj -i preload -l 'results.#.uploads.0.listen_url' | sed 's/"//g'
|
2022-03-30 02:47:33 +03:00
|
|
|
}
|
|
|
|
|
2022-03-31 19:23:14 +03:00
|
|
|
funkwhale_api_get_tracks_from_channel()
|
2022-03-30 02:47:33 +03:00
|
|
|
{
|
2022-04-02 02:26:22 +03:00
|
|
|
track_list=$(curl -s --compressed "$instance_point/tracks?channel=$1&playable=true&include_channels=true")
|
2022-03-31 19:23:14 +03:00
|
|
|
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...'
|
2022-04-02 02:26:22 +03:00
|
|
|
curl -s --compressed --output preload "$instance_point/artists?ordering=-creation_date&playable=true&include_channels=true&content_category=podcast&page=$1"
|
2022-03-31 19:23:14 +03:00
|
|
|
counter=0
|
|
|
|
count_artists=$(jj -i preload count)
|
|
|
|
echo "$count_artists avalaible"
|
2022-04-02 13:16:13 +03:00
|
|
|
artist_channels=$(jj -l -i preload 'results.#.channel.uuid' | sed 's/"//g')
|
|
|
|
podcast_names=$(jj -l -i preload results.#.name | sed 's/\./_/g' | sed 's/"//g')
|
2022-04-02 17:19:37 +03:00
|
|
|
temp_artists="{}"
|
2022-03-31 19:23:14 +03:00
|
|
|
for i in $artist_channels; do
|
2022-04-02 17:19:37 +03:00
|
|
|
name_uuid=$(echo $temp_artists | jj -v "$i" "$(jj -i preload results.$counter.name | sed 's/\./_/g' | sed 's/\"//g')")
|
|
|
|
temp_artists="${name_uuid}"
|
2022-03-31 19:23:14 +03:00
|
|
|
counter=$(expr $counter + 1)
|
|
|
|
done
|
2022-04-02 15:33:36 +03:00
|
|
|
menu_podcast_choice=$(echo "$podcast_names" | fzy)
|
2022-04-02 17:19:37 +03:00
|
|
|
channel_uuid=$(echo $temp_artists | jj "$menu_podcast_choice")
|
2022-04-02 13:16:13 +03:00
|
|
|
if [ -z $channel_uuid ]; then
|
|
|
|
echo 'Error when loading podcast'
|
|
|
|
else
|
|
|
|
funkwhale_api_get_tracks_from_channel $channel_uuid
|
|
|
|
fi
|
2022-03-30 02:47:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
load_tracks_to_playlist()
|
|
|
|
{
|
2022-03-30 18:36:18 +03:00
|
|
|
echo "Loading page $1 ..."
|
|
|
|
echo '#EXTM3U\n' > playlist.m3u8
|
|
|
|
counter_titles=0
|
|
|
|
for i in $(funkwhale_api_get_tracks $1); do
|
2022-03-31 14:15:43 +03:00
|
|
|
title=$(jj -i preload results."$counter_titles".title)
|
2022-04-01 13:00:42 +03:00
|
|
|
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
|
2022-03-30 18:36:18 +03:00
|
|
|
counter_titles=$(expr $counter_titles + 1)
|
|
|
|
echo "https://$instance$i\n" >> playlist.m3u8
|
2022-03-30 02:47:33 +03:00
|
|
|
done
|
2022-03-31 14:15:43 +03:00
|
|
|
count_tracks_results=$(jj -i preload 'results.#')
|
2022-04-02 03:26:36 +03:00
|
|
|
if [ -z $count_tracks_results ] || [ $count_tracks_results -eq 0 ]; then
|
|
|
|
echo 'Error: Page empty or connection error'
|
2022-03-31 14:15:43 +03:00
|
|
|
else
|
|
|
|
echo "Loaded $count_tracks_results tracks"
|
|
|
|
fi
|
2022-03-30 02:47:33 +03:00
|
|
|
}
|
|
|
|
|
2022-03-30 19:58:30 +03:00
|
|
|
get_all_avalaible_count_tracks()
|
|
|
|
{
|
|
|
|
funkwhale_api_get_tracks 1 1>> /dev/null
|
2022-03-31 14:15:43 +03:00
|
|
|
count_all_tracks=$(jj -i preload -l count)
|
2022-04-02 03:01:25 +03:00
|
|
|
if [ -z $count_all_tracks ]; then
|
|
|
|
echo 'Error: Connection error or API limit expired'
|
|
|
|
elif [ $count_all_tracks -eq 0 ]; then
|
|
|
|
echo 'Error: No tracks'
|
|
|
|
else
|
|
|
|
echo "Tracks avalaible on $instance: $count_all_tracks\n"
|
|
|
|
fi
|
2022-03-30 19:58:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
get_all_avalaible_count_tracks
|
2022-03-30 15:04:30 +03:00
|
|
|
|
2022-03-30 02:47:33 +03:00
|
|
|
downloadtrackspls='Download tracks in playlist'
|
|
|
|
startplayer='Start player'
|
2022-03-31 19:23:14 +03:00
|
|
|
podcasts='Podcasts'
|
2022-03-30 19:58:30 +03:00
|
|
|
changepod='Switch instance'
|
2022-03-30 02:47:33 +03:00
|
|
|
checkapilimits='Check API limits (debug)'
|
|
|
|
Exit='Exit'
|
|
|
|
|
|
|
|
while true; do
|
2022-03-31 19:23:14 +03:00
|
|
|
choice=$(echo "$downloadtrackspls\n$startplayer\n$podcasts\n$changepod\n$checkapilimits\n$Exit" | fzy)
|
2022-03-30 02:47:33 +03:00
|
|
|
|
2022-04-02 03:16:31 +03:00
|
|
|
case "$choice" in
|
|
|
|
"$downloadtrackspls")
|
2022-03-30 21:13:25 +03:00
|
|
|
echo 'Order by (prefix - is DESC ordering):'
|
2022-03-31 14:15:43 +03:00
|
|
|
ordering=$(echo 'title\n-title\ncreation_date\n-creation_date\nrelease_date\n-release_date\nrandom' | fzy)
|
2022-03-30 21:13:25 +03:00
|
|
|
export ordering
|
2022-03-31 21:19:08 +03:00
|
|
|
echo 'Tags:'
|
|
|
|
tag=$(jj -l -i config.json tags | sed 's/"//g' | fzy)
|
|
|
|
if [ "$tag" = "TagOFF" ]; then
|
|
|
|
tag=
|
|
|
|
fi
|
|
|
|
export tag
|
2022-03-30 02:47:33 +03:00
|
|
|
echo 'Enter page number: '
|
|
|
|
read page
|
2022-04-02 03:16:31 +03:00
|
|
|
load_tracks_to_playlist $page ;;
|
|
|
|
|
|
|
|
|
|
|
|
"$startplayer")
|
|
|
|
$default_player_command playlist.m3u8 ;;
|
|
|
|
|
|
|
|
|
|
|
|
"$podcasts")
|
2022-03-31 19:23:14 +03:00
|
|
|
echo 'Enter page number: '
|
|
|
|
read page
|
2022-04-02 03:16:31 +03:00
|
|
|
funkwhale_get_podcasts_artists $page ;;
|
|
|
|
|
|
|
|
|
|
|
|
"$changepod")
|
2022-04-01 02:52:11 +03:00
|
|
|
if [ 'Choice from list' = "$(echo 'Choice from list\nManual input' | fzy)" ]; then
|
|
|
|
instance=$(jj -l -i config.json public_list_instances | sed 's/"//g' | fzy)
|
|
|
|
else
|
|
|
|
echo "Type instance (ex. $instance):"
|
|
|
|
read instance
|
|
|
|
fi
|
2022-04-02 03:01:25 +03:00
|
|
|
|
2022-03-30 19:58:30 +03:00
|
|
|
export instance
|
2022-04-02 03:01:25 +03:00
|
|
|
export instance_point="https://$instance/api/v1"
|
2022-03-31 01:48:53 +03:00
|
|
|
conf_instance_state=$(echo 'Permanent\nTemporaly' | fzy)
|
|
|
|
if [ "$conf_instance_state" = 'Permanent' ]; then
|
|
|
|
jj -i config.json instance -v $instance -o config.json
|
|
|
|
else
|
|
|
|
echo ''
|
|
|
|
fi
|
2022-03-30 19:58:30 +03:00
|
|
|
clear
|
2022-04-02 03:16:31 +03:00
|
|
|
get_all_avalaible_count_tracks ;;
|
|
|
|
|
|
|
|
|
|
|
|
"$checkapilimits")
|
|
|
|
funkwhale_api_check_api_limits | more ;;
|
|
|
|
|
|
|
|
|
|
|
|
"$Exit")
|
|
|
|
exit 0 ;;
|
|
|
|
esac
|
2022-03-30 02:47:33 +03:00
|
|
|
done
|