Fix bug with deleted galleries
This commit is contained in:
parent
8826fc5aa9
commit
77aaee96f3
2 changed files with 12 additions and 1 deletions
|
@ -21,7 +21,7 @@ class Gallery(BaseDownloader):
|
||||||
def find_resources(self, authenticator: Optional[SiteAuthenticator] = None) -> list[Resource]:
|
def find_resources(self, authenticator: Optional[SiteAuthenticator] = None) -> list[Resource]:
|
||||||
try:
|
try:
|
||||||
image_urls = self._get_links(self.post.gallery_data['items'])
|
image_urls = self._get_links(self.post.gallery_data['items'])
|
||||||
except AttributeError:
|
except (AttributeError, TypeError):
|
||||||
try:
|
try:
|
||||||
image_urls = self._get_links(self.post.crosspost_parent_list[0]['gallery_data']['items'])
|
image_urls = self._get_links(self.post.crosspost_parent_list[0]['gallery_data']['items'])
|
||||||
except (AttributeError, IndexError, TypeError):
|
except (AttributeError, IndexError, TypeError):
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
import praw
|
import praw
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from bdfr.exceptions import SiteDownloaderError
|
||||||
from bdfr.site_downloaders.gallery import Gallery
|
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]
|
[res.download(120) for res in results]
|
||||||
hashes = [res.hash.hexdigest() for res in results]
|
hashes = [res.hash.hexdigest() for res in results]
|
||||||
assert set(hashes) == expected_hashes
|
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()
|
||||||
|
|
Loading…
Reference in a new issue