From 06fd6308fe4a49133eed06c35d01e406e595fd16 Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Thu, 8 Dec 2022 02:24:48 +0300 Subject: [PATCH] Correct integration shared player storage for tracks --- src/fw_radios.py | 11 ++++++----- src/mpv_control.py | 9 +++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/fw_radios.py b/src/fw_radios.py index 839d20e..a6246ab 100644 --- a/src/fw_radios.py +++ b/src/fw_radios.py @@ -2,7 +2,7 @@ from src.fw_api import current_instance, get_radios, post_radio_session, get_tra from src.fw_libraries import libraries from src.fw_tags import list_tags from src.utils import download_track -from src.mpv_control import player, track_url_to_uuid +from src.mpv_control import player, track_url_to_uuid, player_fw_storage from src.settings import get_config from pyfzf.pyfzf import FzfPrompt from loguru import logger @@ -11,7 +11,6 @@ import time fzf = FzfPrompt() -audio_info = {} @logger.catch def list_radios(): @@ -131,7 +130,7 @@ def radio_load(id_radio=None, type_radio='custom', name=None, related_object=Non name_downloaded = download_track(player.stream_open_filename) print(f'Downloaded: {name_downloaded}') elif select == 'Info': - track = audio_info.get(track_url_to_uuid()) + track = player_fw_storage.storage.get(track_url_to_uuid()) for i in ('title', 'fid', 'license', 'album', 'artist'): if i in ('album', 'artist'): name_aa = track.get(i).get('name') @@ -143,7 +142,7 @@ def radio_load(id_radio=None, type_radio='custom', name=None, related_object=Non print(i + ': ' + key) input() elif select == 'Like': - favorite_track(audio_info.get(track_url_to_uuid())['id']) + favorite_track(player_fw_storage.storage.get(track_url_to_uuid())['id']) elif select == 'Exit': try: radio_event_gen.clear() @@ -152,6 +151,7 @@ def radio_load(id_radio=None, type_radio='custom', name=None, related_object=Non pass player.playlist_clear() player.stop() + player_fw_storage.storage = {} break except: try: @@ -161,6 +161,7 @@ def radio_load(id_radio=None, type_radio='custom', name=None, related_object=Non pass player.playlist_clear() player.stop() + player_fw_storage.storage = {} logger.exception('Radio force stopped') break @@ -180,7 +181,7 @@ def radio_get_track(radio_session_id): else: track = radio_context.get('track') listen_url = track['listen_url'] - audio_info[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') diff --git a/src/mpv_control.py b/src/mpv_control.py index 7ec2f42..4ab33c4 100644 --- a/src/mpv_control.py +++ b/src/mpv_control.py @@ -32,7 +32,7 @@ def track_url_to_uuid(listen_url=None): @logger.catch def player_menu(header='', storage={}): - player_fw_storage.storage = storage + player_fw_storage.storage.update(storage) player.volume = get_config("mpv_volume") while True: try: @@ -61,7 +61,7 @@ def player_menu(header='', storage={}): name_downloaded = download_track(player.stream_open_filename) print(f'Downloaded: {name_downloaded}') elif select == 'Info': - track = storage.get(track_url_to_uuid()) + track = player_fw_storage.storage.get(track_url_to_uuid()) for i in track.keys(): if i in ('album', 'artist'): name_aa = track.get(i).get('name') @@ -73,13 +73,14 @@ def player_menu(header='', storage={}): print(i + ': ' + key) input() elif select == 'Like': - src.fw_api.favorite_track(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': - track = 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'}}) elif select == 'Exit': player.playlist_clear() player.stop() + player_fw_storage.storage = {} break except KeyboardInterrupt: break