mirror of
http://gitea.phreedom.club/localhost_frssoft/funkwlmpv
synced 2024-11-05 15:13:12 +00:00
87 lines
2.3 KiB
Bash
Executable file
87 lines
2.3 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
instance=$(jj -i config.json instance)
|
|
default_player=mpv
|
|
ordering='title'
|
|
|
|
funkwhale_api_check_api_limits()
|
|
{
|
|
curl -s "https://$instance/api/v1/rate-limit/" | jj -p
|
|
}
|
|
|
|
funkwhale_api_get_tracks()
|
|
{
|
|
get_json=$(curl -s "https://$instance/api/v1/tracks?ordering=$ordering&playable=true&page=$1" 2>&1 | tee preload)
|
|
jj -i preload -l 'results.#.uploads.0.listen_url' | sed 's/"//g'
|
|
}
|
|
|
|
funkwhale_api_get_albums()
|
|
{
|
|
curl -s https://$instance/api/v1/albums/ | jj -p results
|
|
}
|
|
|
|
load_tracks_to_playlist()
|
|
{
|
|
echo "Loading page $1 ..."
|
|
echo '#EXTM3U\n' > playlist.m3u8
|
|
counter_titles=0
|
|
for i in $(funkwhale_api_get_tracks $1); do
|
|
title=$(jj -i preload results."$counter_titles".title)
|
|
echo "#EXTINF:-1, $counter_titles - $title" >> playlist.m3u8
|
|
counter_titles=$(expr $counter_titles + 1)
|
|
echo "https://$instance$i\n" >> playlist.m3u8
|
|
done
|
|
count_tracks_results=$(jj -i preload 'results.#')
|
|
if [ -z $count_tracks_results ]; then
|
|
echo 'Error: Page empty or 500 Internal Server Error'
|
|
else
|
|
echo "Loaded $count_tracks_results tracks"
|
|
fi
|
|
}
|
|
|
|
get_all_avalaible_count_tracks()
|
|
{
|
|
funkwhale_api_get_tracks 1 1>> /dev/null
|
|
count_all_tracks=$(jj -i preload -l count)
|
|
echo "Tracks avalaible on $instance: $count_all_tracks\n"
|
|
}
|
|
|
|
get_all_avalaible_count_tracks
|
|
|
|
downloadtrackspls='Download tracks in playlist'
|
|
startplayer='Start player'
|
|
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)
|
|
|
|
if [ "$choice" = "$downloadtrackspls" ]; then
|
|
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
|
|
echo 'Enter page number: '
|
|
read page
|
|
load_tracks_to_playlist $page
|
|
elif [ "$choice" = "$startplayer" ]; then
|
|
$default_player --no-vid --no-ytdl playlist.m3u8
|
|
elif [ "$choice" = "$changepod" ]; then
|
|
echo "Type instance (ex. $instance):"
|
|
read instance
|
|
export instance
|
|
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
|
|
clear
|
|
get_all_avalaible_count_tracks
|
|
elif [ "$choice" = "$checkapilimits" ]; then
|
|
funkwhale_api_check_api_limits | more
|
|
elif [ "$choice" = "$Exit" ]; then
|
|
exit 0
|
|
fi
|
|
done
|