diff --git a/bdfr/site_downloaders/gallery.py b/bdfr/site_downloaders/gallery.py index 62fec60..cd34416 100644 --- a/bdfr/site_downloaders/gallery.py +++ b/bdfr/site_downloaders/gallery.py @@ -21,7 +21,7 @@ class Gallery(BaseDownloader): def find_resources(self, authenticator: Optional[SiteAuthenticator] = None) -> list[Resource]: try: image_urls = self._get_links(self.post.gallery_data['items']) - except AttributeError: + except (AttributeError, TypeError): try: image_urls = self._get_links(self.post.crosspost_parent_list[0]['gallery_data']['items']) except (AttributeError, IndexError, TypeError): diff --git a/tests/site_downloaders/test_gallery.py b/tests/site_downloaders/test_gallery.py index 51045f8..f84650d 100644 --- a/tests/site_downloaders/test_gallery.py +++ b/tests/site_downloaders/test_gallery.py @@ -4,6 +4,7 @@ import praw import pytest +from bdfr.exceptions import SiteDownloaderError from bdfr.site_downloaders.gallery import Gallery @@ -68,3 +69,13 @@ def test_gallery_download(test_submission_id: str, expected_hashes: set[str], re [res.download(120) for res in results] hashes = [res.hash.hexdigest() for res in results] assert set(hashes) == expected_hashes + + +@pytest.mark.parametrize('test_id', ( + 'n0pyzp', +)) +def test_gallery_download_raises_right_error(test_id: str, reddit_instance: praw.Reddit): + test_submission = reddit_instance.submission(id=test_id) + gallery = Gallery(test_submission) + with pytest.raises(SiteDownloaderError): + gallery.find_resources()