From 5d0c5b1ae33b06a2dd82befcbefd02ad03d742f3 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Mon, 8 Mar 2021 13:13:41 -0800 Subject: [PATCH] Add previews for reddit galleries --- inquisitor/templates.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/inquisitor/templates.py b/inquisitor/templates.py index 50487b8..bd30102 100644 --- a/inquisitor/templates.py +++ b/inquisitor/templates.py @@ -181,6 +181,17 @@ class RedditScraper: parts.append(f'') except: pass + if getattr(post, 'is_gallery', False): + try: + for gallery_item in post.gallery_data['items']: + media_id = gallery_item['media_id'] + metadata = post.media_metadata[media_id] + small_previews = [p for p in metadata['p'] if p['x'] < 800] + preview = sorted(small_previews, key=lambda p:-p['x'])[0] + parts.append(f'link: {metadata["s"]["u"]}') + parts.append(f'') + except: + pass if post.selftext: limit = post.selftext[1024:].find(' ') preview_body = post.selftext[:1024 + limit]