mirror of
https://gitea.phreedom.club/localhost_frssoft/funkwlmpv
synced 2024-11-23 23:19:21 +02:00
Compare commits
No commits in common. "9c65117e9c6452b13cb7ca1859004987d23a4ea5" and "220717d522e72bd7233a8ee7ee3bab7fb83be85b" have entirely different histories.
9c65117e9c
...
220717d522
|
@ -1,5 +1,3 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from src.fw_api import current_instance, federate_search_by_url, get_instance_settings
|
||||
from src.fw_radios import list_radios
|
||||
from src.fw_artists import list_artists
|
||||
|
@ -87,7 +85,7 @@ def main():
|
|||
If You want sign in, please visit:
|
||||
https://{instance}/settings/applications/new
|
||||
And fill Name funkwhale-cli
|
||||
Scopes: Read, Write (optional): write:favorites write:listenings write:filters
|
||||
Scopes: Read (only listen music), Write (optional)
|
||||
|
||||
Insert token from "Access token" here''')
|
||||
register_token = input()
|
||||
|
|
|
@ -230,16 +230,6 @@ def federate_search_by_url(object):
|
|||
return r.json()
|
||||
|
||||
|
||||
@logger.catch
|
||||
def record_track_in_history(track_id):
|
||||
params = {
|
||||
'track': int(track_id)
|
||||
}
|
||||
r = current_instance.s.post(f'https://{current_instance.instance}/api/v1/history/listenings', json=params)
|
||||
r.raise_for_status()
|
||||
return r.json
|
||||
|
||||
|
||||
@logger.catch
|
||||
def favorite_track(track_id):
|
||||
r = current_instance.s.post(f'https://{current_instance.instance}/api/v1/favorites/tracks', json={'track': int(track_id)})
|
||||
|
|
|
@ -2,7 +2,7 @@ from src.fw_api import current_instance, get_radios, post_radio_session, get_tra
|
|||
from src.fw_libraries import libraries
|
||||
from src.fw_tags import list_tags
|
||||
from src.utils import download_track
|
||||
from src.mpv_control import player, track_url_to_uuid, player_fw_storage
|
||||
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
|
||||
|
@ -11,6 +11,7 @@ import time
|
|||
|
||||
fzf = FzfPrompt()
|
||||
|
||||
audio_info = {}
|
||||
|
||||
@logger.catch
|
||||
def list_radios():
|
||||
|
@ -130,7 +131,7 @@ def radio_load(id_radio=None, type_radio='custom', name=None, related_object=Non
|
|||
name_downloaded = download_track(player.stream_open_filename)
|
||||
print(f'Downloaded: {name_downloaded}')
|
||||
elif select == 'Info':
|
||||
track = player_fw_storage.storage.get(track_url_to_uuid())
|
||||
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')
|
||||
|
@ -142,7 +143,7 @@ def radio_load(id_radio=None, type_radio='custom', name=None, related_object=Non
|
|||
print(i + ': ' + key)
|
||||
input()
|
||||
elif select == 'Like':
|
||||
favorite_track(player_fw_storage.storage.get(track_url_to_uuid())['id'])
|
||||
favorite_track(audio_info.get(track_url_to_uuid())['id'])
|
||||
elif select == 'Exit':
|
||||
try:
|
||||
radio_event_gen.clear()
|
||||
|
@ -151,7 +152,6 @@ def radio_load(id_radio=None, type_radio='custom', name=None, related_object=Non
|
|||
pass
|
||||
player.playlist_clear()
|
||||
player.stop()
|
||||
player_fw_storage.storage = {}
|
||||
break
|
||||
except:
|
||||
try:
|
||||
|
@ -161,7 +161,6 @@ def radio_load(id_radio=None, type_radio='custom', name=None, related_object=Non
|
|||
pass
|
||||
player.playlist_clear()
|
||||
player.stop()
|
||||
player_fw_storage.storage = {}
|
||||
logger.exception('Radio force stopped')
|
||||
break
|
||||
|
||||
|
@ -181,7 +180,7 @@ def radio_get_track(radio_session_id):
|
|||
else:
|
||||
track = radio_context.get('track')
|
||||
listen_url = track['listen_url']
|
||||
player_fw_storage.storage[track_url_to_uuid(listen_url)] = track
|
||||
audio_info[track_url_to_uuid(listen_url)] = track
|
||||
player.loadfile(get_audio_file(listen_url, listen_url=True), 'append-play')
|
||||
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ from src.settings import get_config
|
|||
from loguru import logger
|
||||
from pyfzf.pyfzf import FzfPrompt
|
||||
import mpv
|
||||
import time
|
||||
|
||||
fzf = FzfPrompt()
|
||||
|
||||
|
@ -12,14 +11,16 @@ player = mpv.MPV()
|
|||
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
|
||||
show_like_button = get_config('show_like_button')
|
||||
track_activity_history = get_config('track_activity_history')
|
||||
|
||||
|
||||
class player_fw_storage:
|
||||
storage = {}
|
||||
|
||||
|
||||
@logger.catch
|
||||
def set_http_header(headers=[]):
|
||||
player.http_header_fields = headers
|
||||
|
||||
|
||||
def track_url_to_uuid(listen_url=None):
|
||||
'''Attempt get uuid from track listen url or current playing url'''
|
||||
if listen_url:
|
||||
|
@ -29,31 +30,9 @@ def track_url_to_uuid(listen_url=None):
|
|||
return uuid
|
||||
|
||||
|
||||
if track_activity_history:
|
||||
@player.property_observer('time-pos')
|
||||
@logger.catch
|
||||
def time_observer(_name, value):
|
||||
# Here, _value is either None if nothing is playing or a float containing
|
||||
# fractional seconds since the beginning of the file.
|
||||
if value and player.http_header_fields != []:
|
||||
if value >= 30.0 and value <= 30.1:
|
||||
# detect 30 secs for reporting listen activity
|
||||
track = player_fw_storage.storage.get(track_url_to_uuid())
|
||||
track_id = track.get('id')
|
||||
if track_id:
|
||||
src.fw_api.record_track_in_history(track_id)
|
||||
else:
|
||||
logger.error("Can't write track to history: No track id")
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
def set_http_header(headers=[]):
|
||||
player.http_header_fields = headers
|
||||
|
||||
|
||||
@logger.catch
|
||||
def player_menu(header='', storage={}):
|
||||
player_fw_storage.storage.update(storage)
|
||||
player_fw_storage.storage = storage
|
||||
player.volume = get_config("mpv_volume")
|
||||
while True:
|
||||
try:
|
||||
|
@ -82,7 +61,7 @@ def player_menu(header='', storage={}):
|
|||
name_downloaded = download_track(player.stream_open_filename)
|
||||
print(f'Downloaded: {name_downloaded}')
|
||||
elif select == 'Info':
|
||||
track = player_fw_storage.storage.get(track_url_to_uuid())
|
||||
track = storage.get(track_url_to_uuid())
|
||||
for i in track.keys():
|
||||
if i in ('album', 'artist'):
|
||||
name_aa = track.get(i).get('name')
|
||||
|
@ -94,14 +73,13 @@ def player_menu(header='', storage={}):
|
|||
print(i + ': ' + key)
|
||||
input()
|
||||
elif select == 'Like':
|
||||
src.fw_api.favorite_track(player_fw_storage.storage.get(track_url_to_uuid())['id'])
|
||||
src.fw_api.favorite_track(storage.get(track_url_to_uuid())['id'])
|
||||
elif select == 'Hide artist':
|
||||
track = player_fw_storage.storage.get(track_url_to_uuid())
|
||||
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()
|
||||
player.stop()
|
||||
player_fw_storage.storage = {}
|
||||
break
|
||||
except KeyboardInterrupt:
|
||||
break
|
||||
|
|
|
@ -39,7 +39,6 @@ default_conf = {
|
|||
"shitnoise.monster"
|
||||
],
|
||||
'enable_server_transcoding': False,
|
||||
'track_activity_history': False,
|
||||
'prefetch_playlist': True,
|
||||
'mpv_volume': 100,
|
||||
'show_like_button': True,
|
||||
|
|
Loading…
Reference in New Issue