mirror of
https://gitea.phreedom.club/localhost_frssoft/funkwlmpv
synced 2024-11-16 04:03:01 +00:00
no more automatic music scrobble, just make it manually with "share" button
This commit is contained in:
parent
3310b56843
commit
bcd6c220f3
@ -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, track_info_output
|
||||
from src.mpv_control import player, track_url_to_uuid, player_fw_storage, soft_volume_reduce
|
||||
from src.mpv_control import player, track_url_to_uuid, player_fw_storage, soft_volume_reduce, send_listen_activity
|
||||
from src.settings import get_config
|
||||
from pyfzf.pyfzf import FzfPrompt
|
||||
from loguru import logger
|
||||
@ -119,7 +119,7 @@ def radio_load(id_radio=None, type_radio='custom', name=None, related_object=Non
|
||||
radio_task = threading.Thread(
|
||||
target=radio_generator, args=(radio_session_id,), daemon=True)
|
||||
radio_task.start()
|
||||
player_items_menu = ['Next', 'Prev', 'Pause', 'Download', 'Info']
|
||||
player_items_menu = ['Next', 'Prev', 'Pause', 'Download', 'Info', 'Share']
|
||||
|
||||
if show_like_button:
|
||||
player_items_menu.append('Like')
|
||||
@ -163,6 +163,8 @@ def radio_load(id_radio=None, type_radio='custom', name=None, related_object=Non
|
||||
track = player_fw_storage.storage.get(track_url_to_uuid())
|
||||
track['direct_url'] = player.stream_open_filename
|
||||
track_info_output(track)
|
||||
elif select == 'Share':
|
||||
send_listen_activity()
|
||||
elif select == 'Like':
|
||||
favorite_track(player_fw_storage.storage.get(
|
||||
track_url_to_uuid())['id'])
|
||||
|
@ -24,8 +24,8 @@ player.volume = get_config('mpv_volume')
|
||||
player.prefetch_playlist = get_config('prefetch_playlist')
|
||||
show_like_button = get_config('show_like_button')
|
||||
track_activity_history = get_config('track_activity_history')
|
||||
scrobbler_to_fediverse_token = get_config('scrobbler_to_fediverse_token')
|
||||
scrobbler_to_fediverse_instance = get_config('scrobbler_to_fediverse_instance')
|
||||
share_to_fediverse_token = get_config('share_to_fediverse_token')
|
||||
share_to_fediverse_instance = get_config('share_to_fediverse_instance')
|
||||
shuffle = False
|
||||
|
||||
|
||||
@ -47,48 +47,35 @@ def track_url_to_uuid(listen_url=None):
|
||||
return uuid[0]
|
||||
|
||||
|
||||
if track_activity_history or scrobbler_to_fediverse_token != '':
|
||||
@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:
|
||||
if value >= 30.0 and value <= 30.2 and player.pause is False:
|
||||
# detect 30 secs for reporting listen activity
|
||||
try:
|
||||
track = player_fw_storage.storage.get(track_url_to_uuid())
|
||||
except:
|
||||
return
|
||||
if src.fw_api.current_instance.token is not None:
|
||||
track_id = track.get('id')
|
||||
def send_listen_activity():
|
||||
try:
|
||||
track = player_fw_storage.storage.get(track_url_to_uuid())
|
||||
except:
|
||||
return
|
||||
if src.fw_api.current_instance.token is not None:
|
||||
track_id = track.get('id')
|
||||
|
||||
if track_id:
|
||||
if track_activity_history:
|
||||
src.fw_api.record_track_in_history(track_id)
|
||||
else:
|
||||
logger.error("Can't write track to history: No track id")
|
||||
if scrobbler_to_fediverse_token != '':
|
||||
fid = track.get('fid')
|
||||
artist = track['artist'].get('name')
|
||||
album = track['album'].get('title')
|
||||
title = track.get('title')
|
||||
tags = track.get('tags')
|
||||
if tags:
|
||||
tags = [f'#{tag}' for tag in tags]
|
||||
tags = ' '.join(tags)
|
||||
if tags == []:
|
||||
tags = ''
|
||||
status_obj = {'spoiler_text': 'funkwhale-cli music scrobbler',
|
||||
'visibility': 'unlisted',
|
||||
'status': f'🎧 {artist} - {album} - {title}\n{fid}\n#NowPlaying {tags}'}
|
||||
requests.post(f'https://{scrobbler_to_fediverse_instance}/api/v1/statuses',
|
||||
json=status_obj,
|
||||
headers={'Authorization': f'Bearer {scrobbler_to_fediverse_token}'})
|
||||
time.sleep(1)
|
||||
if value > 30.2: # passive mode
|
||||
time.sleep(1)
|
||||
return
|
||||
if track_id:
|
||||
src.fw_api.record_track_in_history(track_id)
|
||||
else:
|
||||
logger.error("Can't write track to history: No track id")
|
||||
if share_to_fediverse_token != '':
|
||||
fid = track.get('fid')
|
||||
artist = track['artist'].get('name')
|
||||
album = track['album'].get('title')
|
||||
title = track.get('title')
|
||||
tags = track.get('tags')
|
||||
if tags:
|
||||
tags = [f'#{tag}' for tag in tags]
|
||||
tags = ' '.join(tags)
|
||||
if tags == []:
|
||||
tags = ''
|
||||
status_obj = {'spoiler_text': 'funkwhale-cli music share',
|
||||
'visibility': 'unlisted',
|
||||
'status': f'🎧 {artist} - {album} - {title}\n{fid}\n#NowPlaying {tags}'}
|
||||
requests.post(f'https://{share_to_fediverse_instance}/api/v1/statuses',
|
||||
json=status_obj,
|
||||
headers={'Authorization': f'Bearer {share_to_fediverse_token}'})
|
||||
|
||||
|
||||
def osd_observer(value):
|
||||
@ -160,7 +147,7 @@ def player_menu(header='', storage={}):
|
||||
while True:
|
||||
try:
|
||||
player_items_menu = ['Next', 'Prev', 'Pause',
|
||||
'Shuffle', 'Download', 'Info']
|
||||
'Shuffle', 'Download', 'Info', 'Share']
|
||||
if player.pause:
|
||||
player_items_menu[2] = 'Play'
|
||||
else:
|
||||
@ -202,6 +189,8 @@ def player_menu(header='', storage={}):
|
||||
track = player_fw_storage.storage.get(track_url_to_uuid())
|
||||
track['direct_url'] = player.stream_open_filename
|
||||
track_info_output(track)
|
||||
elif select == 'Share':
|
||||
send_listen_activity()
|
||||
elif select == 'Like':
|
||||
src.fw_api.favorite_track(
|
||||
player_fw_storage.storage.get(track_url_to_uuid())['id'])
|
||||
|
@ -38,9 +38,8 @@ default_conf = {
|
||||
'automatic_fetch_new_instances': False,
|
||||
'enable_server_transcoding': False,
|
||||
'external_transcoder_http_proxy_path': "",
|
||||
'scrobbler_to_fediverse_token': "",
|
||||
'scrobbler_to_fediverse_instance': "",
|
||||
'track_activity_history': False,
|
||||
'share_to_fediverse_token': "",
|
||||
'share_to_fediverse_instance': "",
|
||||
'prefetch_playlist': True,
|
||||
'enable_persistent_cache': False,
|
||||
'mpv_volume': 100,
|
||||
|
Loading…
Reference in New Issue
Block a user