From 3b8d67cbf8943bf5c713ac318798f73c14b52870 Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Tue, 8 Nov 2022 21:37:43 +0300 Subject: [PATCH] gzipped API reqests; more logger catchers; fix play all albums in main menu --- src/fw_albums.py | 6 +++++- src/fw_api.py | 10 +++++++--- src/fw_radios.py | 2 ++ src/mpv_control.py | 2 +- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/fw_albums.py b/src/fw_albums.py index 0741862..b128c96 100644 --- a/src/fw_albums.py +++ b/src/fw_albums.py @@ -10,14 +10,18 @@ fzf = FzfPrompt() def list_albums(albums=None, pg=None): albums_next = None albums_prev = None + play_artist_albums = False if not albums: albums = get_albums(pg=pg) albums_next = albums.get('next') albums_prev = albums.get('previous') albums_results = albums.get('results') else: + play_artist_albums = True albums_results = albums - view = ['Play all'] + view = [] + if play_artist_albums: + view.append('Play all') if albums_next: view.append('Next page') if albums_prev: diff --git a/src/fw_api.py b/src/fw_api.py index c490bc4..9115bb1 100644 --- a/src/fw_api.py +++ b/src/fw_api.py @@ -11,10 +11,12 @@ token = auth.get(instance) if token: s.headers.update({ - "Authorization": "Bearer " + token + "Authorization": "Bearer " + token, + "Accept-encoding": 'gzip' }) set_http_header(['Authorization: ' + 'Bearer ' + token]) else: + s.headers.update({"Accept-encoding": 'gzip'}) s.get(f'https://{instance}/') # Get cookies from unauthorized instance for working some functionality (radios) set_http_header() @@ -25,12 +27,14 @@ def select_instance(new_instance=None): with open('.auth.json', 'rt') as f: auth = json.loads(f.read()) new_token = auth.get(instance) - s.headers.update({"Authorization": None}) + s.headers.update({"Authorization": None, + "Accept-encoding": 'gzip'}) set_http_header() if new_token: s.get(f'https://{instance}') s.headers.update({ - "Authorization": "Bearer " + new_token + "Authorization": "Bearer " + new_token, + "Accept-encoding": 'gzip' }) player.http_header_fields = ['Authorization: ' + 'Bearer ' + new_token] set_http_header(['Authorization: ' + 'Bearer ' + token]) diff --git a/src/fw_radios.py b/src/fw_radios.py index 8e663e1..295f356 100644 --- a/src/fw_radios.py +++ b/src/fw_radios.py @@ -71,6 +71,8 @@ def radio_generator(radio_session_id): radio_event_gen = threading.Event() + +@logger.catch def radio_load(id_radio=None, type_radio='custom', name=None, related_object=None): requested_radio = { 'custom_radio': id_radio, diff --git a/src/mpv_control.py b/src/mpv_control.py index a0756f6..6475cc8 100644 --- a/src/mpv_control.py +++ b/src/mpv_control.py @@ -19,7 +19,7 @@ player = mpv.MPV(log_handler=mpv_log, ytdl=False, def set_http_header(headers=[]): player.http_header_fields = headers - +@logger.catch def player_menu(header=None, storage={}): while True: try: