Correct integration shared player storage for tracks

This commit is contained in:
localhost_frssoft 2022-12-08 02:24:48 +03:00
parent 55fe364842
commit 06fd6308fe
2 changed files with 11 additions and 9 deletions

View file

@ -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')

View file

@ -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