From 3f608a84b73c48491a10c9b9d9067c8a154a98c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sun, 27 Jan 2019 20:37:22 +0100 Subject: [PATCH] [photobucket] don't crash if JSON data is missing --- gallery_dl/extractor/photobucket.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/gallery_dl/extractor/photobucket.py b/gallery_dl/extractor/photobucket.py index c659c416..c9c64eca 100644 --- a/gallery_dl/extractor/photobucket.py +++ b/gallery_dl/extractor/photobucket.py @@ -28,15 +28,22 @@ class PhotobucketAlbumExtractor(Extractor): "pattern": r"http://i\d+.photobucket.com/albums/hh280/focolandia", "count": ">= 39" }), + # subalbums from main "directory" ("http://s271.photobucket.com/user/lakerfanryan/library/", { "options": (("image-filter", "False"),), "pattern": pattern[0], "count": 1, }), + # subalbums from subalbum without images ("http://s271.photobucket.com/user/lakerfanryan/library/Basketball", { "pattern": pattern[0], "count": ">= 9", }), + # private (missing JSON data) + ("http://s1277.photobucket.com/user/sinisterkat44/library/", { + "count": 0, + }), + ("http://s1110.photobucket.com/user/chndrmhn100/library/" "Chandu%20is%20the%20King?sort=3&page=1", None), ] @@ -68,7 +75,13 @@ class PhotobucketAlbumExtractor(Extractor): while True: page = self.request(url, params=params).text - data = json.loads(text.extract(page, "collectionData:", ",\n")[0]) + json_data = text.extract(page, "collectionData:", ",\n")[0] + if not json_data: + msg = text.extract(page, 'libraryPrivacyBlock">', "")[0] + msg = ' ("{}")'.format(text.remove_html(msg)) if msg else "" + self.log.error("Unable to get JSON data%s", msg) + return + data = json.loads(json_data) yield from data["items"]["objects"] @@ -88,7 +101,7 @@ class PhotobucketAlbumExtractor(Extractor): } data = self.request(url, params=params).json() - return data["body"]["subAlbums"] + return data["body"].get("subAlbums", ()) class PhotobucketImageExtractor(Extractor):