Clean up artist junk
This commit is contained in:
@ -22,22 +22,23 @@ class WebhooksFrontend(pykka.ThreadingActor, CoreListener):
|
|||||||
self.webhook_tokens = self.config["webhooks"]["tokens"].split(",")
|
self.webhook_tokens = self.config["webhooks"]["tokens"].split(",")
|
||||||
|
|
||||||
def _build_post_data(self, track) -> dict:
|
def _build_post_data(self, track) -> dict:
|
||||||
primary_artist = track.artists[0]
|
artists = ", ".join(sorted([a.name for a in track.artists]))
|
||||||
|
artists_list = [a for a in track.artists]
|
||||||
|
try:
|
||||||
|
musicbrainz_artist_id = artists_list[0].musicbrainz_id
|
||||||
|
except IndexError:
|
||||||
|
musicbrainz_artist_id = None
|
||||||
duration = track.length and track.length // 1000 or 0
|
duration = track.length and track.length // 1000 or 0
|
||||||
return {
|
return {
|
||||||
"name": track.name,
|
"name": track.name,
|
||||||
"artist": primary_artist.name,
|
"artist": artists,
|
||||||
"album": track.album,
|
"album": track.album,
|
||||||
"track_number": track.track_no,
|
"track_number": track.track_no,
|
||||||
"run_time_ticks": track.length,
|
"run_time_ticks": track.length,
|
||||||
"run_time": str(duration),
|
"run_time": str(duration),
|
||||||
"musicbrainz_track_id": track.musicbrainz_id,
|
"musicbrainz_track_id": track.musicbrainz_id,
|
||||||
"musicbrainz_album_id": track.album.musicbrainz_id
|
"musicbrainz_album_id": track.album.musicbrainz_id,
|
||||||
if track.album
|
"musicbrainz_artist_id": musicbrainz_artist_id,
|
||||||
else None,
|
|
||||||
"musicbrainz_artist_id": track.artist.musicbrainz_id
|
|
||||||
if primary_artist
|
|
||||||
else None,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def _post_update_to_webhooks(self, post_data: dict, status: str):
|
def _post_update_to_webhooks(self, post_data: dict, status: str):
|
||||||
@ -61,6 +62,7 @@ class WebhooksFrontend(pykka.ThreadingActor, CoreListener):
|
|||||||
|
|
||||||
def track_playback_started(self, tl_track):
|
def track_playback_started(self, tl_track):
|
||||||
track = tl_track.track
|
track = tl_track.track
|
||||||
|
artists = ", ".join(sorted([a.name for a in track.artists]))
|
||||||
self.last_start_time = int(time.time())
|
self.last_start_time = int(time.time())
|
||||||
logger.debug(f"Now playing track: {track.artists[0]} - {track.name}")
|
logger.debug(f"Now playing track: {track.artists[0]} - {track.name}")
|
||||||
post_data = self._build_post_data(tl_track.track)
|
post_data = self._build_post_data(tl_track.track)
|
||||||
@ -69,11 +71,12 @@ class WebhooksFrontend(pykka.ThreadingActor, CoreListener):
|
|||||||
if not self.webhook_urls:
|
if not self.webhook_urls:
|
||||||
logger.info("No webhook URLS are configured ")
|
logger.info("No webhook URLS are configured ")
|
||||||
return
|
return
|
||||||
|
logger.info(f"Scrobbling via webhooks: {artists} - {track.name}")
|
||||||
self._post_update_to_webhooks(post_data, "started")
|
self._post_update_to_webhooks(post_data, "started")
|
||||||
|
|
||||||
def track_playback_ended(self, tl_track, time_position):
|
def track_playback_ended(self, tl_track, time_position):
|
||||||
track = tl_track.track
|
track = tl_track.track
|
||||||
|
artists = ", ".join(sorted([a.name for a in track.artists]))
|
||||||
duration = track.length and track.length // 1000 or 0
|
duration = track.length and track.length // 1000 or 0
|
||||||
time_position = time_position // 1000
|
time_position = time_position // 1000
|
||||||
|
|
||||||
@ -88,6 +91,9 @@ class WebhooksFrontend(pykka.ThreadingActor, CoreListener):
|
|||||||
|
|
||||||
if self.last_start_time is None:
|
if self.last_start_time is None:
|
||||||
self.last_start_time = int(time.time()) - duration
|
self.last_start_time = int(time.time()) - duration
|
||||||
|
logger.info(
|
||||||
|
f"Scrobbling finished via webhooks: {artists} - {track.name}"
|
||||||
|
)
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"Sending scroble to webhooks for track: {track.artists} - {track.name}"
|
f"Sending scroble to webhooks for track: {track.artists} - {track.name}"
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user