mirror of
http://gitea.phreedom.club/localhost_frssoft/funkwlmpv
synced 2024-11-22 07:21:28 +00:00
Optional feature: Track listen activity to history (default is disabled)
This commit is contained in:
parent
06fd6308fe
commit
9c65117e9c
|
@ -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)})
|
||||||
|
|
|
@ -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,6 +29,28 @@ 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.update(storage)
|
player_fw_storage.storage.update(storage)
|
||||||
|
|
|
@ -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