From abf0b7f4c05ab682f200ba741975ff9efa01af9a Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Sun, 11 Jun 2023 00:54:26 +0300 Subject: [PATCH] Track info output refactor --- src/fw_radios.py | 12 ++---------- src/mpv_control.py | 12 ++---------- src/utils.py | 14 +++++++++++++- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/fw_radios.py b/src/fw_radios.py index ba2c95d..25228cc 100644 --- a/src/fw_radios.py +++ b/src/fw_radios.py @@ -1,7 +1,7 @@ from src.fw_api import current_instance, get_radios, post_radio_session, get_track_radio, list_libraries, favorite_track, get_audio_file, hide_content from src.fw_libraries import libraries from src.fw_tags import list_tags -from src.utils import download_track +from src.utils import download_track, track_info_output from src.mpv_control import player, track_url_to_uuid, player_fw_storage from src.settings import get_config from pyfzf.pyfzf import FzfPrompt @@ -148,15 +148,7 @@ def radio_load(id_radio=None, type_radio='custom', name=None, related_object=Non name_downloaded = download_track(player.stream_open_filename) elif select == 'Info': 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') - if not name_aa: - name_aa = track[i]['title'] - print(i + ': ' + name_aa) - key = track.get(i) - if key and isinstance(key, str): - print(i + ': ' + key) + track_info_output(track) print('Direct link: ' + player.stream_open_filename) input() elif select == 'Like': diff --git a/src/mpv_control.py b/src/mpv_control.py index 0791b51..a950a04 100644 --- a/src/mpv_control.py +++ b/src/mpv_control.py @@ -1,5 +1,5 @@ import src.fw_api -from src.utils import download_track, print_there +from src.utils import download_track, print_there, track_info_output from src.settings import get_config from loguru import logger from pyfzf.pyfzf import FzfPrompt @@ -147,15 +147,7 @@ def player_menu(header='', storage={}): name_downloaded = download_track(player.stream_open_filename) elif select == 'Info': 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') - if not name_aa: - name_aa = track.get(i).get('title') - print(i + ': ' + name_aa) - key = track.get(i) - if key and isinstance(key, str): - print(i + ': ' + key) + track_info_output(track) print('Direct link: ' + player.stream_open_filename) input() elif select == 'Like': diff --git a/src/utils.py b/src/utils.py index f81c846..1d7391e 100644 --- a/src/utils.py +++ b/src/utils.py @@ -51,6 +51,18 @@ def copy_from_cache(url_file): def print_there(x, y, text): - '''Print at position x, y caption in terminal (? Linux only)''' + '''Print at position x, y caption in terminal (Linux only)''' sys.stdout.write("\x1b7\x1b[%d;%df%s\x1b8" % (x, y, text)) sys.stdout.flush() + + +def track_info_output(track): + for k, v in track.items(): + if k not in ('cover', 'uploads', 'listen_url', 'mbid', 'id', 'is_playable') and v is not None and v != []: + if isinstance(v, dict): + for i in ('title', 'name', 'fid'): + if v.get(i): + val_override = v.get(i) + print(f'{k}: {val_override}') + else: + print(f'{k}: {v}')