mirror of
https://gitea.phreedom.club/localhost_frssoft/funkwlmpv
synced 2024-11-22 21:49:19 +02:00
autopep8 fixes
This commit is contained in:
parent
6c5113abcc
commit
86bbdcf0ea
|
@ -10,13 +10,16 @@ from src.fw_playlists import list_playlists
|
||||||
from src.fw_fav_tracks import list_favorites_tracks
|
from src.fw_fav_tracks import list_favorites_tracks
|
||||||
import src.settings as settings
|
import src.settings as settings
|
||||||
import src.mpv_control
|
import src.mpv_control
|
||||||
import json, sys, time
|
import json
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
from shlex import quote
|
from shlex import quote
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from pyfzf.pyfzf import FzfPrompt
|
from pyfzf.pyfzf import FzfPrompt
|
||||||
|
|
||||||
fzf = FzfPrompt()
|
fzf = FzfPrompt()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
@ -78,7 +81,8 @@ def main():
|
||||||
conf = json.loads(f.read())
|
conf = json.loads(f.read())
|
||||||
public_server_list_instances = settings.get_new_funkwhale_servers()
|
public_server_list_instances = settings.get_new_funkwhale_servers()
|
||||||
new_ins_count = len(settings.get_new_funkwhale_servers())
|
new_ins_count = len(settings.get_new_funkwhale_servers())
|
||||||
list_instances = conf.get('public_list_instances') + public_server_list_instances
|
list_instances = conf.get(
|
||||||
|
'public_list_instances') + public_server_list_instances
|
||||||
instance = fzf.prompt(list_instances,
|
instance = fzf.prompt(list_instances,
|
||||||
'--header='+quote(f'Select instance\nServer instances: +{new_ins_count}'))[0]
|
'--header='+quote(f'Select instance\nServer instances: +{new_ins_count}'))[0]
|
||||||
current_instance.select_instance(instance)
|
current_instance.select_instance(instance)
|
||||||
|
@ -106,8 +110,8 @@ Insert token from "Access token" here''')
|
||||||
print(support_message)
|
print(support_message)
|
||||||
input()
|
input()
|
||||||
if selected == 'Player':
|
if selected == 'Player':
|
||||||
src.mpv_control.player_menu(storage=src.mpv_control.player_fw_storage.storage)
|
src.mpv_control.player_menu(
|
||||||
|
storage=src.mpv_control.player_fw_storage.storage)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -7,6 +7,7 @@ from loguru import logger
|
||||||
|
|
||||||
fzf = FzfPrompt()
|
fzf = FzfPrompt()
|
||||||
|
|
||||||
|
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def list_albums(albums=None, pg=None, search=None, artist=None, include_channels=None, refresh=False):
|
def list_albums(albums=None, pg=None, search=None, artist=None, include_channels=None, refresh=False):
|
||||||
show_artist_name_in_albums = get_config('show_artist_name_in_albums')
|
show_artist_name_in_albums = get_config('show_artist_name_in_albums')
|
||||||
|
@ -14,7 +15,8 @@ def list_albums(albums=None, pg=None, search=None, artist=None, include_channels
|
||||||
albums_prev = None
|
albums_prev = None
|
||||||
play_artist_albums = False
|
play_artist_albums = False
|
||||||
if not albums:
|
if not albums:
|
||||||
albums = get_albums(q=search, artist=artist, include_channels=include_channels, refresh=refresh, pg=pg)
|
albums = get_albums(q=search, artist=artist,
|
||||||
|
include_channels=include_channels, refresh=refresh, pg=pg)
|
||||||
albums_next = albums.get('next')
|
albums_next = albums.get('next')
|
||||||
albums_prev = albums.get('previous')
|
albums_prev = albums.get('previous')
|
||||||
albums_results = albums.get('results')
|
albums_results = albums.get('results')
|
||||||
|
|
145
src/fw_api.py
145
src/fw_api.py
|
@ -1,6 +1,8 @@
|
||||||
from src.mpv_control import set_http_header
|
from src.mpv_control import set_http_header
|
||||||
from src.settings import get_config
|
from src.settings import get_config
|
||||||
import requests, json, time
|
import requests
|
||||||
|
import json
|
||||||
|
import time
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
import os
|
import os
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
@ -38,13 +40,13 @@ class current_instance:
|
||||||
auth = json.loads(f.read())
|
auth = json.loads(f.read())
|
||||||
new_token = auth.get(current_instance.instance)
|
new_token = auth.get(current_instance.instance)
|
||||||
current_instance.s.headers.update({"Authorization": None,
|
current_instance.s.headers.update({"Authorization": None,
|
||||||
"Accept-encoding": 'gzip'})
|
"Accept-encoding": 'gzip'})
|
||||||
set_http_header()
|
set_http_header()
|
||||||
if new_token:
|
if new_token:
|
||||||
s.get(f'https://{current_instance.instance}')
|
s.get(f'https://{current_instance.instance}')
|
||||||
s.headers.update({
|
s.headers.update({
|
||||||
"Authorization": "Bearer " + new_token,
|
"Authorization": "Bearer " + new_token,
|
||||||
"Accept-encoding": 'gzip'
|
"Accept-encoding": 'gzip'
|
||||||
})
|
})
|
||||||
set_http_header(['Authorization: ' + 'Bearer ' + new_token])
|
set_http_header(['Authorization: ' + 'Bearer ' + new_token])
|
||||||
|
|
||||||
|
@ -57,13 +59,15 @@ if current_instance.token:
|
||||||
set_http_header(['Authorization: ' + 'Bearer ' + current_instance.token])
|
set_http_header(['Authorization: ' + 'Bearer ' + current_instance.token])
|
||||||
else:
|
else:
|
||||||
current_instance.s.headers.update({"Accept-encoding": 'gzip'})
|
current_instance.s.headers.update({"Accept-encoding": 'gzip'})
|
||||||
current_instance.s.get(f'https://{current_instance.instance}/') # Get cookies from unauthorized instance for working some functionality (radios)
|
# Get cookies from unauthorized instance for working some functionality (radios)
|
||||||
|
current_instance.s.get(f'https://{current_instance.instance}/')
|
||||||
set_http_header()
|
set_http_header()
|
||||||
|
|
||||||
|
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def get_instance_settings():
|
def get_instance_settings():
|
||||||
r = current_instance.s.get(f'https://{current_instance.instance}/api/v1/instance/settings')
|
r = current_instance.s.get(
|
||||||
|
f'https://{current_instance.instance}/api/v1/instance/settings')
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,8 +77,8 @@ def get_audio_file(track_uuid, listen_url=False, download=False,
|
||||||
if not transcoding:
|
if not transcoding:
|
||||||
to = None
|
to = None
|
||||||
params = {
|
params = {
|
||||||
"download": download,
|
"download": download,
|
||||||
"to": to
|
"to": to
|
||||||
}
|
}
|
||||||
if listen_url:
|
if listen_url:
|
||||||
url = f'https://{current_instance.instance}{track_uuid}?'
|
url = f'https://{current_instance.instance}{track_uuid}?'
|
||||||
|
@ -88,18 +92,19 @@ def get_tracks(page=None, q=None, artist=None, album=None,
|
||||||
tag=None, favourites=None, include_channels=None, pg=None):
|
tag=None, favourites=None, include_channels=None, pg=None):
|
||||||
'''This function get tracks by params'''
|
'''This function get tracks by params'''
|
||||||
params = {
|
params = {
|
||||||
'page': page,
|
'page': page,
|
||||||
'q': q,
|
'q': q,
|
||||||
'artist': artist,
|
'artist': artist,
|
||||||
'album': album,
|
'album': album,
|
||||||
'tag': tag,
|
'tag': tag,
|
||||||
'favourites': favourites,
|
'favourites': favourites,
|
||||||
'include_channels': include_channels
|
'include_channels': include_channels
|
||||||
}
|
}
|
||||||
if pg:
|
if pg:
|
||||||
r = current_instance.s.get(pg)
|
r = current_instance.s.get(pg)
|
||||||
else:
|
else:
|
||||||
r = current_instance.s.get(f'https://{current_instance.instance}/api/v1/tracks', params=params)
|
r = current_instance.s.get(
|
||||||
|
f'https://{current_instance.instance}/api/v1/tracks', params=params)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
|
@ -107,15 +112,16 @@ def get_tracks(page=None, q=None, artist=None, album=None,
|
||||||
def get_favorires_tracks(page=None, q=None, scope=None, include_channels=None, pg=None):
|
def get_favorires_tracks(page=None, q=None, scope=None, include_channels=None, pg=None):
|
||||||
'''This function get favorites tracks (not only for user)'''
|
'''This function get favorites tracks (not only for user)'''
|
||||||
params = {
|
params = {
|
||||||
'page': page,
|
'page': page,
|
||||||
'q': q,
|
'q': q,
|
||||||
'scope': scope,
|
'scope': scope,
|
||||||
'include_channels': include_channels
|
'include_channels': include_channels
|
||||||
}
|
}
|
||||||
if pg:
|
if pg:
|
||||||
r = current_instance.s.get(pg)
|
r = current_instance.s.get(pg)
|
||||||
else:
|
else:
|
||||||
r = current_instance.s.get(f'https://{current_instance.instance}/api/v1/favorites/tracks/', params=params)
|
r = current_instance.s.get(
|
||||||
|
f'https://{current_instance.instance}/api/v1/favorites/tracks/', params=params)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
|
@ -123,17 +129,18 @@ def get_favorires_tracks(page=None, q=None, scope=None, include_channels=None, p
|
||||||
def get_artists(page=None, q=None, artist=None, album=None, favourites=None, refresh=False, pg=None):
|
def get_artists(page=None, q=None, artist=None, album=None, favourites=None, refresh=False, pg=None):
|
||||||
'''This function get artists by params'''
|
'''This function get artists by params'''
|
||||||
params = {
|
params = {
|
||||||
'page': page,
|
'page': page,
|
||||||
'q': q,
|
'q': q,
|
||||||
'artist': artist,
|
'artist': artist,
|
||||||
'album': album,
|
'album': album,
|
||||||
'favourites': favourites,
|
'favourites': favourites,
|
||||||
'refresh': refresh
|
'refresh': refresh
|
||||||
}
|
}
|
||||||
if pg:
|
if pg:
|
||||||
r = current_instance.s.get(pg)
|
r = current_instance.s.get(pg)
|
||||||
else:
|
else:
|
||||||
r = current_instance.s.get(f'https://{current_instance.instance}/api/v1/artists', params=params)
|
r = current_instance.s.get(
|
||||||
|
f'https://{current_instance.instance}/api/v1/artists', params=params)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
|
@ -141,30 +148,32 @@ def get_artists(page=None, q=None, artist=None, album=None, favourites=None, ref
|
||||||
def get_albums(page=None, q=None, artist=None, include_channels=None, refresh=False, pg=None):
|
def get_albums(page=None, q=None, artist=None, include_channels=None, refresh=False, pg=None):
|
||||||
'''This function get artists by params'''
|
'''This function get artists by params'''
|
||||||
params = {
|
params = {
|
||||||
'page': page,
|
'page': page,
|
||||||
'q': q,
|
'q': q,
|
||||||
'artist': artist,
|
'artist': artist,
|
||||||
'include_channels': include_channels,
|
'include_channels': include_channels,
|
||||||
'refresh': refresh
|
'refresh': refresh
|
||||||
}
|
}
|
||||||
if pg:
|
if pg:
|
||||||
r = current_instance.s.get(pg)
|
r = current_instance.s.get(pg)
|
||||||
else:
|
else:
|
||||||
r = current_instance.s.get(f'https://{current_instance.instance}/api/v1/albums', params=params)
|
r = current_instance.s.get(
|
||||||
|
f'https://{current_instance.instance}/api/v1/albums', params=params)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def get_channels(page=None, q=None, tag=None, pg=None):
|
def get_channels(page=None, q=None, tag=None, pg=None):
|
||||||
params = {
|
params = {
|
||||||
'page': page,
|
'page': page,
|
||||||
'q': q,
|
'q': q,
|
||||||
'tag': tag
|
'tag': tag
|
||||||
}
|
}
|
||||||
if pg:
|
if pg:
|
||||||
r = current_instance.s.get(pg)
|
r = current_instance.s.get(pg)
|
||||||
else:
|
else:
|
||||||
r = current_instance.s.get(f'https://{current_instance.instance}/api/v1/channels', params=params)
|
r = current_instance.s.get(
|
||||||
|
f'https://{current_instance.instance}/api/v1/channels', params=params)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
|
@ -172,15 +181,16 @@ def get_channels(page=None, q=None, tag=None, pg=None):
|
||||||
def get_playlists(page=None, page_size=None, q=None, ordering='-modification_date', pg=None):
|
def get_playlists(page=None, page_size=None, q=None, ordering='-modification_date', pg=None):
|
||||||
'''List playlists'''
|
'''List playlists'''
|
||||||
params = {
|
params = {
|
||||||
'page': page,
|
'page': page,
|
||||||
'page_size': page_size,
|
'page_size': page_size,
|
||||||
'q': q,
|
'q': q,
|
||||||
'ordering': ordering
|
'ordering': ordering
|
||||||
}
|
}
|
||||||
if pg:
|
if pg:
|
||||||
r = current_instance.s.get(pg)
|
r = current_instance.s.get(pg)
|
||||||
else:
|
else:
|
||||||
r = current_instance.s.get(f'https://{current_instance.instance}/api/v1/playlists', params=params)
|
r = current_instance.s.get(
|
||||||
|
f'https://{current_instance.instance}/api/v1/playlists', params=params)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
@ -191,65 +201,73 @@ def get_playlist_tracks(playlist_id, pg=None):
|
||||||
if pg:
|
if pg:
|
||||||
r = current_instance.s.get(pg)
|
r = current_instance.s.get(pg)
|
||||||
else:
|
else:
|
||||||
r = current_instance.s.get(f'https://{current_instance.instance}/api/v1/playlists/{playlist_id}/tracks')
|
r = current_instance.s.get(
|
||||||
|
f'https://{current_instance.instance}/api/v1/playlists/{playlist_id}/tracks')
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def list_libraries(page=None, page_size=None, q=None, scope='all', pg=None):
|
def list_libraries(page=None, page_size=None, q=None, scope='all', pg=None):
|
||||||
params = {
|
params = {
|
||||||
'page': page,
|
'page': page,
|
||||||
'page_size': page_size,
|
'page_size': page_size,
|
||||||
'q': q,
|
'q': q,
|
||||||
'scope': scope,
|
'scope': scope,
|
||||||
}
|
}
|
||||||
if pg:
|
if pg:
|
||||||
r = current_instance.s.get(pg)
|
r = current_instance.s.get(pg)
|
||||||
else:
|
else:
|
||||||
r = current_instance.s.get(f'https://{current_instance.instance}/api/v1/libraries', params=params)
|
r = current_instance.s.get(
|
||||||
|
f'https://{current_instance.instance}/api/v1/libraries', params=params)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def get_tags(q=None, pg=None):
|
def get_tags(q=None, pg=None):
|
||||||
params = {
|
params = {
|
||||||
'q': q,
|
'q': q,
|
||||||
}
|
}
|
||||||
if pg:
|
if pg:
|
||||||
r = current_instance.s.get(pg)
|
r = current_instance.s.get(pg)
|
||||||
else:
|
else:
|
||||||
r = current_instance.s.get(f'https://{current_instance.instance}/api/v1/tags', params=params)
|
r = current_instance.s.get(
|
||||||
|
f'https://{current_instance.instance}/api/v1/tags', params=params)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def federate_search_by_url(object):
|
def federate_search_by_url(object):
|
||||||
params = {
|
params = {
|
||||||
'object': object
|
'object': object
|
||||||
}
|
}
|
||||||
r = current_instance.s.post(f'https://{current_instance.instance}/api/v1/federation/fetches', json=params)
|
r = current_instance.s.post(
|
||||||
|
f'https://{current_instance.instance}/api/v1/federation/fetches', json=params)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def record_track_in_history(track_id):
|
def record_track_in_history(track_id):
|
||||||
params = {
|
params = {
|
||||||
'track': int(track_id)
|
'track': int(track_id)
|
||||||
}
|
}
|
||||||
r = current_instance.s.post(f'https://{current_instance.instance}/api/v1/history/listenings', json=params)
|
r = current_instance.s.post(
|
||||||
|
f'https://{current_instance.instance}/api/v1/history/listenings', json=params)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
return r.json
|
return r.json
|
||||||
|
|
||||||
|
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def favorite_track(track_id):
|
def favorite_track(track_id):
|
||||||
r = current_instance.s.post(f'https://{current_instance.instance}/api/v1/favorites/tracks', json={'track': int(track_id)})
|
r = current_instance.s.post(
|
||||||
|
f'https://{current_instance.instance}/api/v1/favorites/tracks', json={'track': int(track_id)})
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
return r.json
|
return r.json
|
||||||
|
|
||||||
|
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def unfavorite_track(track_id):
|
def unfavorite_track(track_id):
|
||||||
r = current_instance.s.post(f'https://{current_instance.instance}/api/v1/favorites/tracks/delete', json={'track': int(track_id)})
|
r = current_instance.s.post(
|
||||||
|
f'https://{current_instance.instance}/api/v1/favorites/tracks/delete', json={'track': int(track_id)})
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
return r.json
|
return r.json
|
||||||
|
|
||||||
|
@ -257,24 +275,27 @@ def unfavorite_track(track_id):
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def hide_content(content):
|
def hide_content(content):
|
||||||
'''This function hide content (write permission)'''
|
'''This function hide content (write permission)'''
|
||||||
r = current_instance.s.post(f'https://{current_instance.instance}/api/v1/moderation/content-filters/', json=content)
|
r = current_instance.s.post(
|
||||||
|
f'https://{current_instance.instance}/api/v1/moderation/content-filters/', json=content)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
return r.json
|
return r.json
|
||||||
|
|
||||||
|
|
||||||
# [FunkWhale radios]
|
# [FunkWhale radios]
|
||||||
def get_radios():
|
def get_radios():
|
||||||
r = current_instance.s.get(f'https://{current_instance.instance}/api/v1/radios/radios/')
|
r = current_instance.s.get(
|
||||||
|
f'https://{current_instance.instance}/api/v1/radios/radios/')
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
def post_radio_session(requested_radio):
|
def post_radio_session(requested_radio):
|
||||||
r = current_instance.s.post(f'https://{current_instance.instance}/api/v1/radios/sessions/', json=requested_radio)
|
r = current_instance.s.post(
|
||||||
|
f'https://{current_instance.instance}/api/v1/radios/sessions/', json=requested_radio)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def get_track_radio(radio_session):
|
def get_track_radio(radio_session):
|
||||||
r = current_instance.s.post(f'https://{current_instance.instance}/api/v1/radios/tracks/', json=radio_session)
|
r = current_instance.s.post(
|
||||||
|
f'https://{current_instance.instance}/api/v1/radios/tracks/', json=radio_session)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,10 @@ from loguru import logger
|
||||||
|
|
||||||
fzf = FzfPrompt()
|
fzf = FzfPrompt()
|
||||||
|
|
||||||
|
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def list_artists(pg=None, search=None):
|
def list_artists(pg=None, search=None):
|
||||||
artists = get_artists(q=search,pg=pg)
|
artists = get_artists(q=search, pg=pg)
|
||||||
artists_next = artists.get('next')
|
artists_next = artists.get('next')
|
||||||
artists_prev = artists.get('previous')
|
artists_prev = artists.get('previous')
|
||||||
artists_results = artists.get('results')
|
artists_results = artists.get('results')
|
||||||
|
@ -52,7 +53,8 @@ def play_artist(artist_id):
|
||||||
storage[track_url_to_uuid(listen_url)] = i
|
storage[track_url_to_uuid(listen_url)] = i
|
||||||
player.loadfile(listen_url, 'append-play')
|
player.loadfile(listen_url, 'append-play')
|
||||||
if tracks_next:
|
if tracks_next:
|
||||||
tracks = get_tracks(artist=artist_id, include_channels=True, pg=tracks_next)
|
tracks = get_tracks(
|
||||||
|
artist=artist_id, include_channels=True, pg=tracks_next)
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
artist_name = tracks.get('results')[0]['artist']['name']
|
artist_name = tracks.get('results')[0]['artist']['name']
|
||||||
|
|
|
@ -34,4 +34,5 @@ def list_channels(pg=None, search=None):
|
||||||
refresh = False
|
refresh = False
|
||||||
if channels_results[int(select)].get('artist').get('is_local') == False:
|
if channels_results[int(select)].get('artist').get('is_local') == False:
|
||||||
refresh = True
|
refresh = True
|
||||||
list_albums(artist=channels_results[int(select)].get('artist').get('id'), include_channels=True, refresh=refresh)
|
list_albums(artist=channels_results[int(select)].get(
|
||||||
|
'artist').get('id'), include_channels=True, refresh=refresh)
|
||||||
|
|
|
@ -5,6 +5,7 @@ from loguru import logger
|
||||||
|
|
||||||
fzf = FzfPrompt()
|
fzf = FzfPrompt()
|
||||||
|
|
||||||
|
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def list_favorites_tracks(pg=None, search=None, scope=None):
|
def list_favorites_tracks(pg=None, search=None, scope=None):
|
||||||
tracks = get_favorires_tracks(q=search, scope=scope, pg=pg)
|
tracks = get_favorires_tracks(q=search, scope=scope, pg=pg)
|
||||||
|
@ -48,9 +49,11 @@ Limit the results to a given user or pod:
|
||||||
play_track(track=i['track'], multi=True)
|
play_track(track=i['track'], multi=True)
|
||||||
elif len(select) > 1:
|
elif len(select) > 1:
|
||||||
for i in select:
|
for i in select:
|
||||||
play_track(track=tracks_results[int(i.split('.', 1)[0])]['track'], multi=True)
|
play_track(track=tracks_results[int(
|
||||||
|
i.split('.', 1)[0])]['track'], multi=True)
|
||||||
else:
|
else:
|
||||||
play_track(track=tracks_results[int(select[0].split('.', 1)[0])]['track'])
|
play_track(track=tracks_results[int(
|
||||||
|
select[0].split('.', 1)[0])]['track'])
|
||||||
|
|
||||||
|
|
||||||
def play_track(track, multi=False):
|
def play_track(track, multi=False):
|
||||||
|
|
|
@ -21,7 +21,8 @@ def libraries(pg=None):
|
||||||
lib_name = lib_i.get('name')
|
lib_name = lib_i.get('name')
|
||||||
lib_by = lib_i.get('actor').get('full_username')
|
lib_by = lib_i.get('actor').get('full_username')
|
||||||
libraries_listing.append(f'{index}.{lib_name} | by {lib_by}')
|
libraries_listing.append(f'{index}.{lib_name} | by {lib_by}')
|
||||||
lib_select = fzf.prompt(libraries_listing, f'--header=\'found {libs_count} libraries\'')[0].split('.', 1)
|
lib_select = fzf.prompt(
|
||||||
|
libraries_listing, f'--header=\'found {libs_count} libraries\'')[0].split('.', 1)
|
||||||
if lib_select[0] == 'Next':
|
if lib_select[0] == 'Next':
|
||||||
libraries(pg=libs_next)
|
libraries(pg=libs_next)
|
||||||
elif lib_select[0] == 'Prev':
|
elif lib_select[0] == 'Prev':
|
||||||
|
@ -31,4 +32,3 @@ def libraries(pg=None):
|
||||||
lib_name = lib_select[1]
|
lib_name = lib_select[1]
|
||||||
lib_uuid = libs[int(lib_addr)].get('uuid')
|
lib_uuid = libs[int(lib_addr)].get('uuid')
|
||||||
return None, 'library', lib_name, lib_uuid
|
return None, 'library', lib_name, lib_uuid
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ from loguru import logger
|
||||||
|
|
||||||
fzf = FzfPrompt()
|
fzf = FzfPrompt()
|
||||||
|
|
||||||
|
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def list_playlists(pg=None, search=None):
|
def list_playlists(pg=None, search=None):
|
||||||
playlists = get_playlists(q=search, pg=pg)
|
playlists = get_playlists(q=search, pg=pg)
|
||||||
|
@ -32,6 +33,7 @@ def list_playlists(pg=None, search=None):
|
||||||
else:
|
else:
|
||||||
play_playlist(playlist_id=playlists_results[int(select)].get('id'))
|
play_playlist(playlist_id=playlists_results[int(select)].get('id'))
|
||||||
|
|
||||||
|
|
||||||
def play_playlist(playlist_id):
|
def play_playlist(playlist_id):
|
||||||
tracks = get_playlist_tracks(playlist_id, pg=None)
|
tracks = get_playlist_tracks(playlist_id, pg=None)
|
||||||
tracks_next = tracks.get('next')
|
tracks_next = tracks.get('next')
|
||||||
|
|
|
@ -28,12 +28,14 @@ def list_radios():
|
||||||
if descr and descr != "":
|
if descr and descr != "":
|
||||||
radio_option += f' | {descr}'
|
radio_option += f' | {descr}'
|
||||||
view.append(f'{index}.{radio_option}')
|
view.append(f'{index}.{radio_option}')
|
||||||
if current_instance.s.headers.get('Authorization'): # Radios avalaible only for auth user
|
# Radios avalaible only for auth user
|
||||||
|
if current_instance.s.headers.get('Authorization'):
|
||||||
view.append('Favourites')
|
view.append('Favourites')
|
||||||
view.append('Less listened')
|
view.append('Less listened')
|
||||||
view.extend(['Tag', 'Random', 'Libraries', 'Users', 'Recently Added'])
|
view.extend(['Tag', 'Random', 'Libraries', 'Users', 'Recently Added'])
|
||||||
|
|
||||||
selected = fzf.prompt(view, f'--header \'Found {count} radios\' --read0', delimiter="\0")[0].split('.', 1)
|
selected = fzf.prompt(
|
||||||
|
view, f'--header \'Found {count} radios\' --read0', delimiter="\0")[0].split('.', 1)
|
||||||
if 'Favourites' in selected:
|
if 'Favourites' in selected:
|
||||||
radio_load(id_radio, 'favorites', name='your favorites tracks')
|
radio_load(id_radio, 'favorites', name='your favorites tracks')
|
||||||
elif 'Tag' in selected:
|
elif 'Tag' in selected:
|
||||||
|
@ -58,7 +60,8 @@ def list_radios():
|
||||||
lib_addr = input()
|
lib_addr = input()
|
||||||
radio_load(None, 'actor-content', lib_addr, lib_addr)
|
radio_load(None, 'actor-content', lib_addr, lib_addr)
|
||||||
elif 'Recently Added' in selected:
|
elif 'Recently Added' in selected:
|
||||||
radio_load(id_radio, 'recently-added', name='Newest content on the network')
|
radio_load(id_radio, 'recently-added',
|
||||||
|
name='Newest content on the network')
|
||||||
elif 'Less listened' in selected:
|
elif 'Less listened' in selected:
|
||||||
radio_load(id_radio, 'less-listened', name="Less listened tracks")
|
radio_load(id_radio, 'less-listened', name="Less listened tracks")
|
||||||
else:
|
else:
|
||||||
|
@ -77,11 +80,13 @@ def radio_generator(radio_session_id):
|
||||||
count_t += 1
|
count_t += 1
|
||||||
if count_t >= 60:
|
if count_t >= 60:
|
||||||
count_t = 0
|
count_t = 0
|
||||||
playlist_remaining = len(player.playlist) - player.playlist_current_pos
|
playlist_remaining = len(player.playlist) - \
|
||||||
|
player.playlist_current_pos
|
||||||
if playlist_remaining <= 2:
|
if playlist_remaining <= 2:
|
||||||
radio_get_track(radio_session_id)
|
radio_get_track(radio_session_id)
|
||||||
logger.info('Radio generator stopped')
|
logger.info('Radio generator stopped')
|
||||||
|
|
||||||
|
|
||||||
radio_event_gen = threading.Event()
|
radio_event_gen = threading.Event()
|
||||||
|
|
||||||
|
|
||||||
|
@ -90,16 +95,17 @@ def radio_load(id_radio=None, type_radio='custom', name=None, related_object=Non
|
||||||
show_like_button = get_config('show_like_button')
|
show_like_button = get_config('show_like_button')
|
||||||
player.volume = get_config('mpv_volume')
|
player.volume = get_config('mpv_volume')
|
||||||
requested_radio = {
|
requested_radio = {
|
||||||
'custom_radio': id_radio,
|
'custom_radio': id_radio,
|
||||||
'radio_type': type_radio,
|
'radio_type': type_radio,
|
||||||
'related_object_id': related_object
|
'related_object_id': related_object
|
||||||
}
|
}
|
||||||
radio_session_id = post_radio_session(requested_radio).get('id')
|
radio_session_id = post_radio_session(requested_radio).get('id')
|
||||||
for i in range(0, 2):
|
for i in range(0, 2):
|
||||||
radio_get_track(radio_session_id)
|
radio_get_track(radio_session_id)
|
||||||
|
|
||||||
radio_event_gen.set()
|
radio_event_gen.set()
|
||||||
radio_task = threading.Thread(target=radio_generator, args=(radio_session_id,), daemon=True)
|
radio_task = threading.Thread(
|
||||||
|
target=radio_generator, args=(radio_session_id,), daemon=True)
|
||||||
radio_task.start()
|
radio_task.start()
|
||||||
player_items_menu = ['Next', 'Prev', 'Pause', 'Download', 'Info']
|
player_items_menu = ['Next', 'Prev', 'Pause', 'Download', 'Info']
|
||||||
|
|
||||||
|
@ -112,11 +118,14 @@ def radio_load(id_radio=None, type_radio='custom', name=None, related_object=Non
|
||||||
player_items_menu[2] = 'Play'
|
player_items_menu[2] = 'Play'
|
||||||
else:
|
else:
|
||||||
player_items_menu[2] = 'Pause'
|
player_items_menu[2] = 'Pause'
|
||||||
select = fzf.prompt(player_items_menu, f"--header=\'Radio {name} playing...\'")[0]
|
select = fzf.prompt(player_items_menu,
|
||||||
|
f"--header=\'Radio {name} playing...\'")[0]
|
||||||
if select == 'Next':
|
if select == 'Next':
|
||||||
playlist_remaining = len(player.playlist) - player.playlist_current_pos
|
playlist_remaining = len(
|
||||||
|
player.playlist) - player.playlist_current_pos
|
||||||
if playlist_remaining <= 2:
|
if playlist_remaining <= 2:
|
||||||
threading.Thread(target=radio_get_track, args=(radio_session_id,), daemon=True).start()
|
threading.Thread(target=radio_get_track, args=(
|
||||||
|
radio_session_id,), daemon=True).start()
|
||||||
player.playlist_next()
|
player.playlist_next()
|
||||||
elif select == 'Prev':
|
elif select == 'Prev':
|
||||||
player.playlist_prev()
|
player.playlist_prev()
|
||||||
|
@ -134,13 +143,14 @@ def radio_load(id_radio=None, type_radio='custom', name=None, related_object=Non
|
||||||
name_aa = track.get(i).get('name')
|
name_aa = track.get(i).get('name')
|
||||||
if not name_aa:
|
if not name_aa:
|
||||||
name_aa = track[i]['title']
|
name_aa = track[i]['title']
|
||||||
print(i + ': '+ name_aa)
|
print(i + ': ' + name_aa)
|
||||||
key = track.get(i)
|
key = track.get(i)
|
||||||
if key and isinstance(key, str):
|
if key and isinstance(key, str):
|
||||||
print(i + ': ' + key)
|
print(i + ': ' + key)
|
||||||
input()
|
input()
|
||||||
elif select == 'Like':
|
elif select == 'Like':
|
||||||
favorite_track(player_fw_storage.storage.get(track_url_to_uuid())['id'])
|
favorite_track(player_fw_storage.storage.get(
|
||||||
|
track_url_to_uuid())['id'])
|
||||||
elif select == 'Exit':
|
elif select == 'Exit':
|
||||||
try:
|
try:
|
||||||
radio_event_gen.clear()
|
radio_event_gen.clear()
|
||||||
|
@ -180,6 +190,5 @@ def radio_get_track(radio_session_id):
|
||||||
track = radio_context.get('track')
|
track = radio_context.get('track')
|
||||||
listen_url = track['listen_url']
|
listen_url = track['listen_url']
|
||||||
player_fw_storage.storage[track_url_to_uuid(listen_url)] = track
|
player_fw_storage.storage[track_url_to_uuid(listen_url)] = track
|
||||||
player.loadfile(get_audio_file(listen_url, listen_url=True), 'append-play')
|
player.loadfile(get_audio_file(
|
||||||
|
listen_url, listen_url=True), 'append-play')
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ from loguru import logger
|
||||||
|
|
||||||
fzf = FzfPrompt()
|
fzf = FzfPrompt()
|
||||||
|
|
||||||
|
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def list_tags(pg=None, search=None):
|
def list_tags(pg=None, search=None):
|
||||||
tags = get_tags(q=search, pg=pg)
|
tags = get_tags(q=search, pg=pg)
|
||||||
|
@ -30,4 +31,3 @@ def list_tags(pg=None, search=None):
|
||||||
return list_tags(search=input())
|
return list_tags(search=input())
|
||||||
else:
|
else:
|
||||||
return tags_results[int(select)].get('name')
|
return tags_results[int(select)].get('name')
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ from loguru import logger
|
||||||
|
|
||||||
fzf = FzfPrompt()
|
fzf = FzfPrompt()
|
||||||
|
|
||||||
|
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def list_tracks(pg=None, search=None, tag=None):
|
def list_tracks(pg=None, search=None, tag=None):
|
||||||
tracks = get_tracks(q=search, pg=pg, tag=tag)
|
tracks = get_tracks(q=search, pg=pg, tag=tag)
|
||||||
|
@ -38,4 +39,3 @@ def list_tracks(pg=None, search=None, tag=None):
|
||||||
play_track(track=i, multi=True)
|
play_track(track=i, multi=True)
|
||||||
else:
|
else:
|
||||||
play_track(track=tracks_results[int(select)])
|
play_track(track=tracks_results[int(select)])
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,9 @@ import time
|
||||||
fzf = FzfPrompt()
|
fzf = FzfPrompt()
|
||||||
|
|
||||||
player = mpv.MPV()
|
player = mpv.MPV()
|
||||||
player.ytdl = False # Prevent attempts load track with yt-dlp
|
player.ytdl = False # Prevent attempts load track with yt-dlp
|
||||||
player.prefetch_playlist = get_config('prefetch_playlist') # Fast loading next track, but high network traffic
|
player.volume = get_config('mpv_volume')
|
||||||
|
player.prefetch_playlist = get_config('prefetch_playlist')
|
||||||
show_like_button = get_config('show_like_button')
|
show_like_button = get_config('show_like_button')
|
||||||
track_activity_history = get_config('track_activity_history')
|
track_activity_history = get_config('track_activity_history')
|
||||||
|
|
||||||
|
@ -86,16 +87,18 @@ def player_menu(header='', storage={}):
|
||||||
name_aa = track.get(i).get('name')
|
name_aa = track.get(i).get('name')
|
||||||
if not name_aa:
|
if not name_aa:
|
||||||
name_aa = track.get(i).get('title')
|
name_aa = track.get(i).get('title')
|
||||||
print(i + ': '+ name_aa)
|
print(i + ': ' + name_aa)
|
||||||
key = track.get(i)
|
key = track.get(i)
|
||||||
if key and isinstance(key, str):
|
if key and isinstance(key, str):
|
||||||
print(i + ': ' + key)
|
print(i + ': ' + key)
|
||||||
input()
|
input()
|
||||||
elif select == 'Like':
|
elif select == 'Like':
|
||||||
src.fw_api.favorite_track(player_fw_storage.storage.get(track_url_to_uuid())['id'])
|
src.fw_api.favorite_track(
|
||||||
|
player_fw_storage.storage.get(track_url_to_uuid())['id'])
|
||||||
elif select == 'Hide artist':
|
elif select == 'Hide artist':
|
||||||
track = player_fw_storage.storage.get(track_url_to_uuid())
|
track = player_fw_storage.storage.get(track_url_to_uuid())
|
||||||
src.fw_api.hide_content({'target': {'id': track.get('artist').get('id'), 'type': 'artist'}})
|
src.fw_api.hide_content(
|
||||||
|
{'target': {'id': track.get('artist').get('id'), 'type': 'artist'}})
|
||||||
elif select == 'Exit':
|
elif select == 'Exit':
|
||||||
player.playlist_clear()
|
player.playlist_clear()
|
||||||
player.stop()
|
player.stop()
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
import json, requests, time
|
import json
|
||||||
|
import requests
|
||||||
|
import time
|
||||||
from os.path import exists
|
from os.path import exists
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from pyfzf.pyfzf import FzfPrompt
|
from pyfzf.pyfzf import FzfPrompt
|
||||||
|
@ -8,42 +10,42 @@ fzf = FzfPrompt()
|
||||||
conf_file = 'config.json'
|
conf_file = 'config.json'
|
||||||
|
|
||||||
default_conf = {
|
default_conf = {
|
||||||
'instance': 'fw.ponychord.rocks',
|
'instance': 'fw.ponychord.rocks',
|
||||||
'public_list_instances': [
|
'public_list_instances': [
|
||||||
"open.audio",
|
"open.audio",
|
||||||
"audio.securetown.top",
|
"audio.securetown.top",
|
||||||
"funkwhale.co.uk",
|
"funkwhale.co.uk",
|
||||||
"am.pirateradio.social",
|
"am.pirateradio.social",
|
||||||
"audio.liberta.vip",
|
"audio.liberta.vip",
|
||||||
"audio.gafamfree.party",
|
"audio.gafamfree.party",
|
||||||
"tanukitunes.com",
|
"tanukitunes.com",
|
||||||
"funkwhale.juniorjpdj.pl",
|
"funkwhale.juniorjpdj.pl",
|
||||||
"tavia.mle.party",
|
"tavia.mle.party",
|
||||||
"funkwhale.thurk.org",
|
"funkwhale.thurk.org",
|
||||||
"buzzworkers.com",
|
"buzzworkers.com",
|
||||||
"soundship.de",
|
"soundship.de",
|
||||||
"funkwhale.kameha.click",
|
"funkwhale.kameha.click",
|
||||||
"music.chosto.me",
|
"music.chosto.me",
|
||||||
"zik.goe.land",
|
"zik.goe.land",
|
||||||
"music.humanoids.be",
|
"music.humanoids.be",
|
||||||
"music.hempton.us",
|
"music.hempton.us",
|
||||||
"mizik.o-k-i.net",
|
"mizik.o-k-i.net",
|
||||||
"klh.radiolivre.org",
|
"klh.radiolivre.org",
|
||||||
"hudba.feildel.fr",
|
"hudba.feildel.fr",
|
||||||
"funkwhale.mita.me",
|
"funkwhale.mita.me",
|
||||||
"funk.deko.cloud",
|
"funk.deko.cloud",
|
||||||
"audio.graz.social",
|
"audio.graz.social",
|
||||||
"funkwhale.desmu.fr",
|
"funkwhale.desmu.fr",
|
||||||
"listen.knsm.cc",
|
"listen.knsm.cc",
|
||||||
"funkwhale.gegeweb.eu",
|
"funkwhale.gegeweb.eu",
|
||||||
"shitnoise.monster"
|
"shitnoise.monster"
|
||||||
],
|
],
|
||||||
'enable_server_transcoding': False,
|
'enable_server_transcoding': False,
|
||||||
'track_activity_history': False,
|
'track_activity_history': False,
|
||||||
'prefetch_playlist': True,
|
'prefetch_playlist': True,
|
||||||
'mpv_volume': 100,
|
'mpv_volume': 100,
|
||||||
'show_like_button': True,
|
'show_like_button': True,
|
||||||
'show_artist_name_in_albums': False
|
'show_artist_name_in_albums': False
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -97,15 +99,15 @@ def get_new_funkwhale_servers():
|
||||||
'from': f"{timeback}",
|
'from': f"{timeback}",
|
||||||
'to': f"{now}",
|
'to': f"{now}",
|
||||||
'queries': [
|
'queries': [
|
||||||
{
|
{
|
||||||
'refId': "A",
|
'refId': "A",
|
||||||
'intervalMs': 60000,
|
'intervalMs': 60000,
|
||||||
'maxDataPoints': 1174,
|
'maxDataPoints': 1174,
|
||||||
'datasourceId': 1,
|
'datasourceId': 1,
|
||||||
'rawSql': "SELECT * FROM (\n SELECT\n DISTINCT on (c.domain) c.domain as \"Name\",\n c.up as \"Is up\",\n coalesce(c.open_registrations, false) as \"Open registrations\",\n coalesce(anonymous_can_listen, false) as \"Anonymous can listen\",\n coalesce(c.usage_users_total, 0) as \"Total users\",\n coalesce(c.usage_users_active_month, 0) as \"Active users (this month)\",\n coalesce(c.software_version_major, 0)::text || '.' || coalesce(c.software_version_minor, 0)::text || '.' || coalesce(c.software_version_patch, 0)::text as \"Version\",\n c.time as \"Last checked\",\n d.first_seen as \"First seen\"\n FROM checks as c\n INNER JOIN domains AS d ON d.name = c.domain\n WHERE d.blocked = false AND c.up = true AND c.time > now() - INTERVAL '7 days'\n AND c.anonymous_can_listen IN ('true')\n AND c.open_registrations IN ('true','false')\n\n ORDER BY c.domain, c.time DESC\n) as t ORDER BY \"Active users (this month)\" DESC",
|
'rawSql': "SELECT * FROM (\n SELECT\n DISTINCT on (c.domain) c.domain as \"Name\",\n c.up as \"Is up\",\n coalesce(c.open_registrations, false) as \"Open registrations\",\n coalesce(anonymous_can_listen, false) as \"Anonymous can listen\",\n coalesce(c.usage_users_total, 0) as \"Total users\",\n coalesce(c.usage_users_active_month, 0) as \"Active users (this month)\",\n coalesce(c.software_version_major, 0)::text || '.' || coalesce(c.software_version_minor, 0)::text || '.' || coalesce(c.software_version_patch, 0)::text as \"Version\",\n c.time as \"Last checked\",\n d.first_seen as \"First seen\"\n FROM checks as c\n INNER JOIN domains AS d ON d.name = c.domain\n WHERE d.blocked = false AND c.up = true AND c.time > now() - INTERVAL '7 days'\n AND c.anonymous_can_listen IN ('true')\n AND c.open_registrations IN ('true','false')\n\n ORDER BY c.domain, c.time DESC\n) as t ORDER BY \"Active users (this month)\" DESC",
|
||||||
'format': "table"
|
'format': "table"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
r = requests.post(public_server_api, json=request_public_servers)
|
r = requests.post(public_server_api, json=request_public_servers)
|
||||||
|
@ -117,4 +119,3 @@ def get_new_funkwhale_servers():
|
||||||
if i[0] not in default_conf['public_list_instances'] and i[1]:
|
if i[0] not in default_conf['public_list_instances'] and i[1]:
|
||||||
new_instances.append(i[0])
|
new_instances.append(i[0])
|
||||||
return new_instances
|
return new_instances
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ def get_remote_file_name(url):
|
||||||
|
|
||||||
|
|
||||||
def download_track(url, name=None):
|
def download_track(url, name=None):
|
||||||
url = url.split('?')[0] # Stripe all params from url
|
url = url.split('?')[0] # Stripe all params from url
|
||||||
r = src.fw_api.current_instance.s.get(url, stream=True)
|
r = src.fw_api.current_instance.s.get(url, stream=True)
|
||||||
if not name:
|
if not name:
|
||||||
name = get_remote_file_name(url)
|
name = get_remote_file_name(url)
|
||||||
|
@ -24,7 +24,7 @@ def download_track(url, name=None):
|
||||||
print(f"Downloading {name}")
|
print(f"Downloading {name}")
|
||||||
total_length = r.headers.get('content-length')
|
total_length = r.headers.get('content-length')
|
||||||
|
|
||||||
if total_length is None: # no content length header
|
if total_length is None: # no content length header
|
||||||
f.write(r.content)
|
f.write(r.content)
|
||||||
else:
|
else:
|
||||||
dl = 0
|
dl = 0
|
||||||
|
@ -33,6 +33,7 @@ def download_track(url, name=None):
|
||||||
dl += len(data)
|
dl += len(data)
|
||||||
f.write(data)
|
f.write(data)
|
||||||
done = int(50 * dl / total_length)
|
done = int(50 * dl / total_length)
|
||||||
sys.stdout.write("\r[%s%s]" % ('=' * done, ' ' * (50-done)) ) # base progress bar
|
# base progress bar
|
||||||
|
sys.stdout.write("\r[%s%s]" % ('=' * done, ' ' * (50-done)))
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
return name
|
return name
|
||||||
|
|
Loading…
Reference in New Issue