This commit is contained in:
localhost_frssoft 2022-11-18 13:22:55 +03:00
parent e653cf27fe
commit 1f502ef52a
6 changed files with 35 additions and 24 deletions

View file

@ -1,7 +1,7 @@
import src.fw_artists import src.fw_artists
from src.fw_api import get_artists, get_tracks, get_albums, concatinate_endpoint from src.fw_api import get_artists, get_tracks, get_albums, concatinate_endpoint
from src.settings import get_config from src.settings import get_config
from src.mpv_control import player, player_menu from src.mpv_control import player, player_menu, track_url_to_uuid
from pyfzf.pyfzf import FzfPrompt from pyfzf.pyfzf import FzfPrompt
from loguru import logger from loguru import logger
@ -63,6 +63,6 @@ def play_album(album_id):
storage = {} storage = {}
for i in tracks_results: for i in tracks_results:
listen_url = concatinate_endpoint(i.get('listen_url')) listen_url = concatinate_endpoint(i.get('listen_url'))
storage[listen_url] = i storage[track_url_to_uuid(listen_url)] = i
player.loadfile(listen_url, 'append-play') player.loadfile(listen_url, 'append-play')
player_menu("Album playing...", storage) player_menu("Album playing...", storage)

View file

@ -1,6 +1,6 @@
from src.fw_api import get_artists, get_tracks, concatinate_endpoint from src.fw_api import get_artists, get_tracks, concatinate_endpoint
from src.fw_albums import list_albums from src.fw_albums import list_albums
from src.mpv_control import player, player_menu from src.mpv_control import player, player_menu, track_url_to_uuid
from pyfzf.pyfzf import FzfPrompt from pyfzf.pyfzf import FzfPrompt
from loguru import logger from loguru import logger
@ -49,11 +49,11 @@ def play_artist(artist_id):
tracks_next = tracks.get('next') tracks_next = tracks.get('next')
for i in tracks_results: for i in tracks_results:
listen_url = concatinate_endpoint(i.get('listen_url')) listen_url = concatinate_endpoint(i.get('listen_url'))
storage[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].get('artist').get('name') artist_name = tracks.get('results')[0]['artist']['name']
player_menu(f"Artist {artist_name} playing...", storage) player_menu(f"Artist {artist_name} playing...", storage)

View file

@ -1,5 +1,5 @@
from src.fw_api import get_playlists, get_playlist_tracks, concatinate_endpoint from src.fw_api import get_playlists, get_playlist_tracks, concatinate_endpoint
from src.mpv_control import player, player_menu from src.mpv_control import player, player_menu, track_url_to_uuid
from pyfzf.pyfzf import FzfPrompt from pyfzf.pyfzf import FzfPrompt
from loguru import logger from loguru import logger
@ -48,7 +48,7 @@ def play_playlist(playlist_id):
for i in tracks_results: for i in tracks_results:
track = i.get('track') track = i.get('track')
listen_url = concatinate_endpoint(track['listen_url']) listen_url = concatinate_endpoint(track['listen_url'])
storage[listen_url] = track storage[track_url_to_uuid(listen_url)] = track
player.loadfile(listen_url, 'append-play') player.loadfile(listen_url, 'append-play')
if tracks_next: if tracks_next:
tracks = get_playlist_tracks(playlist=playlist_id, pg=tracks_next) tracks = get_playlist_tracks(playlist=playlist_id, pg=tracks_next)

View file

