mirror of
http://gitea.phreedom.club/localhost_frssoft/funkwlmpv
synced 2024-12-02 00:46:36 +00:00
Compare commits
4 commits
220717d522
...
9c65117e9c
Author | SHA1 | Date | |
---|---|---|---|
localhost_frssoft | 9c65117e9c | ||
localhost_frssoft | 06fd6308fe | ||
localhost_frssoft | 55fe364842 | ||
localhost_frssoft | b5fe6613a7 |
4
funkwhale_cli.py
Normal file → Executable file
4
funkwhale_cli.py
Normal file → Executable file
|
@ -1,3 +1,5 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from src.fw_api import current_instance, federate_search_by_url, get_instance_settings
|
from src.fw_api import current_instance, federate_search_by_url, get_instance_settings
|
||||||
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
|
||||||
|
@ -85,7 +87,7 @@ def main():
|
||||||
If You want sign in, please visit:
|
If You want sign in, please visit:
|
||||||
https://{instance}/settings/applications/new
|
https://{instance}/settings/applications/new
|
||||||
And fill Name funkwhale-cli
|
And fill Name funkwhale-cli
|
||||||
Scopes: Read (only listen music), Write (optional)
|
Scopes: Read, Write (optional): write:favorites write:listenings write:filters
|
||||||
|
|
||||||
Insert token from "Access token" here''')
|
Insert token from "Access token" here''')
|
||||||
register_token = input()
|
register_token = input()
|
||||||
|
|
|
@ -230,6 +230,16 @@ def federate_search_by_url(object):
|
||||||
return r.json()
|
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
|
@logger.catch
|
||||||
def favorite_track(track_id):
|
def favorite_track(track_id):
|
||||||
r = current_instance.s.post(f'https://{current_instance.instance}/api/v1/favorites/tracks', json={'track': int(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_libraries import libraries
|
||||||
from src.fw_tags import list_tags
|
from src.fw_tags import list_tags
|
||||||
from src.utils import download_track
|
from src.utils import download_track
|
||||||
from src.mpv_control import player, track_url_to_uuid
|
from src.mpv_control import player, track_url_to_uuid, player_fw_storage
|
||||||
from src.settings import get_config
|
from src.settings import get_config
|
||||||
from pyfzf.pyfzf import FzfPrompt
|
from pyfzf.pyfzf import FzfPrompt
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
@ -11,7 +11,6 @@ import time
|
||||||
|
|
||||||
fzf = FzfPrompt()
|
fzf = FzfPrompt()
|
||||||
|
|
||||||
audio_info = {}
|
|
||||||
|
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def list_radios():
|
def list_radios():
|
||||||
|
@ -131,7 +130,7 @@ def radio_load(id_radio=None, type_radio='custom', name=None, related_object=Non
|
||||||
name_downloaded = download_track(player.stream_open_filename)
|
name_downloaded = download_track(player.stream_open_filename)
|
||||||
print(f'Downloaded: {name_downloaded}')
|
print(f'Downloaded: {name_downloaded}')
|
||||||
elif select == 'Info':
|
elif select == 'Info':
|
||||||
track = audio_info.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'):
|
||||||
if i in ('album', 'artist'):
|
if i in ('album', 'artist'):
|
||||||
name_aa = track.get(i).get('name')
|
name_aa = track.get(i).get('name')
|
||||||
|
@ -143,7 +142,7 @@ def radio_load(id_radio=None, type_radio='custom', name=None, related_object=Non
|
||||||
print(i + ': ' + key)
|
print(i + ': ' + key)
|
||||||
input()
|
input()
|
||||||
elif select == 'Like':
|
elif select == 'Like':
|
||||||
favorite_track(audio_info.get(track_url_to_uuid())['id'])
|
favorite_track(player_fw_storage.storage.get(track_url_to_uuid())['id'])
|
||||||
elif select == 'Exit':
|
elif select == 'Exit':
|
||||||
try:
|
try:
|
||||||
radio_event_gen.clear()
|
radio_event_gen.clear()
|
||||||
|
@ -152,6 +151,7 @@ def radio_load(id_radio=None, type_radio='custom', name=None, related_object=Non
|
||||||
pass
|
pass
|
||||||
player.playlist_clear()
|
player.playlist_clear()
|
||||||
player.stop()
|
player.stop()
|
||||||
|
player_fw_storage.storage = {}
|
||||||
break
|
break
|
||||||
except:
|
except:
|
||||||
try:
|
try:
|
||||||
|
@ -161,6 +161,7 @@ def radio_load(id_radio=None, type_radio='custom', name=None, related_object=Non
|
||||||
pass
|
pass
|
||||||
player.playlist_clear()
|
player.playlist_clear()
|
||||||
player.stop()
|
player.stop()
|
||||||
|
player_fw_storage.storage = {}
|
||||||
logger.exception('Radio force stopped')
|
logger.exception('Radio force stopped')
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -180,7 +181,7 @@ def radio_get_track(radio_session_id):
|
||||||
else:
|
else:
|
||||||
track = radio_context.get('track')
|
track = radio_context.get('track')
|
||||||
listen_url = track['listen_url']
|
listen_url = track['listen_url']
|
||||||
audio_info[track_url_to_uuid(listen_url)] = track
|
player_fw_storage.storage[track_url_to_uuid(listen_url)] = track
|
||||||
player.loadfile(get_audio_file(listen_url, listen_url=True), 'append-play')
|
player.loadfile(get_audio_file(listen_url, listen_url=True), 'append-play')
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ from src.settings import get_config
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from pyfzf.pyfzf import FzfPrompt
|
from pyfzf.pyfzf import FzfPrompt
|
||||||
import mpv
|
import mpv
|
||||||
|
import time
|
||||||
|
|
||||||
fzf = FzfPrompt()
|
fzf = FzfPrompt()
|
||||||
|
|
||||||
|
@ -11,16 +12,14 @@ 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
|
||||||
show_like_button = get_config('show_like_button')
|
show_like_button = get_config('show_like_button')
|
||||||
|
track_activity_history = get_config('track_activity_history')
|
||||||
|
|
||||||
|
|
||||||
class player_fw_storage:
|
class player_fw_storage:
|
||||||
storage = {}
|
storage = {}
|
||||||
|
|
||||||
|
|
||||||
def set_http_header(headers=[]):
|
@logger.catch
|
||||||
player.http_header_fields = headers
|
|
||||||
|
|
||||||
|
|
||||||
def track_url_to_uuid(listen_url=None):
|
def track_url_to_uuid(listen_url=None):
|
||||||
'''Attempt get uuid from track listen url or current playing url'''
|
'''Attempt get uuid from track listen url or current playing url'''
|
||||||
if listen_url:
|
if listen_url:
|
||||||
|
@ -30,9 +29,31 @@ def track_url_to_uuid(listen_url=None):
|
||||||
return uuid
|
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
|
@logger.catch
|
||||||
def player_menu(header='', storage={}):
|
def player_menu(header='', storage={}):
|
||||||
player_fw_storage.storage = storage
|
player_fw_storage.storage.update(storage)
|
||||||
player.volume = get_config("mpv_volume")
|
player.volume = get_config("mpv_volume")
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
@ -61,7 +82,7 @@ def player_menu(header='', storage={}):
|
||||||
name_downloaded = download_track(player.stream_open_filename)
|
name_downloaded = download_track(player.stream_open_filename)
|
||||||
print(f'Downloaded: {name_downloaded}')
|
print(f'Downloaded: {name_downloaded}')
|
||||||
elif select == 'Info':
|
elif select == 'Info':
|
||||||
track = 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():
|
||||||
if i in ('album', 'artist'):
|
if i in ('album', 'artist'):
|
||||||
name_aa = track.get(i).get('name')
|
name_aa = track.get(i).get('name')
|
||||||
|
@ -73,13 +94,14 @@ def player_menu(header='', storage={}):
|
||||||
print(i + ': ' + key)
|
print(i + ': ' + key)
|
||||||
input()
|
input()
|
||||||
elif select == 'Like':
|
elif select == 'Like':
|
||||||
src.fw_api.favorite_track(storage.get(track_url_to_uuid())['id'])
|
src.fw_api.favorite_track(player_fw_storage.storage.get(track_url_to_uuid())['id'])
|
||||||
elif select == 'Hide artist':
|
elif select == 'Hide artist':
|
||||||
track = storage.get(track_url_to_uuid())
|
track = player_fw_storage.storage.get(track_url_to_uuid())
|
||||||
src.fw_api.hide_content({'target': {'id': track.get('artist').get('id'), 'type': 'artist'}})
|
src.fw_api.hide_content({'target': {'id': track.get('artist').get('id'), 'type': 'artist'}})
|
||||||
elif select == 'Exit':
|
elif select == 'Exit':
|
||||||
player.playlist_clear()
|
player.playlist_clear()
|
||||||
player.stop()
|
player.stop()
|
||||||
|
player_fw_storage.storage = {}
|
||||||
break
|
break
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
break
|
break
|
||||||
|
|
|
@ -39,6 +39,7 @@ default_conf = {
|
||||||
"shitnoise.monster"
|
"shitnoise.monster"
|
||||||
],
|
],
|
||||||
'enable_server_transcoding': False,
|
'enable_server_transcoding': False,
|
||||||
|
'track_activity_history': False,
|
||||||
'prefetch_playlist': True,
|
'prefetch_playlist': True,
|
||||||
'mpv_volume': 100,
|
'mpv_volume': 100,
|
||||||
'show_like_button': True,
|
'show_like_button': True,
|
||||||
|
|
Loading…
Reference in a new issue