mirror of
https://gitea.phreedom.club/localhost_frssoft/funkwlmpv
synced 2024-12-23 10:23:33 +02:00
Optional feature: Track listen activity to history (default is disabled)
This commit is contained in:
parent
06fd6308fe
commit
9c65117e9c
3 changed files with 36 additions and 4 deletions
|
@ -228,6 +228,16 @@ def federate_search_by_url(object):
|
|||
}
|
||||
r = current_instance.s.post(f'https://{current_instance.instance}/api/v1/federation/fetches', json=params)
|
||||
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
|
||||
|
|
|
@ -4,6 +4,7 @@ from src.settings import get_config
|
|||
from loguru import logger
|
||||
from pyfzf.pyfzf import FzfPrompt
|
||||
import mpv
|
||||
import time
|
||||
|
||||
fzf = FzfPrompt()
|
||||
|
||||
|
@ -11,16 +12,14 @@ 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 = {}
|
||||
|
||||
|
||||
def set_http_header(headers=[]):
|
||||
player.http_header_fields = headers
|
||||
|
||||
|
||||
@logger.catch
|
||||
def track_url_to_uuid(listen_url=None):
|
||||
'''Attempt get uuid from track listen url or current playing url'''
|
||||
if listen_url:
|
||||
|
@ -30,6 +29,28 @@ 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)
|
||||
|
|
|
@ -39,6 +39,7 @@ 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 a new issue