@ -1,7 +1,7 @@
from src.fw_api import s, get_radios, post_radio_session, get_track_radio, list_libraries, concatinate_endpoint from src.fw_api import s, get_radios, post_radio_session, get_track_radio, list_libraries, concatinate_endpoint, favorite_track
from src.fw_libraries import libraries from src.fw_libraries import libraries
from src.utils import download_track from src.utils import download_track
from src.mpv_control import player from src.mpv_control import player, track_url_to_uuid
from src.settings import get_config from src.settings import get_config
from pyfzf.pyfzf import FzfPrompt from pyfzf.pyfzf import FzfPrompt
from loguru import logger from loguru import logger
@ -95,40 +95,43 @@ def radio_load(id_radio=None, type_radio='custom', name=None, related_object=Non
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()
while True: player_items_menu = ['Next', 'Prev', 'Pause', 'Download', 'Info']
try:
player_items_menu = ['Next', 'Prev', 'Pause',
'Download', 'Info']
if show_like_button: if show_like_button:
player_items_menu.append('Like') player_items_menu.append('Like')
player_items_menu.extend(['Hide artist', 'Exit']) player_items_menu.extend(['Hide artist', 'Exit'])
while True:
try:
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':
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()
elif select == 'Pause': elif select in ('Pause', 'Play'):
if player.pause: if player.pause:
player_items_menu[2] = 'Pause'
player.pause = False player.pause = False
else: else:
player_items_menu[2] = 'Play'
player.pause = True player.pause = True
elif select == 'Download': elif select == 'Download':
print('Downloading...') print('Downloading...')
name_downloaded = download_track(player.filename) name_downloaded = download_track(player.filename)
print(f'Downloaded: {name_downloaded}') print(f'Downloaded: {name_downloaded}')
elif select == 'Info': elif select == 'Info':
track = audio_info.get(player.filename) track = audio_info.get(track_url_to_uuid())
for i in ('title', 'fid', 'license', 'album', 'artist'): for i in ('title', 'fid', 'license', 'album', 'artist'):
if i in ('album', 'artist'): if i in ('album', 'artist'):
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[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':
favorite_track(audio_info.get(track_url_to_uuid())['id'])
elif select == 'Exit': elif select == 'Exit':
try: try:
radio_event_gen.clear() radio_event_gen.clear()
@ -165,7 +168,7 @@ def radio_get_track(radio_session_id):
else: else:
track = radio_context.get('track') track = radio_context.get('track')
listen_url = track.get('listen_url') listen_url = track.get('listen_url')
audio_info[concatinate_endpoint(listen_url)] = track audio_info[track_url_to_uuid(listen_url)] = track
player.loadfile(concatinate_endpoint(listen_url), 'append-play') player.loadfile(concatinate_endpoint(listen_url), 'append-play')

View file

@ -1,5 +1,5 @@
from src.fw_api import get_tracks, concatinate_endpoint from src.fw_api import get_tracks, concatinate_endpoint
from src.mpv_control import player, player_menu from src.mpv_control import player, player_menu, track_url_to_uuid
from pyfzf.pyfzf import FzfPrompt from pyfzf.pyfzf import FzfPrompt
from loguru import logger from loguru import logger
@ -36,7 +36,7 @@ def list_tracks(pg=None, search=None):
def play_track(track): def play_track(track):
storage = {} storage = {}
listen_url = concatinate_endpoint(track.get('listen_url')) listen_url = concatinate_endpoint(track.get('listen_url'))
storage[listen_url] = track storage[track_url_to_uuid(listen_url)] = track
player.loadfile(listen_url, 'append-play') player.loadfile(listen_url, 'append-play')
track_name = track.get('title') track_name = track.get('title')
player_menu(f"{track_name} playing...", storage) player_menu(f"{track_name} playing...", storage)

View file

@ -21,6 +21,14 @@ def set_http_header(headers=[]):
player.http_header_fields = headers player.http_header_fields = headers
def track_url_to_uuid(listen_url=None):
if listen_url:
uuid = listen_url.split(r'/')[-2]
else:
uuid = player.filename.split(r'/')[-2]
return uuid
@logger.catch @logger.catch
def player_menu(header='', storage={}): def player_menu(header='', storage={}):
player_fw_storage.storage = storage player_fw_storage.storage = storage
@ -48,8 +56,8 @@ def player_menu(header='', storage={}):
name_downloaded = download_track(player.filename) name_downloaded = download_track(player.filename)
print(f'Downloaded: {name_downloaded}') print(f'Downloaded: {name_downloaded}')
elif select == 'Info': elif select == 'Info':
track = storage.get(player.filename) track = storage.get(track_url_to_uuid())
for i in ('title', 'fid', 'license', 'album', 'artist'): for i in track.keys():
if i in ('album', 'artist'): if i in ('album', 'artist'):
name_aa = track.get(i).get('name') name_aa = track.get(i).get('name')
if not name_aa: if not name_aa:
@ -60,9 +68,9 @@ def player_menu(header='', storage={}):
print(i + ': ' + key) print(i + ': ' + key)
input() input()
elif select == 'Like': elif select == 'Like':
src.fw_api.favorite_track(storage.get(player.filename).get('id')) src.fw_api.favorite_track(storage.get(track_url_to_uuid())['id'])
elif select == 'Hide artist': elif select == 'Hide artist':
track = storage.get(player.filename) track = 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()