add scrobble frontend
This commit is contained in:
parent
4bc641e95a
commit
370508acc4
4 changed files with 50 additions and 0 deletions
|
@ -23,9 +23,12 @@ class SubidyExtension(ext.Extension):
|
||||||
schema["password"] = config.Secret()
|
schema["password"] = config.Secret()
|
||||||
schema["legacy_auth"] = config.Boolean(optional=True)
|
schema["legacy_auth"] = config.Boolean(optional=True)
|
||||||
schema["api_version"] = config.String(optional=True)
|
schema["api_version"] = config.String(optional=True)
|
||||||
|
schema["scrobble"] = config.Boolean(optional=True)
|
||||||
return schema
|
return schema
|
||||||
|
|
||||||
def setup(self, registry):
|
def setup(self, registry):
|
||||||
from .backend import SubidyBackend
|
from .backend import SubidyBackend
|
||||||
|
from .frontend import SubidyFrontend
|
||||||
|
|
||||||
registry.add("backend", SubidyBackend)
|
registry.add("backend", SubidyBackend)
|
||||||
|
registry.add("frontend", SubidyFrontend)
|
||||||
|
|
|
@ -5,3 +5,4 @@ username =
|
||||||
password =
|
password =
|
||||||
legacy_auth = no
|
legacy_auth = no
|
||||||
api_version = 1.14.0
|
api_version = 1.14.0
|
||||||
|
scrobble = false
|
||||||
|
|
29
mopidy_subidy/frontend.py
Normal file
29
mopidy_subidy/frontend.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
import pykka
|
||||||
|
|
||||||
|
import mopidy_subidy
|
||||||
|
from mopidy import core
|
||||||
|
from mopidy_subidy import subsonic_api
|
||||||
|
|
||||||
|
class SubidyFrontend(pykka.ThreadingActor, core.CoreListener):
|
||||||
|
def __init__(self, config, core):
|
||||||
|
super().__init__()
|
||||||
|
subidy_config = config["subidy"]
|
||||||
|
self.subsonic_api = subsonic_api.SubsonicApi(
|
||||||
|
url=subidy_config["url"],
|
||||||
|
username=subidy_config["username"],
|
||||||
|
password=subidy_config["password"],
|
||||||
|
app_name=mopidy_subidy.SubidyExtension.dist_name,
|
||||||
|
legacy_auth=subidy_config["legacy_auth"],
|
||||||
|
api_version=subidy_config["api_version"],
|
||||||
|
)
|
||||||
|
self.scrobble = subidy_config["scrobble"]
|
||||||
|
|
||||||
|
def track_playback_started(self, tl_track):
|
||||||
|
if self.scrobble == True:
|
||||||
|
return self.subsonic_api.send_scrobble(tl_track.track.uri, False)
|
||||||
|
|
||||||
|
def track_playback_ended(self, tl_track, time_position):
|
||||||
|
if self.scrobble == True:
|
||||||
|
time_position = time_position // 1000
|
||||||
|
if time_position < tl_track.track.length // 2:
|
||||||
|
return self.subsonic_api.send_scrobble(tl_track.track.uri, True)
|
|
@ -93,6 +93,23 @@ class SubsonicApi:
|
||||||
def get_censored_song_stream_uri(self, song_id):
|
def get_censored_song_stream_uri(self, song_id):
|
||||||
return self.get_subsonic_uri("stream", dict(id=song_id), True)
|
return self.get_subsonic_uri("stream", dict(id=song_id), True)
|
||||||
|
|
||||||
|
def send_scrobble(self, song_id, submission=True):
|
||||||
|
try:
|
||||||
|
response = self.connection.scrobble(
|
||||||
|
uri.get_song_id(song_id),
|
||||||
|
submission
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
logger.warning("Failed to scrobble")
|
||||||
|
return None
|
||||||
|
if response.get("status") != RESPONSE_OK:
|
||||||
|
logger.warning(
|
||||||
|
"Got non-okay status code from subsonic: $s"
|
||||||
|
% response.get("status")
|
||||||
|
)
|
||||||
|
return None
|
||||||
|
return response.get("scrobble")
|
||||||
|
|
||||||
def find_raw(
|
def find_raw(
|
||||||
self,
|
self,
|
||||||
query,
|
query,
|
||||||
|
|
Loading…
Add table
Reference in a new issue