Compare commits

..

2 commits

Author SHA1 Message Date
localhost_frssoft 125c76bbed Added auth mode 2022-04-07 22:05:49 +03:00
localhost_frssoft 52b27009e8 Added genre synth 2022-04-07 22:02:45 +03:00
3 changed files with 49 additions and 13 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
playlist.m3u8 playlist.m3u8
preload preload
instance.hist instance.hist
.auth.json

View file

@ -25,6 +25,7 @@
"Reggae", "Reggae",
"Rock", "Rock",
"Singler", "Singler",
"Synth",
"Songwriter", "Songwriter",
"Soundtrack", "Soundtrack",
"Vocal" "Vocal"

View file

@ -4,22 +4,38 @@ instance=$(jj -i config.json instance)
instance_hist='instance.hist' instance_hist='instance.hist'
ordering='title' ordering='title'
default_player_command='mpv --no-vid --no-ytdl --network-timeout=30' default_player_command='mpv --no-vid --no-ytdl --network-timeout=30'
instance_point="https://$instance/api/v1" instance_point="https://$instance/api/v1"
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" $1
}
listen_token=$(default_curl_opt "$instance_point/users/me" | jj tokens.listen)
echo '+Authorized account+'
else
default_curl_opt()
{
curl -s --compressed $1
}
fi
funkwhale_api_check_api_limits() funkwhale_api_check_api_limits()
{ {
curl -s --compressed "$instance_point/rate-limit/" | jj -p default_curl_opt "$instance_point/rate-limit/" | jj -p
} }
funkwhale_api_get_tracks() funkwhale_api_get_tracks()
{ {
get_json=$(curl -s --compressed "$instance_point/tracks?ordering=$ordering&playable=true&page=$1&tag=$tag" 2>&1 | tee preload) get_json=$(default_curl_opt "$instance_point/tracks?ordering=$ordering&playable=true&page=$1&tag=$tag" 2>&1 | tee preload)
jj -i preload -l 'results.#.uploads.0.listen_url' | sed 's/"//g' jj -i preload -l 'results.#.uploads.0.listen_url' | sed 's/"//g'
} }
funkwhale_api_get_albums() funkwhale_api_get_albums()
{ {
get_json=$(curl -s --compressed "$instance_point/albums?ordering=$ordering&playable=true&page=$1" 2>&1 | tee preload) get_json=$(default_curl_opt "$instance_point/albums?ordering=$ordering&playable=true&page=$1" 2>&1 | tee preload)
} }
funkwhale_menu_albums() funkwhale_menu_albums()
@ -51,7 +67,7 @@ funkwhale_menu_albums_tracks()
level=1 level=1
fi fi
tracks_a=$(curl -s --compressed "$instance_point/tracks?ordering=$ordering&playable=true&album=$1&page_size=50") tracks_a=$(default_curl_opt "$instance_point/tracks?ordering=$ordering&playable=true&album=$1&page_size=50")
while [ $sub2_menu -eq $level ]; do while [ $sub2_menu -eq $level ]; do
@ -69,27 +85,36 @@ funkwhale_menu_albums_tracks()
"Listen all") "Listen all")
echo > playlist.m3u8 echo > playlist.m3u8
chmod 600 playlist.m3u8
for i in $playlist; do for i in $playlist; do
if [ -n "$auth" ]; then
echo "https://$instance$i?token=$listen_token\n" >> playlist.m3u8
else
echo "https://$instance$i\n" >> playlist.m3u8 echo "https://$instance$i\n" >> playlist.m3u8
fi
done done
$default_player_command playlist.m3u8 ;; $default_player_command playlist.m3u8 ;;
*) *)
index=$(echo $menu_album_tracks_choice | cut -f 1 -d:) index=$(echo $menu_album_tracks_choice | cut -f 1 -d:)
play_track=$(echo $tracks_a | jj results.$index.listen_url) play_track=$(echo $tracks_a | jj results.$index.listen_url)
$default_player_command "https://$instance$play_track" ;; if [ -n "$auth" ]; then
$default_player_command "https://$instance$play_track?token=$listen_token"
else
$default_player_command "https://$instance$play_track"
fi ;;
esac esac
done done
} }
funkwhale_api_get_artists() funkwhale_api_get_artists()
{ {
curl -s --compressed "$instance_point/artists?ordering=-creation_date&playable=true&page=$1" default_curl_opt "$instance_point/artists?ordering=-creation_date&playable=true&page=$1"
} }
funkwhale_api_get_artist() funkwhale_api_get_artist()
{ {
curl -s --compressed "$instance_point/artists/$1" default_curl_opt "$instance_point/artists/$1"
} }
funkwhale_menu_artists() funkwhale_menu_artists()
@ -137,7 +162,7 @@ funkwhale_menu_albums_artist()
funkwhale_api_get_tracks_from_channel() funkwhale_api_get_tracks_from_channel()
{ {
sub2_menu=1 sub2_menu=1
track_list=$(curl -s --compressed "$instance_point/tracks?channel=$1&playable=true&include_channels=true") track_list=$(default_curl_opt "$instance_point/tracks?channel=$1&playable=true&include_channels=true")
echo "Loaded $(echo $track_list | jj count) podcasts" echo "Loaded $(echo $track_list | jj count) podcasts"
while [ $sub2_menu -eq 1 ]; do while [ $sub2_menu -eq 1 ]; do
@ -149,7 +174,11 @@ funkwhale_api_get_tracks_from_channel()
*) *)
index=$(echo $menu_podcast_choice | cut -f 1 -d:) index=$(echo $menu_podcast_choice | cut -f 1 -d:)
play_track=$(echo $track_list | jj results.$index.listen_url) play_track=$(echo $track_list | jj results.$index.listen_url)
$default_player_command "https://$instance$play_track" ;; if [ -n "$auth" ]; then
$default_player_command "https://$instance$play_track&token=$listen_token"
else
$default_player_command "https://$instance$play_track"
fi ;;
esac esac
done done
} }
@ -158,7 +187,7 @@ funkwhale_get_podcasts_artists()
{ {
sub_menu=1 sub_menu=1
echo 'Loading podcast artists...' echo 'Loading podcast artists...'
curl -s --compressed --output preload "$instance_point/artists?ordering=-creation_date&playable=true&include_channels=true&content_category=podcast&page=$1" default_curl_opt "$instance_point/artists?ordering=-creation_date&playable=true&include_channels=true&content_category=podcast&page=$1" | tee preload 1>> /dev/null
while [ $sub_menu -eq 1 ]; do while [ $sub_menu -eq 1 ]; do
count_artists=$(jj -i preload count) count_artists=$(jj -i preload count)
echo "$count_artists avalaible" echo "$count_artists avalaible"
@ -184,6 +213,7 @@ load_tracks_to_playlist()
{ {
echo "Loading page $1 ..." echo "Loading page $1 ..."
echo '#EXTM3U\n' > playlist.m3u8 echo '#EXTM3U\n' > playlist.m3u8
chmod 600 playlist.m3u8
counter_titles=0 counter_titles=0
for i in $(funkwhale_api_get_tracks $1); do for i in $(funkwhale_api_get_tracks $1); do
title=$(jj -i preload results."$counter_titles".title) title=$(jj -i preload results."$counter_titles".title)
@ -191,7 +221,11 @@ load_tracks_to_playlist()
duration=$(jj -i preload results."$counter_titles".uploads.0.duration) duration=$(jj -i preload results."$counter_titles".uploads.0.duration)
echo "#EXTINF:$duration, $artist_name - $title" >> playlist.m3u8 echo "#EXTINF:$duration, $artist_name - $title" >> playlist.m3u8
counter_titles=$(expr $counter_titles + 1) 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 echo "https://$instance$i\n" >> playlist.m3u8
fi
done done
count_tracks_results=$(jj -i preload 'results.#') count_tracks_results=$(jj -i preload 'results.#')
if [ -z $count_tracks_results ] || [ $count_tracks_results -eq 0 ]; then if [ -z $count_tracks_results ] || [ $count_tracks_results -eq 0 ]; then