fix: keep GIFs moving in reply contexts (v2.20.1)
Mastodon turns GIFs into silent looping MP4s (gifv); only the first-frame preview was kept. The MP4 is now saved locally and played muted and looping with the still as poster. Animated GIFs from other sites are saved as animated WebP. Migration 025 adds reply_contexts.video and has fediverse contexts with an image fetched again once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
03a1c8fcea
commit
952ca300c0
9 files changed
+193
-19
No files matched your search
@@ -65,7 +65,7 @@ FEDIVERSE_PATH_RE = re.compile(
|
||||
FEDI_TITLE_RE = re.compile(r"^(.*?)\s*\((@[^)\s]+)\)\s*$")
|
||||
|
||||
FIELDS = ('title', 'content_snippet', 'published_at', 'author_name', 'author_handle',
|
||||
'author_url', 'author_photo', 'site_name', 'photo', 'photo_alt')
|
||||
'author_url', 'author_photo', 'site_name', 'photo', 'photo_alt', 'video')
|
||||
|
||||
|
||||
def fetch_reply_context(
|
||||
@@ -300,11 +300,14 @@ def _from_status(status: dict, url: str) -> Dict[str, Any]:
|
||||
snippet = _text_snippet(f"CW: {spoiler}")
|
||||
else:
|
||||
snippet = _snippet(status.get('content') or '') or None
|
||||
photo = photo_alt = None
|
||||
photo = photo_alt = video = None
|
||||
if not status.get('sensitive'):
|
||||
for media in status.get('media_attachments') or []:
|
||||
if media.get('type') in ('image', 'gifv', 'video') and _is_http_url(media.get('preview_url')):
|
||||
photo, photo_alt = media['preview_url'], media.get('description') or None
|
||||
# A "GIF" on Mastodon is a silent looping MP4; the preview is its first frame
|
||||
if media['type'] == 'gifv' and _is_http_url(media.get('url')):
|
||||
video = media['url']
|
||||
break
|
||||
avatar = account.get('avatar_static') or account.get('avatar')
|
||||
return {
|
||||
@@ -319,6 +322,7 @@ def _from_status(status: dict, url: str) -> Dict[str, Any]:
|
||||
'site_name': urlparse(url).hostname,
|
||||
'photo': photo,
|
||||
'photo_alt': photo_alt,
|
||||
'video': video,
|
||||
}
|
||||
|
||||
|
||||
@@ -482,6 +486,7 @@ def _save_images(context: Dict[str, Any], site_url: str) -> None:
|
||||
data_path = current_app.config['DATA_PATH']
|
||||
avatars.fetch(data_path, context.get('author_photo'), site_url)
|
||||
avatars.fetch_preview(data_path, context.get('photo'), site_url)
|
||||
avatars.fetch_video(data_path, context.get('video'), site_url)
|
||||
except Exception as e:
|
||||
logger.info(f"Could not save reply context images: {e}")
|
||||
|
||||
|
||||
Reference in new issue
Block a user