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-04-02 22:44:45 +03:00
|
|
|
|
instance_hist='instance.hist'
|
2022-07-17 13:57:38 +03:00
|
|
|
|
ordering='-creation_date'
|
2022-04-01 01:12:45 +03:00
|
|
|
|
default_player_command='mpv --no-vid --no-ytdl --network-timeout=30'
|
2022-04-02 02:26:22 +03:00
|
|
|
|
instance_point="https://$instance/api/v1"
|
2022-04-18 11:51:05 +03:00
|
|
|
|
download_selected_track=$(jj -i config.json download_selected_track)
|
2022-04-07 22:05:49 +03:00
|
|
|
|
|
|
|
|
|
touch .auth.json
|
|
|
|
|
chmod 600 .auth.json
|
2022-04-29 22:38:00 +03:00
|
|
|
|
|
|
|
|
|
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
|
2022-07-18 01:44:39 +03:00
|
|
|
|
listen_token=''
|
|
|
|
|
export listen_token
|
2022-04-29 22:38:00 +03:00
|
|
|
|
default_curl_opt()
|
|
|
|
|
{
|
|
|
|
|
curl -s --compressed "$@"
|
|
|
|
|
}
|
|
|
|
|
fi
|
|
|
|
|
export default_curl_opt
|
|
|
|
|
}
|
|
|
|
|
make_login
|
2022-04-17 02:11:07 +03:00
|
|
|
|
|
|
|
|
|
delq()
|
|
|
|
|
{
|
|
|
|
|
sed 's/"//g'
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-30 02:47:33 +03:00
|
|
|
|
funkwhale_api_check_api_limits()
|
|
|
|
|
{
|
2022-04-07 22:05:49 +03:00
|
|
|
|
default_curl_opt "$instance_point/rate-limit/" | jj -p
|
2022-03-30 02:47:33 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-15 12:32:53 +03:00
|
|
|
|
funkwhale_api_tags()
|
|
|
|
|
{
|
|
|
|
|
mkdir -p tags_db
|
2022-04-15 22:11:29 +03:00
|
|
|
|
if [ ! -f "tags_db/tags_$instance.gz" ]; then
|
2022-04-15 12:32:53 +03:00
|
|
|
|
tagsload=$(default_curl_opt "$instance_point/tags?playable=true")
|
2022-04-18 17:11:00 +03:00
|
|
|
|
pageindex=$(echo "$tagsload" | jj next)
|
2022-04-29 22:38:00 +03:00
|
|
|
|
echo "$tagsload" | jj -l 'results.#.name' | delq | gzip > tags_db/tags_"$instance".gz
|
2022-04-15 12:32:53 +03:00
|
|
|
|
clear
|
|
|
|
|
while [ -n "$pageindex" ]; do
|
2022-04-29 22:38:00 +03:00
|
|
|
|
echo "Loading... +$(echo "$tagsload" | jj 'results.#') tags"
|
|
|
|
|
echo "$tagsload" | jj -l 'results.#.name' | delq | gzip >> tags_db/tags_"$instance".gz
|
2022-04-18 17:11:00 +03:00
|
|
|
|
pageindex=$(echo "$tagsload" | jj next)
|
2022-04-15 12:32:53 +03:00
|
|
|
|
tagsload=$(default_curl_opt "$pageindex")
|
|
|
|
|
sleep 1
|
|
|
|
|
done
|
|
|
|
|
fi
|
2022-04-15 22:11:29 +03:00
|
|
|
|
|
2022-04-18 17:11:00 +03:00
|
|
|
|
tag=$(cat tags_db/tags_"$instance".gz | gzip -d | fzy)
|
2022-04-15 12:32:53 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-03-30 02:47:33 +03:00
|
|
|
|
funkwhale_api_get_tracks()
|
|
|
|
|
{
|
2022-04-10 22:55:20 +03:00
|
|
|
|
default_curl_opt \
|
2022-07-17 13:57:38 +03:00
|
|
|
|
"$instance_point/tracks?ordering=$ordering&playable=true&page_size=50&page=$1&tag=$tag&artist=$2" \
|
2022-04-10 22:55:20 +03:00
|
|
|
|
2>&1 | tee preload
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-18 11:51:05 +03:00
|
|
|
|
play_or_download_selected()
|
|
|
|
|
{
|
|
|
|
|
mkdir -p music_dl
|
2022-07-18 10:59:56 +03:00
|
|
|
|
if [ "$download_selected_track" = 'true' ]; then
|
|
|
|
|
default_curl_opt --tcp-fastopen --output - --url "https://$instance$download_track&token=$listen_token" | \
|
|
|
|
|
tee "music_dl/$artist_name - $title.$download_ext" | $default_player_command -
|
2022-04-18 11:51:05 +03:00
|
|
|
|
else
|
2022-07-18 10:59:56 +03:00
|
|
|
|
$default_player_command "https://$instance$play_track?token=$listen_token"
|
2022-04-18 11:51:05 +03:00
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-10 22:55:20 +03:00
|
|
|
|
funkwhale_menu_tracks()
|
|
|
|
|
{
|
2022-04-10 23:19:22 +03:00
|
|
|
|
sub2_menu=1
|
|
|
|
|
level=1
|
2022-04-10 22:55:20 +03:00
|
|
|
|
echo 'Loading tracks...'
|
2022-04-18 17:11:00 +03:00
|
|
|
|
funkwhale_api_get_tracks "$1" "$2" 1>> /dev/null
|
2022-04-10 22:55:20 +03:00
|
|
|
|
count_tracks_results=$(jj -i preload 'results.#')
|
|
|
|
|
echo '#EXTM3U\n' > playlist.m3u8
|
|
|
|
|
chmod 600 playlist.m3u8
|
|
|
|
|
counter_titles=0
|
|
|
|
|
|
|
|
|
|
while [ $sub2_menu -eq $level ]; do
|
2022-07-18 10:59:56 +03:00
|
|
|
|
titles=$(jj -i preload -l 'results.#.title' | nl -s: -v0 -w1)
|
|
|
|
|
playlist=$(jj -i preload -l 'results.#.listen_url' | delq)
|
2022-04-10 22:55:20 +03:00
|
|
|
|
menu_album_tracks_choice=$(echo "Back\nMain menu\nListen all\n$titles" | fzy)
|
|
|
|
|
case $menu_album_tracks_choice in
|
|
|
|
|
"Back")
|
|
|
|
|
if [ $sub2_menu -eq 2 ]; then
|
|
|
|
|
sub2_menu=1
|
|
|
|
|
else
|
|
|
|
|
sub2_menu=0
|
|
|
|
|
fi ;;
|
|
|
|
|
"Main menu") sub2_menu=0 && sub_menu=0 ;;
|
|
|
|
|
|
|
|
|
|
"Listen all")
|
|
|
|
|
echo > playlist.m3u8
|
|
|
|
|
chmod 600 playlist.m3u8
|
2022-04-17 02:11:07 +03:00
|
|
|
|
tracks_for_playlist=$(jj -i preload -l 'results.#.uploads.0.listen_url' | delq)
|
2022-04-10 22:55:20 +03:00
|
|
|
|
for i in $tracks_for_playlist; do
|
|
|
|
|
title=$(jj -i preload results."$counter_titles".title)
|
|
|
|
|
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
|
|
|
|
|
counter_titles=$(expr $counter_titles + 1)
|
2022-07-18 10:59:56 +03:00
|
|
|
|
echo "https://$instance$i&token=$listen_token\n" >> playlist.m3u8
|
2022-04-10 22:55:20 +03:00
|
|
|
|
done
|
|
|
|
|
$default_player_command playlist.m3u8 ;;
|
|
|
|
|
|
|
|
|
|
*)
|
2022-04-18 17:11:00 +03:00
|
|
|
|
index=$(echo "$menu_album_tracks_choice" | cut -f 1 -d:)
|
|
|
|
|
play_track=$(jj -i preload results."$index".listen_url)
|
|
|
|
|
download_track=$(jj -i preload results."$index".uploads.0.listen_url)
|
|
|
|
|
download_ext=$(jj -i preload results."$index".uploads.0.extension)
|
|
|
|
|
title=$(jj -i preload results."$index".title)
|
|
|
|
|
artist_name=$(jj -i preload results."$index".artist.name)
|
2022-04-18 11:51:05 +03:00
|
|
|
|
play_or_download_selected
|
|
|
|
|
;;
|
2022-04-10 22:55:20 +03:00
|
|
|
|
esac
|
|
|
|
|
done
|
2022-03-30 02:47:33 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-04 02:46:47 +03:00
|
|
|
|
funkwhale_api_get_albums()
|
|
|
|
|
{
|
2022-04-07 22:05:49 +03:00
|
|
|
|
get_json=$(default_curl_opt "$instance_point/albums?ordering=$ordering&playable=true&page=$1" 2>&1 | tee preload)
|
2022-04-04 02:46:47 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
funkwhale_menu_albums()
|
|
|
|
|
{
|
|
|
|
|
echo 'Loading albums...'
|
2022-04-18 17:11:00 +03:00
|
|
|
|
funkwhale_api_get_albums "$1"
|
2022-04-04 02:46:47 +03:00
|
|
|
|
echo "Avalaible $(jj -i preload count) albums"
|
|
|
|
|
sub_menu=1
|
|
|
|
|
while [ $sub_menu -eq 1 ]; do
|
2022-04-07 03:01:48 +03:00
|
|
|
|
titles=$(jj -i preload -l 'results.#.title' | nl -s: -v0 -w1)
|
2022-04-10 16:42:35 +03:00
|
|
|
|
menu_albums_choice=$(echo "Main menu\n$titles\nNext page" | fzy)
|
2022-04-04 02:46:47 +03:00
|
|
|
|
case $menu_albums_choice in
|
|
|
|
|
"Main menu") sub_menu=0 ;;
|
2022-04-10 16:42:35 +03:00
|
|
|
|
"Next page")
|
2022-04-18 17:11:00 +03:00
|
|
|
|
page=$(expr "$page" + 1)
|
|
|
|
|
get_json=$(funkwhale_api_get_albums "$page")
|
2022-04-10 16:42:35 +03:00
|
|
|
|
;;
|
2022-04-04 02:46:47 +03:00
|
|
|
|
*)
|
2022-04-18 17:11:00 +03:00
|
|
|
|
index=$(echo "$menu_albums_choice" | cut -f 1 -d:)
|
|
|
|
|
album_id=$(jj -i preload results."$index".id)
|
|
|
|
|
funkwhale_menu_albums_tracks "$album_id"
|
2022-04-04 02:46:47 +03:00
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
funkwhale_menu_albums_tracks()
|
|
|
|
|
{
|
2022-04-07 15:25:33 +03:00
|
|
|
|
if [ $sub2_menu -eq 1 ]; then
|
|
|
|
|
sub2_menu=2
|
|
|
|
|
level=2
|
|
|
|
|
else
|
|
|
|
|
sub2_menu=1
|
|
|
|
|
level=1
|
|
|
|
|
fi
|
|
|
|
|
|
2022-04-07 22:05:49 +03:00
|
|
|
|
tracks_a=$(default_curl_opt "$instance_point/tracks?ordering=$ordering&playable=true&album=$1&page_size=50")
|
2022-04-04 02:46:47 +03:00
|
|
|
|
|
|
|
|
|
|
2022-04-07 15:25:33 +03:00
|
|
|
|
while [ $sub2_menu -eq $level ]; do
|
2022-04-29 22:38:00 +03:00
|
|
|
|
titles=$(echo "$tracks_a" | jj -l 'results.#.title' | nl -s: -v0 -w1)
|
|
|
|
|
playlist=$(echo "$tracks_a" | jj -l 'results.#.listen_url' | delq)
|
2022-04-04 12:06:37 +03:00
|
|
|
|
menu_album_tracks_choice=$(echo "Back\nMain menu\nListen all\n$titles" | fzy)
|
2022-04-04 02:46:47 +03:00
|
|
|
|
case $menu_album_tracks_choice in
|
2022-04-07 15:25:33 +03:00
|
|
|
|
"Back")
|
|
|
|
|
if [ $sub2_menu -eq 2 ]; then
|
|
|
|
|
sub2_menu=1
|
|
|
|
|
else
|
|
|
|
|
sub2_menu=0
|
|
|
|
|
fi ;;
|
2022-04-04 12:06:37 +03:00
|
|
|
|
"Main menu") sub2_menu=0 && sub_menu=0 ;;
|
|
|
|
|
|
|
|
|
|
"Listen all")
|
|
|
|
|
echo > playlist.m3u8
|
2022-04-07 22:05:49 +03:00
|
|
|
|
chmod 600 playlist.m3u8
|
2022-04-04 12:06:37 +03:00
|
|
|
|
for i in $playlist; do
|
2022-04-07 22:05:49 +03:00
|
|
|
|
if [ -n "$auth" ]; then
|
|
|
|
|
echo "https://$instance$i?token=$listen_token\n" >> playlist.m3u8
|
|
|
|
|
else
|
|
|
|
|
echo "https://$instance$i\n" >> playlist.m3u8
|
|
|
|
|
fi
|
2022-04-04 12:06:37 +03:00
|
|
|
|
done
|
|
|
|
|
$default_player_command playlist.m3u8 ;;
|
|
|
|
|
|
2022-04-04 02:46:47 +03:00
|
|
|
|
*)
|
2022-04-18 17:11:00 +03:00
|
|
|
|
index=$(echo "$menu_album_tracks_choice" | cut -f 1 -d:)
|
|
|
|
|
play_track=$(echo "$tracks_a" | jj results."$index".listen_url)
|
2022-04-07 22:05:49 +03:00
|
|
|
|
if [ -n "$auth" ]; then
|
|
|
|
|
$default_player_command "https://$instance$play_track?token=$listen_token"
|
|
|
|
|
else
|
|
|
|
|
$default_player_command "https://$instance$play_track"
|
|
|
|
|
fi ;;
|
2022-04-04 02:46:47 +03:00
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-07 15:25:33 +03:00
|
|
|
|
funkwhale_api_get_artists()
|
|
|
|
|
{
|
2022-04-07 22:05:49 +03:00
|
|
|
|
default_curl_opt "$instance_point/artists?ordering=-creation_date&playable=true&page=$1"
|
2022-04-07 15:25:33 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
funkwhale_api_get_artist()
|
|
|
|
|
{
|
2022-04-07 22:05:49 +03:00
|
|
|
|
default_curl_opt "$instance_point/artists/$1"
|
2022-04-07 15:25:33 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
funkwhale_menu_artists()
|
|
|
|
|
{
|
|
|
|
|
echo 'Loading artists...'
|
2022-04-18 17:11:00 +03:00
|
|
|
|
get_json=$(funkwhale_api_get_artists "$1")
|
|
|
|
|
echo "Avalaible $(echo "$get_json" | jj count) artists"
|
2022-04-07 15:25:33 +03:00
|
|
|
|
sub_menu=1
|
|
|
|
|
while [ $sub_menu -eq 1 ]; do
|
2022-04-18 17:11:00 +03:00
|
|
|
|
names=$(echo "$get_json" | jj -l 'results.#.name' | nl -s: -v0 -w1)
|
2022-04-10 16:42:35 +03:00
|
|
|
|
menu_artists_choice=$(echo "Main menu\n$names\nNext page" | fzy)
|
2022-04-07 15:25:33 +03:00
|
|
|
|
case $menu_artists_choice in
|
|
|
|
|
"Main menu") sub_menu=0 ;;
|
2022-04-10 16:42:35 +03:00
|
|
|
|
"Next page")
|
2022-04-18 17:11:00 +03:00
|
|
|
|
page=$(expr "$page" + 1)
|
|
|
|
|
get_json=$(funkwhale_api_get_artists "$page")
|
2022-04-10 16:42:35 +03:00
|
|
|
|
;;
|
2022-04-07 15:25:33 +03:00
|
|
|
|
*)
|
2022-04-18 17:11:00 +03:00
|
|
|
|
index=$(echo "$menu_artists_choice" | cut -f 1 -d:)
|
|
|
|
|
artist_id=$(echo "$get_json" | jj results."$index".id)
|
|
|
|
|
funkwhale_menu_albums_artist "$artist_id" ;;
|
2022-04-07 15:25:33 +03:00
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
funkwhale_menu_albums_artist()
|
|
|
|
|
{
|
|
|
|
|
echo 'Loading albums...'
|
2022-04-18 17:11:00 +03:00
|
|
|
|
albums_a=$(funkwhale_api_get_artist "$1")
|
2022-04-07 15:25:33 +03:00
|
|
|
|
standart_albums='albums.#.title'
|
2022-04-18 17:11:00 +03:00
|
|
|
|
count_albums=$(echo "$albums_a" | jj albums.\#)
|
|
|
|
|
if [ "$count_albums" -eq 0 ]; then
|
2022-04-10 22:55:20 +03:00
|
|
|
|
echo 'failed: no albums, getting tracks...'
|
|
|
|
|
sub2_menu=1
|
2022-04-18 17:11:00 +03:00
|
|
|
|
funkwhale_menu_tracks 1 "$1"
|
2022-04-10 22:55:20 +03:00
|
|
|
|
return 1
|
|
|
|
|
fi
|
2022-04-07 15:25:33 +03:00
|
|
|
|
index_type='albums'
|
2022-04-10 22:55:20 +03:00
|
|
|
|
echo "Avalaible $count_albums albums"
|
2022-04-07 15:25:33 +03:00
|
|
|
|
sub2_menu=1
|
|
|
|
|
while [ $sub2_menu -eq 1 ]; do
|
2022-04-18 17:11:00 +03:00
|
|
|
|
titles=$(echo "$albums_a" | jj -l $standart_albums | nl -s: -v0 -w1)
|
2022-04-07 15:25:33 +03:00
|
|
|
|
menu_albums_choice=$(echo "Back\nMain menu\n$titles" | fzy)
|
|
|
|
|
case $menu_albums_choice in
|
|
|
|
|
"Main menu") sub2_menu=0 && sub_menu=0 ;;
|
|
|
|
|
"Back") sub2_menu=0 ;;
|
|
|
|
|
*)
|
2022-04-18 17:11:00 +03:00
|
|
|
|
index=$(echo "$menu_albums_choice" | cut -f 1 -d:)
|
|
|
|
|
album_id=$(echo "$albums_a" | jj $index_type."$index".id)
|
|
|
|
|
funkwhale_menu_albums_tracks "$album_id"
|
2022-04-07 15:25:33 +03:00
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-31 19:23:14 +03:00
|
|
|
|
funkwhale_api_get_tracks_from_channel()
|
2022-04-04 00:58:18 +03:00
|
|
|
|
{
|
|
|
|
|
sub2_menu=1
|
2022-04-07 22:05:49 +03:00
|
|
|
|
track_list=$(default_curl_opt "$instance_point/tracks?channel=$1&playable=true&include_channels=true")
|
2022-04-18 17:11:00 +03:00
|
|
|
|
echo "Loaded $(echo "$track_list" | jj count) podcasts"
|
2022-04-02 18:28:19 +03:00
|
|
|
|
|
2022-04-04 00:58:18 +03:00
|
|
|
|
while [ $sub2_menu -eq 1 ]; do
|
2022-04-18 17:11:00 +03:00
|
|
|
|
titles=$(echo "$track_list" | jj -l 'results.#.title' | nl -s: -v0 -w1)
|
2022-04-04 01:30:33 +03:00
|
|
|
|
menu_podcast_choice=$(echo "Back\nMain menu\n$titles" | fzy)
|
2022-04-04 00:58:18 +03:00
|
|
|
|
case $menu_podcast_choice in
|
|
|
|
|
"Back") sub2_menu=0 ;;
|
2022-04-04 01:30:33 +03:00
|
|
|
|
"Main menu") sub2_menu=0 && sub_menu=0 ;;
|
2022-04-04 00:58:18 +03:00
|
|
|
|
*)
|
2022-04-18 17:11:00 +03:00
|
|
|
|
index=$(echo "$menu_podcast_choice" | cut -f 1 -d:)
|
|
|
|
|
play_track=$(echo "$track_list" | jj results."$index".listen_url)
|
2022-07-18 10:59:56 +03:00
|
|
|
|
$default_player_command "https://$instance$play_track&token=$listen_token"
|
|
|
|
|
;;
|
2022-04-02 18:50:24 +03:00
|
|
|
|
esac
|
|
|
|
|
done
|
2022-03-31 19:23:14 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
funkwhale_get_podcasts_artists()
|
|
|
|
|
{
|
2022-04-04 00:58:18 +03:00
|
|
|
|
sub_menu=1
|
2022-03-31 19:23:14 +03:00
|
|
|
|
echo 'Loading podcast artists...'
|
2022-04-07 22:05:49 +03:00
|
|
|
|
default_curl_opt "$instance_point/artists?ordering=-creation_date&playable=true&include_channels=true&content_category=podcast&page=$1" | tee preload 1>> /dev/null
|
2022-04-04 00:58:18 +03:00
|
|
|
|
while [ $sub_menu -eq 1 ]; do
|
|
|
|
|
count_artists=$(jj -i preload count)
|
|
|
|
|
echo "$count_artists avalaible"
|
2022-04-29 22:38:00 +03:00
|
|
|
|
podcast_names=$(jj -l -i preload 'results.#.name' | nl -s: -v0 -w1)
|
2022-04-04 00:58:18 +03:00
|
|
|
|
menu_podcast_choice=$(echo "Main menu\n$podcast_names" | fzy)
|
|
|
|
|
case $menu_podcast_choice in
|
|
|
|
|
"Main menu") sub_menu=0 ;;
|
|
|
|
|
|
|
|
|
|
*)
|
2022-04-18 17:11:00 +03:00
|
|
|
|
index=$(echo "$menu_podcast_choice" | cut -f 1 -d:)
|
|
|
|
|
channel_uuid=$(jj -i preload results."$index".channel.uuid)
|
2022-04-03 17:57:32 +03:00
|
|
|
|
|
2022-04-18 17:11:00 +03:00
|
|
|
|
if [ -z "$channel_uuid" ]; then
|
2022-04-04 00:58:18 +03:00
|
|
|
|
echo 'Error when loading podcast'
|
|
|
|
|
else
|
2022-04-18 17:11:00 +03:00
|
|
|
|
funkwhale_api_get_tracks_from_channel "$channel_uuid"
|
2022-04-04 00:58:18 +03:00
|
|
|
|
fi ;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
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-07-18 01:44:39 +03:00
|
|
|
|
export count_all_tracks=$(jj -i preload -l count)
|
2022-04-18 17:11:00 +03:00
|
|
|
|
if [ -z "$count_all_tracks" ]; then
|
2022-04-02 03:01:25 +03:00
|
|
|
|
echo 'Error: Connection error or API limit expired'
|
2022-04-18 17:11:00 +03:00
|
|
|
|
elif [ "$count_all_tracks" -eq 0 ]; then
|
2022-04-02 03:01:25 +03:00
|
|
|
|
echo 'Error: No tracks'
|
|
|
|
|
else
|
|
|
|
|
echo "Tracks avalaible on $instance: $count_all_tracks\n"
|
|
|
|
|
fi
|
2022-03-30 19:58:30 +03:00
|
|
|
|
}
|
2022-07-18 01:44:39 +03:00
|
|
|
|
get_all_avalaible_count_tracks
|
2022-03-30 19:58:30 +03:00
|
|
|
|
|
2022-07-17 13:57:38 +03:00
|
|
|
|
funkwhale_pseudofs_load()
|
|
|
|
|
{
|
|
|
|
|
# Создаёт дерево каталогов из id исполнителей
|
|
|
|
|
# В каждый каталог складывает плейлист с URL треков для прослушивания\закачки
|
|
|
|
|
# tree:
|
|
|
|
|
# [fwfs_instance.url]
|
|
|
|
|
# |
|
|
|
|
|
# | -- [id исполнителя]
|
|
|
|
|
# | |
|
|
|
|
|
# | | -- плейлист с треками
|
|
|
|
|
# | ...
|
2022-07-18 01:44:39 +03:00
|
|
|
|
echo "Processing..."
|
2022-07-17 13:57:38 +03:00
|
|
|
|
mkdir -p "fwfs_$instance"
|
|
|
|
|
counter_page=1
|
2022-07-18 01:44:39 +03:00
|
|
|
|
tracks_counter_watch=0
|
|
|
|
|
skip_count=0
|
2022-07-17 13:57:38 +03:00
|
|
|
|
while true; do
|
|
|
|
|
tracks=$(funkwhale_api_get_tracks $counter_page)
|
|
|
|
|
next_check=$(echo "$tracks" | jj next)
|
|
|
|
|
for idartist in $(echo "$tracks" | jj -l 'results.#.artist.id' | delq | sort -u); do
|
|
|
|
|
mkdir -p "fwfs_$instance/$idartist"
|
2022-07-18 01:44:39 +03:00
|
|
|
|
if [ ! -f "fwfs_$instance/$idartist/playlist.m3u8" ]; then
|
|
|
|
|
echo '#EXTM3U' > "fwfs_$instance/$idartist/playlist.m3u8"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
get_tracks_uuid_by_artist_id=$(echo "$tracks" | jj -l "results.#[artist.id=$idartist]#.uploads.0.uuid" | delq)
|
|
|
|
|
for track in $get_tracks_uuid_by_artist_id; do
|
2022-07-18 10:51:37 +03:00
|
|
|
|
fid_url=$(echo "$tracks" | jj "results.#[uploads.0.uuid="$track"].fid")
|
2022-07-18 01:44:39 +03:00
|
|
|
|
artist_name=$(echo "$tracks" | jj "results.#[uploads.0.uuid="$track"].artist.name")
|
|
|
|
|
album_name=$(echo "$tracks" | jj "results.#[uploads.0.uuid="$track"].album.title")
|
|
|
|
|
track_name=$(echo "$tracks" | jj "results.#[uploads.0.uuid="$track"].title")
|
|
|
|
|
extension=$(echo "$tracks" | jj "results.#[uploads.0.uuid="$track"].uploads.0.extension")
|
|
|
|
|
duration=$(echo "$tracks" | jj "results.#[uploads.0.uuid="$track"].uploads.0.duration")
|
|
|
|
|
track_filename=$(echo "$artist_name - $album_name - $track_name.$extension")
|
|
|
|
|
listen_url=$(echo "$tracks" | jj "results.#[uploads.0.uuid="$track"].uploads.0.listen_url")
|
|
|
|
|
full_url=$(echo $listen_url | delq | sed "s/^/https:\/\/$instance/ ; s/$/\&token=$listen_token\&to=ogg/")
|
|
|
|
|
echo "adding "$idartist"_$track_filename"
|
|
|
|
|
exists_test=$(grep -F ""$idartist"_$track_filename" "fwfs_$instance/$idartist/playlist.m3u8")
|
|
|
|
|
if [ -n "$exists_test" ]; then
|
|
|
|
|
skip_count=$(expr $skip_count + 1)
|
|
|
|
|
else
|
2022-07-18 10:51:37 +03:00
|
|
|
|
echo "#EXTINF:$duration, "$idartist"_$track_filename\n#$fid_url\n$full_url\n" >> "fwfs_$instance/$idartist/playlist.m3u8"
|
2022-07-18 01:44:39 +03:00
|
|
|
|
fi
|
|
|
|
|
tracks_counter_watch=$(expr $tracks_counter_watch + 1)
|
|
|
|
|
echo "current: $tracks_counter_watch skipped: $skip_count total: $count_all_tracks"
|
|
|
|
|
done
|
|
|
|
|
chmod 600 "fwfs_$instance/$idartist/playlist.m3u8"
|
2022-07-17 13:57:38 +03:00
|
|
|
|
done
|
|
|
|
|
if [ -z "$next_check" ]; then
|
|
|
|
|
break
|
|
|
|
|
fi
|
|
|
|
|
counter_page=$(expr $counter_page + 1)
|
2022-07-18 01:44:39 +03:00
|
|
|
|
echo "page $counter_page"
|
2022-07-17 13:57:38 +03:00
|
|
|
|
|
|
|
|
|
done
|
|
|
|
|
}
|
2022-03-30 15:04:30 +03:00
|
|
|
|
|
2022-07-18 02:10:58 +03:00
|
|
|
|
funkwhale_pseudofs_transcode_switch()
|
|
|
|
|
{
|
|
|
|
|
echo "Transcode to"
|
|
|
|
|
transcode_ch=$(echo "none\nogg\nmp3" | fzy)
|
|
|
|
|
if [ "$transcode_ch" = 'none' ]; then
|
|
|
|
|
find "fwfs_$instance" -type f -exec sed -i 's/to=.*/to=/' {} +
|
|
|
|
|
else
|
|
|
|
|
find "fwfs_$instance" -type f -exec sed -i "s/to=.*/to=$transcode_ch/" {} +
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-10 23:19:22 +03:00
|
|
|
|
trackspls='Tracks'
|
2022-04-04 02:46:47 +03:00
|
|
|
|
albumsmenu='Albums'
|
2022-04-07 15:25:33 +03:00
|
|
|
|
artistmenu='Artists'
|
2022-03-31 19:23:14 +03:00
|
|
|
|
podcasts='Podcasts'
|
2022-03-30 19:58:30 +03:00
|
|
|
|
changepod='Switch instance'
|
2022-07-18 01:44:39 +03:00
|
|
|
|
load_pseudofs='Create artists local playlist'
|
2022-03-30 02:47:33 +03:00
|
|
|
|
checkapilimits='Check API limits (debug)'
|
|
|
|
|
Exit='Exit'
|
|
|
|
|
|
|
|
|
|
while true; do
|
2022-07-18 01:44:39 +03:00
|
|
|
|
choice=$(echo "$trackspls\n$albumsmenu\n$artistmenu\n$podcasts\n$changepod\n$load_pseudofs\n$checkapilimits\n$Exit" | fzy)
|
2022-03-30 02:47:33 +03:00
|
|
|
|
|
2022-04-02 03:16:31 +03:00
|
|
|
|
case "$choice" in
|
2022-04-10 23:19:22 +03:00
|
|
|
|
"$trackspls")
|
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:'
|
2022-04-15 12:32:53 +03:00
|
|
|
|
|
2022-04-17 02:11:07 +03:00
|
|
|
|
tag=$(echo "TagOFF\nTags from instance\n$(jj -l -i config.json tags | delq)" | fzy)
|
2022-04-15 12:32:53 +03:00
|
|
|
|
case $tag in
|
|
|
|
|
"TagOFF") tag= ;;
|
|
|
|
|
"Tags from instance") funkwhale_api_tags ;;
|
|
|
|
|
esac
|
2022-03-31 21:19:08 +03:00
|
|
|
|
export tag
|
2022-03-30 02:47:33 +03:00
|
|
|
|
echo 'Enter page number: '
|
|
|
|
|
read page
|
2022-04-18 17:11:00 +03:00
|
|
|
|
funkwhale_menu_tracks "$page"
|
2022-04-15 12:32:53 +03:00
|
|
|
|
tag=
|
|
|
|
|
;;
|
2022-04-02 03:16:31 +03:00
|
|
|
|
|
2022-04-04 02:46:47 +03:00
|
|
|
|
"$albumsmenu")
|
|
|
|
|
echo 'Enter page number: '
|
|
|
|
|
read page
|
2022-04-18 17:11:00 +03:00
|
|
|
|
funkwhale_menu_albums "$page" ;;
|
2022-04-07 15:25:33 +03:00
|
|
|
|
|
|
|
|
|
"$artistmenu")
|
|
|
|
|
echo 'Enter page number: '
|
|
|
|
|
read page
|
2022-04-18 17:11:00 +03:00
|
|
|
|
funkwhale_menu_artists "$page" ;;
|
2022-04-02 03:16:31 +03:00
|
|
|
|
|
|
|
|
|
"$podcasts")
|
2022-03-31 19:23:14 +03:00
|
|
|
|
echo 'Enter page number: '
|
|
|
|
|
read page
|
2022-04-18 17:11:00 +03:00
|
|
|
|
funkwhale_get_podcasts_artists "$page" ;;
|
2022-04-02 03:16:31 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"$changepod")
|
2022-04-02 22:44:45 +03:00
|
|
|
|
empty=0
|
|
|
|
|
case $(echo 'Recently used\nChoice from list\nManual input' | fzy) in
|
|
|
|
|
"Recently used")
|
|
|
|
|
if [ -s $instance_hist ]; then
|
|
|
|
|
touch $instance_hist && instance=$(cat $instance_hist | fzy)
|
|
|
|
|
else
|
|
|
|
|
echo 'No recently used instances...'
|
|
|
|
|
empty=1
|
|
|
|
|
fi ;;
|
|
|
|
|
|
2022-04-17 02:11:07 +03:00
|
|
|
|
"Choice from list") instance=$(jj -l -i config.json public_list_instances | delq | fzy) ;;
|
2022-04-02 22:44:45 +03:00
|
|
|
|
|
|
|
|
|
"Manual input") echo "Type instance (ex. $instance):" && read instance ;;
|
|
|
|
|
esac
|
|
|
|
|
if [ $empty -eq 0 ]; then
|
2022-04-18 17:11:00 +03:00
|
|
|
|
echo "$instance" >> $instance_hist
|
2022-04-02 22:44:45 +03:00
|
|
|
|
cat $instance_hist | sort | uniq | tee $instance_hist 1>>/dev/null
|
2022-04-29 22:38:00 +03:00
|
|
|
|
instance_point="https://$instance/api/v1"
|
2022-04-02 22:44:45 +03:00
|
|
|
|
conf_instance_state=$(echo 'Permanent\nTemporaly' | fzy)
|
|
|
|
|
if [ "$conf_instance_state" = 'Permanent' ]; then
|
2022-04-18 17:11:00 +03:00
|
|
|
|
jj -i config.json instance -v "$instance" -o config.json
|
2022-04-02 22:44:45 +03:00
|
|
|
|
else
|
|
|
|
|
echo ''
|
|
|
|
|
fi
|
|
|
|
|
clear
|
2022-04-29 22:38:00 +03:00
|
|
|
|
make_login
|
2022-04-02 22:44:45 +03:00
|
|
|
|
get_all_avalaible_count_tracks
|
|
|
|
|
fi ;;
|
2022-04-02 03:16:31 +03:00
|
|
|
|
|
2022-07-18 01:44:39 +03:00
|
|
|
|
"$load_pseudofs")
|
|
|
|
|
funkwhale_pseudofs_load ;; # beta
|
|
|
|
|
|
2022-04-02 03:16:31 +03:00
|
|
|
|
|
|
|
|
|
"$checkapilimits")
|
|
|
|
|
funkwhale_api_check_api_limits | more ;;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"$Exit")
|
|
|
|
|
exit 0 ;;
|
|
|
|
|
esac
|
2022-03-30 02:47:33 +03:00
|
|
|
|
done
|