Added partially working tracks list; Removed mpv logger func

This commit is contained in:
localhost_frssoft 2022-11-11 01:42:29 +03:00
parent 522a6e36b8
commit 93380080d0
3 changed files with 46 additions and 7 deletions

View File

@ -2,6 +2,7 @@ from src.fw_api import s, select_instance, instance, federate_search_by_url
from src.fw_radios import list_radios from src.fw_radios import list_radios
from src.fw_artists import list_artists from src.fw_artists import list_artists
from src.fw_albums import list_albums from src.fw_albums import list_albums
from src.fw_tracks import list_tracks
from src.fw_channels import list_channels from src.fw_channels import list_channels
from src.fw_playlists import list_playlists from src.fw_playlists import list_playlists
import src.settings as settings import src.settings as settings
@ -16,6 +17,7 @@ def main():
menu = ['Radios', menu = ['Radios',
'Artists', 'Artists',
'Albums', 'Albums',
'Tracks',
'Channels', 'Channels',
'Playlists', 'Playlists',
'Search', 'Search',
@ -31,6 +33,8 @@ def main():
list_artists() list_artists()
if selected == 'Albums': if selected == 'Albums':
list_albums() list_albums()
if selected == 'Tracks':
list_tracks()
if selected == 'Channels': if selected == 'Channels':
list_channels() list_channels()
if selected == 'Playlists': if selected == 'Playlists':

42
src/fw_tracks.py Normal file
View File

@ -0,0 +1,42 @@
from src.fw_api import get_tracks, concatinate_endpoint
from src.mpv_control import player, player_menu
from pyfzf.pyfzf import FzfPrompt
from loguru import logger
fzf = FzfPrompt()
@logger.catch
def list_tracks(pg=None, search=None):
tracks = get_tracks(q=search, pg=pg)
tracks_next = tracks.get('next')
tracks_prev = tracks.get('previous')
tracks_results = tracks.get('results')
view = ['Search']
if tracks_next:
view.append('Next page')
if tracks_prev:
view.append('Prev page')
for i in tracks_results:
index = tracks_results.index(i)
track_name = i.get('title')
view.append(f'{index}.{track_name}')
select = fzf.prompt(view)[0].split('.', 1)[0]
if select == 'Next page':
list_tracks(pg=tracks_next)
elif select == 'Prev page':
list_tracks(pg=tracks_prev)
elif select == 'Search':
print('Search by track:')
list_tracks(search=input())
else:
play_track(track=tracks_results[int(select)])
def play_track(track):
storage = {}
listen_url = concatinate_endpoint(track.get('listen_url'))
storage[listen_url] = track
player.loadfile(listen_url, 'append-play')
track_name = track.get('title')
player_menu(f"{track_name} playing...", storage)

View File

@ -7,13 +7,6 @@ import mpv
fzf = FzfPrompt() fzf = FzfPrompt()
def mpv_log(loglevel, component, message):
if loglevel == 'info':
logger.info(f'{component} {message}')
elif loglevel == 'error':
logger.error(f'{component} {message}')
player = mpv.MPV() player = mpv.MPV()
player.ytdl = False # Prevent attempts load track with yt-dlp player.ytdl = False # Prevent attempts load track with yt-dlp
player.prefetch_playlist = get_config('prefetch_playlist') # Fast loading next track, but high network traffic player.prefetch_playlist = get_config('prefetch_playlist') # Fast loading next track, but high network traffic