From 4aa1476a8188757413d27eeff273a5ca72679092 Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Wed, 21 Dec 2022 23:08:46 +0300 Subject: [PATCH] Some visual changes in mpv console osd --- src/fw_radios.py | 4 +++- src/mpv_control.py | 21 +++++++++++++++++---- src/utils.py | 6 ++++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/fw_radios.py b/src/fw_radios.py index 0e66bd1..6e6dc48 100644 --- a/src/fw_radios.py +++ b/src/fw_radios.py @@ -8,6 +8,7 @@ from pyfzf.pyfzf import FzfPrompt from loguru import logger import threading import time +import sys fzf = FzfPrompt() @@ -84,7 +85,8 @@ def radio_generator(radio_session_id): player.playlist_current_pos if playlist_remaining <= 2: radio_get_track(radio_session_id) - logger.info('Radio generator stopped') + sys.stdout.write('\rRadio generator stopped') + sys.stdout.flush() radio_event_gen = threading.Event() diff --git a/src/mpv_control.py b/src/mpv_control.py index d78b6a3..820d0b7 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 +from src.utils import download_track, print_there from src.settings import get_config from loguru import logger from pyfzf.pyfzf import FzfPrompt @@ -58,9 +58,22 @@ def osd_observer(_name, value): for i in value.items(): if i[0] in ('Artist', 'Album', 'Title'): osd_message.append(i[1]) - sys.stdout.write('\r ') - sys.stdout.write('\r'+' — '.join(osd_message)) - sys.stdout.flush() + print_there(0, 0, '\r ') + print_there(0, 0, '\r'+' — '.join(osd_message)) + + +@player.property_observer('percent-pos') +@logger.catch +def universal_observer(_name, value): + if value: + if player.audio_bitrate: + kbps = round(player.audio_bitrate/1024, 1) + else: + kbps = '?' + percent = int(value) + track_size = round(player.file_size/1024/1024, 1) + print_there(2, 2, f'\r{kbps} kbps | {percent}% | {track_size}Mb') + time.sleep(1) def set_http_header(headers=[]): diff --git a/src/utils.py b/src/utils.py index a2f6cf5..aafd15a 100644 --- a/src/utils.py +++ b/src/utils.py @@ -37,3 +37,9 @@ def download_track(url, name=None): sys.stdout.write("\r[%s%s]" % ('=' * done, ' ' * (50-done))) sys.stdout.flush() return name + + +def print_there(x, y, text): + '''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()