[imgur] print error message if no JSON data is found (#446)
This commit is contained in:
@@ -54,9 +54,17 @@ class ImgurExtractor(Extractor):
|
|||||||
return self.session.cookies
|
return self.session.cookies
|
||||||
|
|
||||||
def _extract_data(self, path):
|
def _extract_data(self, path):
|
||||||
response = self.request(self.root + path, notfound=self.subcategory)
|
page = self.request(self.root + path, notfound=self.subcategory).text
|
||||||
data = json.loads(text.extract(
|
data = text.extract(page, "image : ", ",\n")[0]
|
||||||
response.text, "image : ", ",\n")[0])
|
|
||||||
|
if not data:
|
||||||
|
if ">Sign in required<" in page:
|
||||||
|
self.log.error("'Sign in required'")
|
||||||
|
else:
|
||||||
|
self.log.error("Unable to extract JSON data")
|
||||||
|
raise exception.StopExtraction()
|
||||||
|
data = json.loads(data)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
del data["adConfig"]
|
del data["adConfig"]
|
||||||
del data["isAd"]
|
del data["isAd"]
|
||||||
@@ -218,7 +226,7 @@ class ImgurAlbumExtractor(ImgurExtractor):
|
|||||||
|
|
||||||
def items(self):
|
def items(self):
|
||||||
self.login()
|
self.login()
|
||||||
album = self._extract_data("/a/" + self.key + "/all")
|
album = self._extract_data("/a/" + self.key)
|
||||||
images = album["album_images"]["images"]
|
images = album["album_images"]["images"]
|
||||||
del album["album_images"]
|
del album["album_images"]
|
||||||
|
|
||||||
|
|||||||
@@ -285,8 +285,10 @@ def setup_test_config():
|
|||||||
config.set(("extractor", "password"), name)
|
config.set(("extractor", "password"), name)
|
||||||
config.set(("extractor", "nijie" , "username"), email)
|
config.set(("extractor", "nijie" , "username"), email)
|
||||||
config.set(("extractor", "seiga" , "username"), email)
|
config.set(("extractor", "seiga" , "username"), email)
|
||||||
|
|
||||||
config.set(("extractor", "danbooru" , "username"), None)
|
config.set(("extractor", "danbooru" , "username"), None)
|
||||||
config.set(("extractor", "instagram", "username"), None)
|
config.set(("extractor", "instagram", "username"), None)
|
||||||
|
config.set(("extractor", "imgur" , "username"), None)
|
||||||
config.set(("extractor", "twitter" , "username"), None)
|
config.set(("extractor", "twitter" , "username"), None)
|
||||||
|
|
||||||
config.set(("extractor", "mangoxo" , "username"), "LiQiang3")
|
config.set(("extractor", "mangoxo" , "username"), "LiQiang3")
|
||||||
|
|||||||
Reference in New Issue
Block a user