[imgur] add "mp4" config key to decide between GIF and MP4
possible values:
- false : always use GIF
- true : use MP4 if "prefer_video" flag is set,
GIF otherwise (default)
- "always": always use MP4
This commit is contained in:
@@ -20,6 +20,7 @@ class ImgurExtractor(Extractor):
|
|||||||
def __init__(self, match):
|
def __init__(self, match):
|
||||||
Extractor.__init__(self)
|
Extractor.__init__(self)
|
||||||
self.item_id = match.group(1)
|
self.item_id = match.group(1)
|
||||||
|
self.mp4 = self.config("mp4", True)
|
||||||
|
|
||||||
def _get_data(self, urlpart):
|
def _get_data(self, urlpart):
|
||||||
response = self.session.get("https://imgur.com/" + urlpart)
|
response = self.session.get("https://imgur.com/" + urlpart)
|
||||||
@@ -28,9 +29,10 @@ class ImgurExtractor(Extractor):
|
|||||||
data = text.extract(response.text, "image : ", ",\n")[0]
|
data = text.extract(response.text, "image : ", ",\n")[0]
|
||||||
return self._clean(json.loads(data))
|
return self._clean(json.loads(data))
|
||||||
|
|
||||||
@staticmethod
|
def _prepare(self, image):
|
||||||
def _prepare(image):
|
if image["ext"] == ".gif" and (
|
||||||
if image["prefer_video"]:
|
(self.mp4 and image["prefer_video"]) or self.mp4 == "always"
|
||||||
|
):
|
||||||
image["ext"] = ".mp4"
|
image["ext"] = ".mp4"
|
||||||
url = "https://i.imgur.com/" + image["hash"] + image["ext"]
|
url = "https://i.imgur.com/" + image["hash"] + image["ext"]
|
||||||
image["extension"] = image["ext"][1:]
|
image["extension"] = image["ext"][1:]
|
||||||
|
|||||||
Reference in New Issue
Block a user