mirror of
http://gitea.phreedom.club/localhost_frssoft/funkwlmpv
synced 2024-12-01 21:46:33 +00:00
Compare commits
2 commits
a794cb4f5a
...
6c5113abcc
Author | SHA1 | Date | |
---|---|---|---|
localhost_frssoft | 6c5113abcc | ||
localhost_frssoft | b835454f11 |
|
@ -126,9 +126,7 @@ def radio_load(id_radio=None, type_radio='custom', name=None, related_object=Non
|
||||||
else:
|
else:
|
||||||
player.pause = True
|
player.pause = True
|
||||||
elif select == 'Download':
|
elif select == 'Download':
|
||||||
print('Downloading...')
|
|
||||||
name_downloaded = download_track(player.stream_open_filename)
|
name_downloaded = download_track(player.stream_open_filename)
|
||||||
print(f'Downloaded: {name_downloaded}')
|
|
||||||
elif select == 'Info':
|
elif select == 'Info':
|
||||||
track = player_fw_storage.storage.get(track_url_to_uuid())
|
track = player_fw_storage.storage.get(track_url_to_uuid())
|
||||||
for i in ('title', 'fid', 'license', 'album', 'artist'):
|
for i in ('title', 'fid', 'license', 'album', 'artist'):
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from src.fw_api import get_tracks, get_audio_file
|
from src.fw_api import get_tracks, get_audio_file
|
||||||
from src.fw_tags import list_tags
|
from src.fw_tags import list_tags
|
||||||
from src.mpv_control import player, player_menu, track_url_to_uuid
|
from src.mpv_control import player, player_menu, track_url_to_uuid, play_track
|
||||||
from pyfzf.pyfzf import FzfPrompt
|
from pyfzf.pyfzf import FzfPrompt
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ def list_tracks(pg=None, search=None, tag=None):
|
||||||
tracks_next = tracks.get('next')
|
tracks_next = tracks.get('next')
|
||||||
tracks_prev = tracks.get('previous')
|
tracks_prev = tracks.get('previous')
|
||||||
tracks_results = tracks.get('results')
|
tracks_results = tracks.get('results')
|
||||||
view = ['Search', 'Tags']
|
view = ['Search', 'Tags', 'Play this page']
|
||||||
if tracks_next:
|
if tracks_next:
|
||||||
view.append('Next page')
|
view.append('Next page')
|
||||||
if tracks_prev:
|
if tracks_prev:
|
||||||
|
@ -33,14 +33,9 @@ def list_tracks(pg=None, search=None, tag=None):
|
||||||
elif select == 'Tags':
|
elif select == 'Tags':
|
||||||
select_tag = list_tags()
|
select_tag = list_tags()
|
||||||
list_tracks(tag=select_tag)
|
list_tracks(tag=select_tag)
|
||||||
|
elif select == 'Play this page':
|
||||||
|
for i in tracks_results:
|
||||||
|
play_track(track=i, multi=True)
|
||||||
else:
|
else:
|
||||||
play_track(track=tracks_results[int(select)])
|
play_track(track=tracks_results[int(select)])
|
||||||
|
|
||||||
|
|
||||||
def play_track(track):
|
|
||||||
storage = {}
|
|
||||||
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)
|
|
||||||
|
|
|
@ -78,9 +78,7 @@ def player_menu(header='', storage={}):
|
||||||
else:
|
else:
|
||||||
player.pause = True
|
player.pause = True
|
||||||
elif select == 'Download':
|
elif select == 'Download':
|
||||||
print('Downloading...')
|
|
||||||
name_downloaded = download_track(player.stream_open_filename)
|
name_downloaded = download_track(player.stream_open_filename)
|
||||||
print(f'Downloaded: {name_downloaded}')
|
|
||||||
elif select == 'Info':
|
elif select == 'Info':
|
||||||
track = player_fw_storage.storage.get(track_url_to_uuid())
|
track = player_fw_storage.storage.get(track_url_to_uuid())
|
||||||
for i in track.keys():
|
for i in track.keys():
|
||||||
|
@ -106,3 +104,13 @@ def player_menu(header='', storage={}):
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
|
def play_track(track, multi=False):
|
||||||
|
listen_url = src.fw_api.get_audio_file(track['listen_url'], True)
|
||||||
|
player_fw_storage.storage[track_url_to_uuid(listen_url)] = track
|
||||||
|
if multi:
|
||||||
|
player.loadfile(listen_url, 'append-play')
|
||||||
|
else:
|
||||||
|
player.loadfile(listen_url, 'append-play')
|
||||||
|
track_name = track.get('title')
|
||||||
|
player_menu(f"{track_name} playing...", player_fw_storage.storage)
|
||||||
|
|
19
src/utils.py
19
src/utils.py
|
@ -1,4 +1,6 @@
|
||||||
import src.fw_api
|
import src.fw_api
|
||||||
|
|
||||||
|
import sys
|
||||||
from urllib.parse import unquote
|
from urllib.parse import unquote
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,12 +14,25 @@ def get_remote_file_name(url):
|
||||||
|
|
||||||
def download_track(url, name=None):
|
def download_track(url, name=None):
|
||||||
url = url.split('?')[0] # Stripe all params from url
|
url = url.split('?')[0] # Stripe all params from url
|
||||||
r = src.fw_api.current_instance.s.get(url)
|
r = src.fw_api.current_instance.s.get(url, stream=True)
|
||||||
if not name:
|
if not name:
|
||||||
name = get_remote_file_name(url)
|
name = get_remote_file_name(url)
|
||||||
if not name:
|
if not name:
|
||||||
name = url.split(r'/')[-1]
|
name = url.split(r'/')[-1]
|
||||||
|
|
||||||
with open(name.replace(r'/', '_'), 'wb') as f:
|
with open(name.replace('/', '_'), 'wb') as f:
|
||||||
|
print(f"Downloading {name}")
|
||||||
|
total_length = r.headers.get('content-length')
|
||||||
|
|
||||||
|
if total_length is None: # no content length header
|
||||||
f.write(r.content)
|
f.write(r.content)
|
||||||
|
else:
|
||||||
|
dl = 0
|
||||||
|
total_length = int(total_length)
|
||||||
|
for data in r.iter_content(chunk_size=4096):
|
||||||
|
dl += len(data)
|
||||||
|
f.write(data)
|
||||||
|
done = int(50 * dl / total_length)
|
||||||
|
sys.stdout.write("\r[%s%s]" % ('=' * done, ' ' * (50-done)) ) # base progress bar
|
||||||
|
sys.stdout.flush()
|
||||||
return name
|
return name
|
||||||
|
|
Loading…
Reference in a new issue