mirror of
http://gitea.phreedom.club/localhost_frssoft/funkwlmpv
synced 2024-11-21 18:41:28 +00:00
Correct way for get configurable listen url track
This commit is contained in:
parent
1f502ef52a
commit
d56630b71e
|
@ -1,5 +1,5 @@
|
|||
import src.fw_artists
|
||||
from src.fw_api import get_artists, get_tracks, get_albums, concatinate_endpoint
|
||||
from src.fw_api import get_artists, get_tracks, get_albums, get_audio_file
|
||||
from src.settings import get_config
|
||||
from src.mpv_control import player, player_menu, track_url_to_uuid
|
||||
from pyfzf.pyfzf import FzfPrompt
|
||||
|
@ -62,7 +62,7 @@ def play_album(album_id):
|
|||
tracks_results = tracks.get('results')
|
||||
storage = {}
|
||||
for i in tracks_results:
|
||||
listen_url = concatinate_endpoint(i.get('listen_url'))
|
||||
listen_url = get_audio_file(i['listen_url'], True)
|
||||
storage[track_url_to_uuid(listen_url)] = i
|
||||
player.loadfile(listen_url, 'append-play')
|
||||
player_menu("Album playing...", storage)
|
||||
|
|
|
@ -58,8 +58,19 @@ def select_instance(new_instance=None):
|
|||
set_http_header(['Authorization: ' + 'Bearer ' + token])
|
||||
|
||||
|
||||
def concatinate_endpoint(endpoint):
|
||||
return 'https://' + instance + endpoint
|
||||
@logger.catch
|
||||
def get_audio_file(track_uuid, listen_url=False, download=False, transcoding=False, to='ogg'):
|
||||
if not transcoding:
|
||||
to = None
|
||||
params = {
|
||||
"download": download,
|
||||
"to": to
|
||||
}
|
||||
if listen_url:
|
||||
r = s.head(f'https://{instance}{track_uuid}', params=params)
|
||||
else:
|
||||
r = s.head(f'https://{instance}/api/v1/listen/{track_uuid}', params=params)
|
||||
return r.url
|
||||
|
||||
|
||||
@logger.catch
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from src.fw_api import get_artists, get_tracks, concatinate_endpoint
|
||||
from src.fw_api import get_artists, get_tracks, get_audio_file
|
||||
from src.fw_albums import list_albums
|
||||
from src.mpv_control import player, player_menu, track_url_to_uuid
|
||||
from pyfzf.pyfzf import FzfPrompt
|
||||
|
@ -48,7 +48,7 @@ def play_artist(artist_id):
|
|||
tracks_results = tracks.get('results')
|
||||
tracks_next = tracks.get('next')
|
||||
for i in tracks_results:
|
||||
listen_url = concatinate_endpoint(i.get('listen_url'))
|
||||
listen_url = get_audio_file(i['listen_url'], True)
|
||||
storage[track_url_to_uuid(listen_url)] = i
|
||||
player.loadfile(listen_url, 'append-play')
|
||||
if tracks_next:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from src.fw_api import get_favorires_tracks, concatinate_endpoint
|
||||
from src.mpv_control import player, player_menu
|
||||
from src.fw_api import get_favorires_tracks, get_audio_file
|
||||
from src.mpv_control import player, player_menu, track_url_to_uuid
|
||||
from pyfzf.pyfzf import FzfPrompt
|
||||
from loguru import logger
|
||||
|
||||
|
@ -49,8 +49,8 @@ Limit the results to a given user or pod:
|
|||
|
||||
def play_track(track):
|
||||
storage = {}
|
||||
listen_url = concatinate_endpoint(track.get('listen_url'))
|
||||
storage[listen_url] = track
|
||||
listen_url = get_audio_file(track['listen_url'], True)
|
||||
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)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from src.fw_api import get_playlists, get_playlist_tracks, concatinate_endpoint
|
||||
from src.fw_api import get_playlists, get_playlist_tracks, get_audio_file
|
||||
from src.mpv_control import player, player_menu, track_url_to_uuid
|
||||
from pyfzf.pyfzf import FzfPrompt
|
||||
from loguru import logger
|
||||
|
@ -47,7 +47,7 @@ def play_playlist(playlist_id):
|
|||
tracks_next = tracks.get('next')
|
||||
for i in tracks_results:
|
||||
track = i.get('track')
|
||||
listen_url = concatinate_endpoint(track['listen_url'])
|
||||
listen_url = get_audio_file(track['listen_url'], True)
|
||||
storage[track_url_to_uuid(listen_url)] = track
|
||||
player.loadfile(listen_url, 'append-play')
|
||||
if tracks_next:
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from src.fw_api import s, get_radios, post_radio_session, get_track_radio, list_libraries, concatinate_endpoint, favorite_track
|
||||
from src.fw_api import s, get_radios, post_radio_session, get_track_radio, list_libraries, favorite_track, get_audio_file
|
||||
from src.fw_libraries import libraries
|
||||
from src.utils import download_track
|
||||
from src.mpv_control import player, track_url_to_uuid
|
||||
|
@ -116,7 +116,7 @@ def radio_load(id_radio=None, type_radio='custom', name=None, related_object=Non
|
|||
player.pause = True
|
||||
elif select == 'Download':
|
||||
print('Downloading...')
|
||||
name_downloaded = download_track(player.filename)
|
||||
name_downloaded = download_track(player.stream_open_filename)
|
||||
print(f'Downloaded: {name_downloaded}')
|
||||
elif select == 'Info':
|
||||
track = audio_info.get(track_url_to_uuid())
|
||||
|
@ -167,8 +167,8 @@ def radio_get_track(radio_session_id):
|
|||
return
|
||||
else:
|
||||
track = radio_context.get('track')
|
||||
listen_url = track.get('listen_url')
|
||||
listen_url = track['listen_url']
|
||||
audio_info[track_url_to_uuid(listen_url)] = track
|
||||
player.loadfile(concatinate_endpoint(listen_url), 'append-play')
|
||||
player.loadfile(get_audio_file(listen_url, listen_url=True), 'append-play')
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from src.fw_api import get_tracks, concatinate_endpoint
|
||||
from src.fw_api import get_tracks, get_audio_file
|
||||
from src.mpv_control import player, player_menu, track_url_to_uuid
|
||||
from pyfzf.pyfzf import FzfPrompt
|
||||
from loguru import logger
|
||||
|
@ -35,7 +35,7 @@ def list_tracks(pg=None, search=None):
|
|||
|
||||
def play_track(track):
|
||||
storage = {}
|
||||
listen_url = concatinate_endpoint(track.get('listen_url'))
|
||||
listen_url = get_audio_file(track['listen_url'], True)
|
||||
storage[track_url_to_uuid(listen_url)] = track
|
||||
player.loadfile(listen_url, 'append-play')
|
||||
track_name = track.get('title')
|
||||
|
|
|
@ -22,10 +22,11 @@ def set_http_header(headers=[]):
|
|||
|
||||
|
||||
def track_url_to_uuid(listen_url=None):
|
||||
'''Attempt get uuid from track listen url or current playing url'''
|
||||
if listen_url:
|
||||
uuid = listen_url.split(r'/')[-2]
|
||||
else:
|
||||
uuid = player.filename.split(r'/')[-2]
|
||||
uuid = player.stream_open_filename.split(r'/')[-2]
|
||||
return uuid
|
||||
|
||||
|
||||
|
@ -53,7 +54,7 @@ def player_menu(header='', storage={}):
|
|||
player.pause = True
|
||||
elif select == 'Download':
|
||||
print('Downloading...')
|
||||
name_downloaded = download_track(player.filename)
|
||||
name_downloaded = download_track(player.stream_open_filename)
|
||||
print(f'Downloaded: {name_downloaded}')
|
||||
elif select == 'Info':
|
||||
track = storage.get(track_url_to_uuid())
|
||||
|
|
|
@ -11,6 +11,7 @@ def get_remote_file_name(url):
|
|||
|
||||
|
||||
def download_track(url, name=None):
|
||||
url = url.split('?')[0] # Stripe all params from url
|
||||
r = src.fw_api.s.get(url)
|
||||
if not name:
|
||||
name = get_remote_file_name(url)
|
||||
|
|
Loading…
Reference in a new issue