[imgyt] raise NotFoundError instead of crashing

This commit is contained in:
Mike Fährmann
2017-02-02 15:52:48 +01:00
parent 94e10f249a
commit 2b38398940

View File

@@ -9,7 +9,7 @@
"""Collection of extractors for various imagehosts""" """Collection of extractors for various imagehosts"""
from .common import Extractor, Message from .common import Extractor, Message
from .. import text from .. import text, exception
from os.path import splitext from os.path import splitext
from urllib.parse import urljoin from urllib.parse import urljoin
@@ -64,15 +64,22 @@ class ImgytImageExtractor(ImagehostImageExtractor):
"""Extractor for single images from img.yt""" """Extractor for single images from img.yt"""
category = "imgyt" category = "imgyt"
pattern = [r"(?:https?://)?((?:www\.)?img\.yt/img-([a-z0-9]+)\.html)"] pattern = [r"(?:https?://)?((?:www\.)?img\.yt/img-([a-z0-9]+)\.html)"]
test = [("https://img.yt/img-57a2050547b97.html", { test = [
"url": "6801fac1ff8335bd27a1665ad27ad64cace2cd84", ("https://img.yt/img-57a2050547b97.html", {
"keyword": "7548cc9915f90f5d7ffbafa079085457ae34562c", "url": "6801fac1ff8335bd27a1665ad27ad64cace2cd84",
"content": "54592f2635674c25677c6872db3709d343cdf92f", "keyword": "7548cc9915f90f5d7ffbafa079085457ae34562c",
})] "content": "54592f2635674c25677c6872db3709d343cdf92f",
}),
("https://img.yt/img-57a2050547b98.html", {
"exception": exception.NotFoundError,
}),
]
https = True https = True
def get_info(self, page): def get_info(self, page):
url , pos = text.extract(page, "<img class='centred' src='", "'") url, pos = text.extract(page, "<img class='centred' src='", "'")
if not url:
raise exception.NotFoundError("image")
filename, pos = text.extract(page, " alt='", "'", pos) filename, pos = text.extract(page, " alt='", "'", pos)
filename += splitext(url)[1] if filename else url filename += splitext(url)[1] if filename else url
return url, filename return url, filename