Attach cover art to ActivityPub "now playing" posts
CI / validate-monitoring (push) Successful in 9s
CI / lint (push) Successful in 11s
CI / federation-interop (push) Successful in 1m38s
CI / test (push) Successful in 3m31s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / trigger-deploy (push) Skipped
CI / notify (push) Successful in 5s
CI / validate-monitoring (push) Successful in 9s
CI / lint (push) Successful in 11s
CI / federation-interop (push) Successful in 1m38s
CI / test (push) Successful in 3m31s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / trigger-deploy (push) Skipped
CI / notify (push) Successful in 5s
Note objects can now carry an optional attachment (an AS2 Image), which Mastodon and other AP servers render as the post's media. Only "now playing" posts use it for now - it's the only post type tied to a single track, and therefore the only one with one unambiguous album; weekly summaries and milestones aggregate many tracks. The attachment points straight at the Cover Art Archive URL cached in AlbumArt, not our own authenticated /api/v1/art/album proxy - a remote server fetches attachments unauthenticated, and Cover Art Archive is already public. The lookup happens in the periodic now-playing worker task, not a request, so a cache-miss MusicBrainz/ Cover Art Archive call adds no request latency. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011Hn2QwS1HRT8tFAzo8ew63
This commit is contained in:
1 parent
f106d68921
commit
44abd70caa
5 files changed
+114
-8
No files matched your search
@@ -19,7 +19,7 @@ from scrobbler.federation import activities, actors, followers, publishing, shar
|
||||
from scrobbler.federation import metrics as fed_metrics
|
||||
from scrobbler.federation.models import FederationNowPlaying, FederationPost, FederationSettings
|
||||
from scrobbler.federation.protocol import content, vocab
|
||||
from scrobbler.services import accounts
|
||||
from scrobbler.services import accounts, art
|
||||
from scrobbler.services.scrobbles import get_now_playing
|
||||
|
||||
KIND = "now_playing"
|
||||
@@ -80,10 +80,36 @@ def _build_content(playing) -> tuple[str, str]:
|
||||
return text, html
|
||||
|
||||
|
||||
def _attachment_for(playing) -> list[dict]:
|
||||
"""Cover art for the post, if we have an album and can resolve it. Cover Art
|
||||
Archive's sized convenience endpoints (what art.lookup() resolves to) are always
|
||||
JPEG, whatever the original upload was."""
|
||||
if not playing.album:
|
||||
return []
|
||||
result = art.lookup(playing.artist, playing.album)
|
||||
if result.status != "found":
|
||||
return []
|
||||
return [
|
||||
{
|
||||
"type": "Image",
|
||||
"mediaType": "image/jpeg",
|
||||
"url": result.image_url,
|
||||
"name": f"Cover art for {playing.album}",
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def _post_now_playing(user, playing, key: str, state: FederationNowPlaying, now: datetime) -> str:
|
||||
text, html = _build_content(playing)
|
||||
post = publishing.publish(
|
||||
user.id, user.username, KIND, key, text=text, html=html, tags=("Scrobbler", "NowPlaying")
|
||||
user.id,
|
||||
user.username,
|
||||
KIND,
|
||||
key,
|
||||
text=text,
|
||||
html=html,
|
||||
tags=("Scrobbler", "NowPlaying"),
|
||||
attachment=_attachment_for(playing),
|
||||
)
|
||||
if post is None:
|
||||
return "none"
|
||||
|
||||
Reference in new issue
Block a user