Some fixes in observer's; add show caching speed

This commit is contained in:
localhost_frssoft 2022-12-22 13:27:23 +03:00
parent 640242dad5
commit de40f9027d

View File

@ -3,6 +3,7 @@ from src.utils import download_track, print_there
from src.settings import get_config
from loguru import logger
from pyfzf.pyfzf import FzfPrompt
from shutil import get_terminal_size
import mpv
import time
import sys
@ -59,7 +60,12 @@ def osd_observer(_name, value):
if i[0] in ('Artist', 'Album', 'Title'):
osd_message.append(i[1])
print_there(0, 0, '\r ')
print_there(0, 0, '\r'+''.join(osd_message))
osd_string = ''.join(osd_message)
term_len = get_terminal_size().columns
print_there(0, 0, '\r'+osd_string[term_len:])
else:
if not player.core_idle:
print_there(0, 0, '\r[N/A metadata, check info]')
@player.property_observer('stream-open-filename')
@ -79,8 +85,17 @@ def universal_observer(_name, value):
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')
if player.file_size:
track_size = round(player.file_size/1024/1024, 1)
else:
track_size = '?'
if player.cache_speed:
cache_speed = round(player.cache_speed/1024/1024*8, 1)
cache_speed = f'| caching: ~{cache_speed}Mbit/s'
else:
cache_speed = ''
print_there(2, 2, f'\r'+' '*get_terminal_size().columns)
print_there(2, 2, f'\r{kbps} kbps | {percent}% | {track_size}MB {cache_speed}')
time.sleep(1)