Fix error with crossposted Reddit galleries
This commit is contained in:
@@ -21,7 +21,16 @@ class Gallery(BaseDownloader):
|
|||||||
super().__init__(post)
|
super().__init__(post)
|
||||||
|
|
||||||
def find_resources(self, authenticator: Optional[SiteAuthenticator] = None) -> list[Resource]:
|
def find_resources(self, authenticator: Optional[SiteAuthenticator] = None) -> list[Resource]:
|
||||||
image_urls = self._get_links(self.post.gallery_data['items'])
|
try:
|
||||||
|
image_urls = self._get_links(self.post.gallery_data['items'])
|
||||||
|
except AttributeError:
|
||||||
|
try:
|
||||||
|
image_urls = self._get_links(self.post.crosspost_parent_list[0]['gallery_data']['items'])
|
||||||
|
except (AttributeError, IndexError):
|
||||||
|
logger.error(f'Could not find gallery data in submission {self.post.id}')
|
||||||
|
logger.exception('Gallery image find failure')
|
||||||
|
raise SiteDownloaderError('No images found in Reddit gallery')
|
||||||
|
|
||||||
if not image_urls:
|
if not image_urls:
|
||||||
raise SiteDownloaderError('No images found in Reddit gallery')
|
raise SiteDownloaderError('No images found in Reddit gallery')
|
||||||
return [Resource(self.post, url) for url in image_urls]
|
return [Resource(self.post, url) for url in image_urls]
|
||||||
|
|||||||
@@ -56,6 +56,10 @@ def test_gallery_get_links(test_ids: list[dict], expected: set[str]):
|
|||||||
'b89a3f41feb73ec1136ec4ffa7353eb1',
|
'b89a3f41feb73ec1136ec4ffa7353eb1',
|
||||||
'cabb76fd6fd11ae6e115a2039eb09f04',
|
'cabb76fd6fd11ae6e115a2039eb09f04',
|
||||||
}),
|
}),
|
||||||
|
('obkflw', {
|
||||||
|
'65163f685fb28c5b776e0e77122718be',
|
||||||
|
'2a337eb5b13c34d3ca3f51b5db7c13e9',
|
||||||
|
}),
|
||||||
))
|
))
|
||||||
def test_gallery_download(test_submission_id: str, expected_hashes: set[str], reddit_instance: praw.Reddit):
|
def test_gallery_download(test_submission_id: str, expected_hashes: set[str], reddit_instance: praw.Reddit):
|
||||||
test_submission = reddit_instance.submission(id=test_submission_id)
|
test_submission = reddit_instance.submission(id=test_submission_id)
|
||||||
|
|||||||
Reference in New Issue
Block a user