Skip to content

Commit 8a1a4e5

Browse files
committed
fix external video thumbnailing detection
1 parent 2c7d21b commit 8a1a4e5

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

pod/activitypub/deserialization/video.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
def format_ap_video_data(payload, source_instance):
1212
"""Create an ExternalVideo object from an AP Video payload."""
13-
1413
video_source_links = [
1514
{
1615
"type": link["mediaType"],
@@ -39,14 +38,17 @@ def format_ap_video_data(payload, source_instance):
3938
if "mediaType" in link and link["mediaType"] == "video/mp4"
4039
]
4140

41+
# For peertube payloads, guess the thumbnail by looking for 'thumbnail' in the url
42+
thumbnails = [
43+
icon for icon in payload["icon"] if "thumbnails" in icon["url"]
44+
] + payload["icon"]
45+
thumbnail_url = thumbnails[0]["url"] if thumbnails else None
4246
external_video_attributes = {
4347
"ap_id": payload["id"],
4448
"videos": video_source_links,
4549
"title": payload["name"],
4650
"date_added": isoparse(payload["published"]),
47-
"thumbnail": [icon for icon in payload["icon"] if "thumbnails" in icon["url"]][
48-
0
49-
]["url"],
51+
"thumbnail": thumbnail_url,
5052
"duration": int(payload["duration"].lstrip("PT").rstrip("S")),
5153
"viewcount": payload["views"],
5254
"source_instance": source_instance,

0 commit comments

Comments
 (0)