mirror of
https://gitea.phreedom.club/localhost_frssoft/funkwlmpv
synced 2024-11-23 23:19:21 +02:00
Compare commits
2 Commits
96ce6e6e0d
...
0fb4edc655
Author | SHA1 | Date | |
---|---|---|---|
localhost_frssoft | 0fb4edc655 | ||
localhost_frssoft | ac73249396 |
|
@ -8,6 +8,7 @@ from shlex import quote
|
||||||
import mpv
|
import mpv
|
||||||
import time
|
import time
|
||||||
import re
|
import re
|
||||||
|
import requests
|
||||||
|
|
||||||
fzf = FzfPrompt()
|
fzf = FzfPrompt()
|
||||||
|
|
||||||
|
@ -23,6 +24,8 @@ player.volume = get_config('mpv_volume')
|
||||||
player.prefetch_playlist = get_config('prefetch_playlist')
|
player.prefetch_playlist = get_config('prefetch_playlist')
|
||||||
show_like_button = get_config('show_like_button')
|
show_like_button = get_config('show_like_button')
|
||||||
track_activity_history = get_config('track_activity_history')
|
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')
|
||||||
shuffle = False
|
shuffle = False
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,22 +47,48 @@ def track_url_to_uuid(listen_url=None):
|
||||||
return uuid[0]
|
return uuid[0]
|
||||||
|
|
||||||
|
|
||||||
if track_activity_history:
|
if track_activity_history or scrobbler_to_fediverse_token != '':
|
||||||
@player.property_observer('time-pos')
|
@player.property_observer('time-pos')
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def time_observer(_name, value):
|
def time_observer(_name, value):
|
||||||
# Here, _value is either None if nothing is playing or a float containing
|
# Here, _value is either None if nothing is playing or a float containing
|
||||||
# fractional seconds since the beginning of the file.
|
# fractional seconds since the beginning of the file.
|
||||||
if value and src.fw_api.current_instance.token != None and player.pause is False:
|
if value:
|
||||||
if value >= 30.0 and value <= 30.1:
|
if value >= 30.0 and value <= 30.1 and player.pause is False:
|
||||||
# detect 30 secs for reporting listen activity
|
# detect 30 secs for reporting listen activity
|
||||||
track = player_fw_storage.storage.get(track_url_to_uuid())
|
try:
|
||||||
track_id = track.get('id')
|
track = player_fw_storage.storage.get(track_url_to_uuid())
|
||||||
if track_id:
|
except:
|
||||||
src.fw_api.record_track_in_history(track_id)
|
return
|
||||||
else:
|
if src.fw_api.current_instance.token is not None:
|
||||||
logger.error("Can't write track to history: No track id")
|
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(0.100)
|
||||||
|
if value > 30.1:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
def osd_observer(value):
|
def osd_observer(value):
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
from os.path import exists
|
from os.path import exists
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from pyfzf.pyfzf import FzfPrompt
|
from pyfzf.pyfzf import FzfPrompt
|
||||||
|
@ -37,6 +38,8 @@ default_conf = {
|
||||||
'automatic_fetch_new_instances': False,
|
'automatic_fetch_new_instances': False,
|
||||||
'enable_server_transcoding': False,
|
'enable_server_transcoding': False,
|
||||||
'external_transcoder_http_proxy_path': "",
|
'external_transcoder_http_proxy_path': "",
|
||||||
|
'scrobbler_to_fediverse_token': "",
|
||||||
|
'scrobbler_to_fediverse_instance': "",
|
||||||
'track_activity_history': False,
|
'track_activity_history': False,
|
||||||
'prefetch_playlist': True,
|
'prefetch_playlist': True,
|
||||||
'enable_persistent_cache': False,
|
'enable_persistent_cache': False,
|
||||||
|
@ -50,7 +53,15 @@ def set_defaults(corrected_config=None):
|
||||||
conf_rewrite = default_conf
|
conf_rewrite = default_conf
|
||||||
if corrected_config:
|
if corrected_config:
|
||||||
conf_rewrite = corrected_config
|
conf_rewrite = corrected_config
|
||||||
with open(conf_file, 'wt') as f:
|
descriptor = os.open(
|
||||||
|
path=conf_file,
|
||||||
|
flags=(
|
||||||
|
os.O_WRONLY # access mode: write only
|
||||||
|
| os.O_CREAT # create if not exists
|
||||||
|
| os.O_TRUNC # truncate the file to zero
|
||||||
|
),
|
||||||
|
mode=0o600)
|
||||||
|
with open(descriptor, 'wt') as f:
|
||||||
f.write(json.dumps(conf_rewrite, indent=4))
|
f.write(json.dumps(conf_rewrite, indent=4))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue