This commit is contained in:
localhost_frssoft 2022-11-18 13:22:55 +03:00
parent e653cf27fe
commit 1f502ef52a
6 changed files with 35 additions and 24 deletions

View File

@ -1,7 +1,7 @@
import src.fw_artists
from src.fw_api import get_artists, get_tracks, get_albums, concatinate_endpoint
from src.settings import get_config
from src.mpv_control import player, player_menu
from src.mpv_control import player, player_menu, track_url_to_uuid
from pyfzf.pyfzf import FzfPrompt
from loguru import logger
@ -63,6 +63,6 @@ def play_album(album_id):
storage = {}
for i in tracks_results:
listen_url = concatinate_endpoint(i.get('listen_url'))
storage[listen_url] = i
storage[track_url_to_uuid(listen_url)] = i
player.loadfile(listen_url, 'append-play')
player_menu("Album playing...", storage)

View File

@ -1,6 +1,6 @@
from src.fw_api import get_artists, get_tracks, concatinate_endpoint
from src.fw_albums import list_albums
from src.mpv_control import player, player_menu
from src.mpv_control import player, player_menu, track_url_to_uuid
from pyfzf.pyfzf import FzfPrompt
from loguru import logger
@ -49,11 +49,11 @@ def play_artist(artist_id):
tracks_next = tracks.get('next')
for i in tracks_results:
listen_url = concatinate_endpoint(i.get('listen_url'))
storage[listen_url] = i
storage[track_url_to_uuid(listen_url)] = i
player.loadfile(listen_url, 'append-play')
if tracks_next:
tracks = get_tracks(artist=artist_id, include_channels=True, pg=tracks_next)
else:
break
artist_name = tracks.get('results')[0].get('artist').get('name')
artist_name = tracks.get('results')[0]['artist']['name']
player_menu(f"Artist {artist_name} playing...", storage)

View File

@ -1,5 +1,5 @@
from src.fw_api import get_playlists, get_playlist_tracks, concatinate_endpoint
from src.mpv_control import player, player_menu
from src.mpv_control import player, player_menu, track_url_to_uuid
from pyfzf.pyfzf import FzfPrompt
from loguru import logger
@ -48,7 +48,7 @@ def play_playlist(playlist_id):
for i in tracks_results:
track = i.get('track')
listen_url = concatinate_endpoint(track['listen_url'])
storage[listen_url] = track
storage[track_url_to_uuid(listen_url)] = track
player.loadfile(listen_url, 'append-play')
if tracks_next:
tracks = get_playlist_tracks(playlist=playlist_id, pg=tracks_next)

View File

@ -1,7 +1,7 @@
from src.fw_api import s, get_radios, post_radio_session, get_track_radio, list_libraries, concatinate_endpoint
from src.fw_api import s, get_radios, post_radio_session, get_track_radio, list_libraries, concatinate_endpoint, favorite_track
from src.fw_libraries import libraries
from src.utils import download_track
from src.mpv_control import player
from src.mpv_control import player, track_url_to_uuid
from src.settings import get_config
from pyfzf.pyfzf import FzfPrompt
from loguru import logger
@ -95,40 +95,43 @@ def radio_load(id_radio=None, type_radio='custom', name=None, related_object=Non
radio_event_gen.set()
radio_task = threading.Thread(target=radio_generator, args=(radio_session_id,), daemon=True)
radio_task.start()
player_items_menu = ['Next', 'Prev', 'Pause', 'Download', 'Info']
if show_like_button:
player_items_menu.append('Like')
player_items_menu.extend(['Hide artist', 'Exit'])
while True:
try:
player_items_menu = ['Next', 'Prev', 'Pause',
'Download', 'Info']
if show_like_button:
player_items_menu.append('Like')
player_items_menu.extend(['Hide artist', 'Exit'])
select = fzf.prompt(player_items_menu, f"--header=\'Radio {name} playing...\'")[0]
if select == 'Next':
threading.Thread(target=radio_get_track, args=(radio_session_id,), daemon=True).start()
player.playlist_next()
elif select == 'Prev':
player.playlist_prev()
elif select == 'Pause':
elif select in ('Pause', 'Play'):
if player.pause:
player_items_menu[2] = 'Pause'
player.pause = False
else:
player_items_menu[2] = 'Play'
player.pause = True
elif select == 'Download':
print('Downloading...')
name_downloaded = download_track(player.filename)
print(f'Downloaded: {name_downloaded}')
elif select == 'Info':
track = audio_info.get(player.filename)
track = audio_info.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.get(i).get('title')
name_aa = track[i]['title']
print(i + ': '+ name_aa)
key = track.get(i)
if key and isinstance(key, str):
print(i + ': ' + key)
input()
elif select == 'Like':
favorite_track(audio_info.get(track_url_to_uuid())['id'])
elif select == 'Exit':
try:
radio_event_gen.clear()
@ -165,7 +168,7 @@ def radio_get_track(radio_session_id):
else:
track = radio_context.get('track')
listen_url = track.get('listen_url')
audio_info[concatinate_endpoint(listen_url)] = track
audio_info[track_url_to_uuid(listen_url)] = track
player.loadfile(concatinate_endpoint(listen_url), 'append-play')

View File

@ -1,5 +1,5 @@
from src.fw_api import get_tracks, concatinate_endpoint
from src.mpv_control import player, player_menu
from src.mpv_control import player, player_menu, track_url_to_uuid
from pyfzf.pyfzf import FzfPrompt
from loguru import logger
@ -36,7 +36,7 @@ def list_tracks(pg=None, search=None):
def play_track(track):
storage = {}
listen_url = concatinate_endpoint(track.get('listen_url'))
storage[listen_url] = track
storage[track_url_to_uuid(listen_url)] = track
player.loadfile(listen_url, 'append-play')
track_name = track.get('title')
player_menu(f"{track_name} playing...", storage)

View File

@ -21,6 +21,14 @@ def set_http_header(headers=[]):
player.http_header_fields = headers
def track_url_to_uuid(listen_url=None):
if listen_url:
uuid = listen_url.split(r'/')[-2]
else:
uuid = player.filename.split(r'/')[-2]
return uuid
@logger.catch
def player_menu(header='', storage={}):
player_fw_storage.storage = storage
@ -48,8 +56,8 @@ def player_menu(header='', storage={}):
name_downloaded = download_track(player.filename)
print(f'Downloaded: {name_downloaded}')
elif select == 'Info':
track = storage.get(player.filename)
for i in ('title', 'fid', 'license', 'album', 'artist'):
track = 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:
@ -60,9 +68,9 @@ def player_menu(header='', storage={}):
print(i + ': ' + key)
input()
elif select == 'Like':
src.fw_api.favorite_track(storage.get(player.filename).get('id'))
src.fw_api.favorite_track(storage.get(track_url_to_uuid())['id'])
elif select == 'Hide artist':
track = storage.get(player.filename)
track = storage.get(track_url_to_uuid())
src.fw_api.hide_content({'target': {'id': track.get('artist').get('id'), 'type': 'artist'}})
elif select == 'Exit':
player.playlist_clear()