Compare commits

...

10 Commits

Author SHA1 Message Date
0cac2e0a47 Add primary artist mopidy URI to POST 2023-03-02 11:21:27 -05:00
2edf49e78e Move README to markdown 2023-01-23 11:25:22 -05:00
ff5f9e0c3e Bump version to 0.2.2
- Fix string interpolation for tokens
2023-01-23 11:12:27 -05:00
3e33f6b464 Fix the bug for real 2023-01-23 11:09:27 -05:00
2db63ad49c Bump version to 0.2.1 2023-01-21 23:21:51 -05:00
a140140322 Fix un-interpolated token 2023-01-21 23:20:29 -05:00
34a03bed6a Fix pushing pause to webhook regardless of time 2023-01-16 13:45:54 -05:00
53b0abe03a Fix ambiguous starting log message 2023-01-16 12:34:07 -05:00
47317081f9 Bump version to 0.2.0 2023-01-12 16:09:50 -05:00
b988e4bf0a Fix not properly sending playback ticks 2023-01-12 15:58:43 -05:00
3 changed files with 13 additions and 22 deletions

View File

@ -1,10 +1,5 @@
****************
Mopidy-Webhooks
****************
.. image:: https://img.shields.io/pypi/v/Mopidy-Webhooks
:target: https://pypi.org/project/Mopidy-Webhooks/
:alt: Latest PyPI version
===============
`Mopidy <https://www.mopidy.com/>`_ extension for sending mopidy play status to
arbitrary URL endpoints
@ -41,9 +36,9 @@ The following configuration values are available:
Project resources
=================
- `Source code <https://github.com/powellc/mopidy-webhooks>`_
- `Issue tracker <https://github.com/powellc/mopidy-webhooks/issues>`_
- `Changelog <https://github.com/powellc/mopidy-webhooks/releases>`_
- `Source code <https://code.unbl.ink/secstate/mopidy-webhooks>`_
- `Issue tracker <https://code.unbl.ink/secstate/mopidy-webhooks/issues>`_
- `Changelog <https://code.unbl.ink/secstate/mopidy-webhooks/releases>`_
Credits

View File

@ -18,9 +18,9 @@ class WebhooksFrontend(pykka.ThreadingActor, CoreListener):
self.last_start_time = None
def on_start(self):
logger.info("Parsing webhook URLs and tokens")
self.webhook_urls = self.config["webhooks"]["urls"].split(",")
self.webhook_tokens = self.config["webhooks"]["tokens"].split(",")
logger.info(f"Parsing webhook URLs and tokens: {self.webhook_urls}")
def _build_post_data(self, track, time_position: Optional[int]=None) -> dict:
artists = ", ".join(sorted([a.name for a in track.artists]))
@ -33,6 +33,7 @@ class WebhooksFrontend(pykka.ThreadingActor, CoreListener):
album_name = ""
if track.album:
album_name = getattr(track.album, "name")
return {
"name": track.name,
"artist": artists,
@ -45,6 +46,7 @@ class WebhooksFrontend(pykka.ThreadingActor, CoreListener):
"musicbrainz_album_id": track.album.musicbrainz_id if track.album else "",
"musicbrainz_artist_id": musicbrainz_artist_id,
"mopidy_uri": track.uri,
"primary_artist_mopidy_uri": artists_list[0].uri,
}
def _post_update_to_webhooks(self, post_data: dict, status: str):
@ -59,7 +61,7 @@ class WebhooksFrontend(pykka.ThreadingActor, CoreListener):
logger.info(f"No token found for Webhook URL: {webhook_url}")
if token:
headers["Authorization"] = "Token {token}"
headers["Authorization"] = f"Token {token}"
response = requests.post(
webhook_url, json=json.dumps(post_data), headers=headers
@ -71,7 +73,7 @@ class WebhooksFrontend(pykka.ThreadingActor, CoreListener):
artists = ", ".join(sorted([a.name for a in track.artists]))
self.last_start_time = int(time.time())
logger.debug(f"Now playing track: {artists} - {track.name}")
post_data = self._build_post_data(tl_track.track)
post_data = self._build_post_data(tl_track.track, time_position=0)
# Build post data to send to urls
if not self.webhook_urls:
@ -84,11 +86,11 @@ class WebhooksFrontend(pykka.ThreadingActor, CoreListener):
track = tl_track.track
artists = ", ".join(sorted([a.name for a in track.artists]))
duration = track.length and track.length // 1000 or 0
time_position = time_position // 1000
time_position_sec = time_position // 1000
post_data = self._build_post_data(tl_track.track, time_position=time_position)
if time_position < duration // 2 and time_position < 240:
if time_position_sec < duration // 2 and time_position_sec < 240:
logger.debug(
"Track not played long enough to scrobble. (50% or 240s)"
)
@ -106,16 +108,10 @@ class WebhooksFrontend(pykka.ThreadingActor, CoreListener):
track = tl_track.track
artists = ", ".join(sorted([a.name for a in track.artists]))
duration = track.length and track.length // 1000 or 0
time_position = time_position // 1000
time_position_sec = time_position // 1000
post_data = self._build_post_data(tl_track.track, time_position=time_position)
if time_position < duration // 2 and time_position < 240:
logger.debug(
"Track not played long enough to scrobble. (50% or 240s)"
)
return
if self.last_start_time is None:
self.last_start_time = int(time.time()) - duration
logger.info(

View File

@ -1,6 +1,6 @@
[metadata]
name = Mopidy-Webhooks
version = 0.1.6
version = 0.2.2
url = https://github.com/powellc/mopidy-webhooks
author = Colin Powell
author_email = colin@unbl.ink