2016-11-03 15:46:04 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2018-01-30 22:49:16 +01:00
|
|
|
# Copyright 2016-2018 Mike Fährmann
|
2016-11-03 15:46:04 +01:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License version 2 as
|
|
|
|
# published by the Free Software Foundation.
|
|
|
|
|
2016-11-03 18:14:33 +01:00
|
|
|
"""Collection of extractors for various imagehosts"""
|
2016-11-03 15:46:04 +01:00
|
|
|
|
|
|
|
from .common import Extractor, Message
|
2017-02-02 15:52:48 +01:00
|
|
|
from .. import text, exception
|
2018-02-22 23:50:50 +01:00
|
|
|
from ..cache import memcache
|
2016-11-03 15:46:04 +01:00
|
|
|
from os.path import splitext
|
2016-11-28 22:30:00 +01:00
|
|
|
from urllib.parse import urljoin
|
2016-11-03 15:46:04 +01:00
|
|
|
|
2017-02-01 00:53:19 +01:00
|
|
|
|
2016-11-03 15:46:04 +01:00
|
|
|
class ImagehostImageExtractor(Extractor):
|
2016-11-03 18:14:33 +01:00
|
|
|
"""Base class for single-image extractors for various imagehosts"""
|
2016-11-03 15:46:04 +01:00
|
|
|
subcategory = "image"
|
2018-01-30 22:49:16 +01:00
|
|
|
archive_fmt = "{token}"
|
2016-11-03 15:46:04 +01:00
|
|
|
https = False
|
|
|
|
method = "post"
|
|
|
|
params = "simple"
|
2016-11-09 12:03:14 +01:00
|
|
|
cookies = None
|
2018-04-09 15:53:20 +02:00
|
|
|
encoding = None
|
2016-11-03 15:46:04 +01:00
|
|
|
|
|
|
|
def __init__(self, match):
|
|
|
|
Extractor.__init__(self)
|
|
|
|
self.url = ("https://" if self.https else "http://") + match.group(1)
|
|
|
|
self.token = match.group(2)
|
|
|
|
if self.params == "simple":
|
|
|
|
self.params = {
|
|
|
|
"imgContinue": "Continue+to+image+...+",
|
|
|
|
}
|
|
|
|
elif self.params == "complex":
|
|
|
|
self.params = {
|
|
|
|
"op": "view",
|
|
|
|
"id": self.token,
|
|
|
|
"pre": "1",
|
|
|
|
"adb": "1",
|
|
|
|
"next": "Continue+to+image+...+",
|
|
|
|
}
|
|
|
|
else:
|
|
|
|
self.params = {}
|
2016-11-04 09:33:38 +01:00
|
|
|
self.method = "get"
|
2016-11-03 15:46:04 +01:00
|
|
|
|
|
|
|
def items(self):
|
2018-04-09 15:53:20 +02:00
|
|
|
page = self.request(
|
|
|
|
self.url,
|
|
|
|
method=self.method,
|
|
|
|
data=self.params,
|
|
|
|
cookies=self.cookies,
|
|
|
|
encoding=self.encoding,
|
|
|
|
).text
|
|
|
|
|
2016-11-03 15:46:04 +01:00
|
|
|
url, filename = self.get_info(page)
|
|
|
|
data = text.nameext_from_url(filename, {"token": self.token})
|
|
|
|
if self.https and url.startswith("http:"):
|
|
|
|
url = "https:" + url[5:]
|
2018-04-09 15:53:20 +02:00
|
|
|
|
2016-11-03 15:46:04 +01:00
|
|
|
yield Message.Version, 1
|
|
|
|
yield Message.Directory, data
|
|
|
|
yield Message.Url, url, data
|
|
|
|
|
2016-11-03 18:14:33 +01:00
|
|
|
def get_info(self, page):
|
|
|
|
"""Find image-url and string to get filename from"""
|
|
|
|
|
2016-11-03 15:46:04 +01:00
|
|
|
|
2018-04-09 15:53:20 +02:00
|
|
|
class ImxtoImageExtractor(ImagehostImageExtractor):
|
|
|
|
"""Extractor for single images from imx.to"""
|
|
|
|
category = "imxto"
|
|
|
|
pattern = [r"(?:https?://)?(?:www\.)?(imx\.to/i/(\w+))",
|
|
|
|
r"(?:https?://)?(?:www\.)?((?:imx\.to|img\.yt)"
|
|
|
|
r"/img-([a-z0-9]+)\.html)"]
|
2017-02-02 15:52:48 +01:00
|
|
|
test = [
|
2018-04-09 15:53:20 +02:00
|
|
|
("https://imx.to/i/1qdeva", { # new-style URL
|
|
|
|
"url": "ab2173088a6cdef631d7a47dec4a5da1c6a00130",
|
|
|
|
"keyword": "7bb48a2327561ae04ea7a6d4e18e715379e2f497",
|
|
|
|
"content": "0c8768055e4e20e7c7259608b67799171b691140",
|
|
|
|
}),
|
|
|
|
("https://imx.to/img-57a2050547b97.html", { # old-style URL
|
|
|
|
"url": "a83fe6ef1909a318c4d49fcf2caf62f36c3f9204",
|
|
|
|
"keyword": "451ad3d4745489c2e663acb1281d89c36ada940a",
|
2017-02-02 15:52:48 +01:00
|
|
|
"content": "54592f2635674c25677c6872db3709d343cdf92f",
|
|
|
|
}),
|
2018-04-09 15:53:20 +02:00
|
|
|
("https://img.yt/img-57a2050547b97.html", { # img.yt domain
|
|
|
|
"url": "a83fe6ef1909a318c4d49fcf2caf62f36c3f9204",
|
|
|
|
}),
|
|
|
|
("https://imx.to/img-57a2050547b98.html", {
|
2017-02-02 15:52:48 +01:00
|
|
|
"exception": exception.NotFoundError,
|
|
|
|
}),
|
|
|
|
]
|
2016-11-03 15:46:04 +01:00
|
|
|
https = True
|
2018-04-09 15:53:20 +02:00
|
|
|
encoding = "utf-8"
|
|
|
|
|
|
|
|
def __init__(self, match):
|
|
|
|
ImagehostImageExtractor.__init__(self, match)
|
|
|
|
if "/img-" in self.url:
|
|
|
|
self.url = self.url.replace("img.yt", "imx.to")
|
|
|
|
self.urlext = True
|
|
|
|
else:
|
|
|
|
self.urlext = False
|
2016-11-03 15:46:04 +01:00
|
|
|
|
|
|
|
def get_info(self, page):
|
2018-04-09 15:53:20 +02:00
|
|
|
url, pos = text.extract(
|
|
|
|
page, '<div style="text-align:center;"><a href="', '"')
|
2017-02-02 15:52:48 +01:00
|
|
|
if not url:
|
|
|
|
raise exception.NotFoundError("image")
|
2018-04-09 15:53:20 +02:00
|
|
|
filename, pos = text.extract(page, ' title="', '"', pos)
|
|
|
|
if self.urlext and filename:
|
|
|
|
filename += splitext(url)[1]
|
|
|
|
return url, filename or url
|
2016-11-03 15:46:04 +01:00
|
|
|
|
2017-02-01 00:53:19 +01:00
|
|
|
|
2018-04-09 15:53:20 +02:00
|
|
|
class AcidimgImageExtractor(ImagehostImageExtractor):
|
2017-09-09 15:17:51 +02:00
|
|
|
"""Extractor for single images from acidimg.cc"""
|
|
|
|
category = "acidimg"
|
|
|
|
pattern = [r"(?:https?://)?((?:www\.)?acidimg\.cc/img-([a-z0-9]+)\.html)"]
|
2018-04-09 15:53:20 +02:00
|
|
|
test = [("https://acidimg.cc/img-5acb6b9de4640.html", {
|
|
|
|
"url": "f132a630006e8d84f52d59555191ed82b3b64c04",
|
|
|
|
"keyword": "183098c59d9244650f666b6cb4df96d76d2aeae8",
|
|
|
|
"content": "0c8768055e4e20e7c7259608b67799171b691140",
|
|
|
|
})]
|
|
|
|
https = True
|
|
|
|
encoding = "utf-8"
|
|
|
|
|
|
|
|
def get_info(self, page):
|
|
|
|
url, pos = text.extract(page, "<img class='centred' src='", "'")
|
|
|
|
if not url:
|
|
|
|
raise exception.NotFoundError("image")
|
|
|
|
filename, pos = text.extract(page, " alt='", "'", pos)
|
|
|
|
return url, (filename + splitext(url)[1]) if filename else url
|
2017-09-09 15:17:51 +02:00
|
|
|
|
|
|
|
|
2016-11-28 22:30:00 +01:00
|
|
|
class ImagevenueImageExtractor(ImagehostImageExtractor):
|
|
|
|
"""Extractor for single images from imagevenue.com"""
|
|
|
|
category = "imagevenue"
|
|
|
|
pattern = [(r"(?:https?://)?(img\d+\.imagevenue\.com/"
|
2017-10-09 22:37:50 +02:00
|
|
|
r"img\.php\?image=(\d+)_[^&#]+)")]
|
2016-11-28 22:30:00 +01:00
|
|
|
params = None
|
|
|
|
|
|
|
|
def get_info(self, page):
|
|
|
|
url = text.extract(page, 'SRC="', '"')[0]
|
|
|
|
url = urljoin(self.url, url)
|
|
|
|
return url, url
|
|
|
|
|
|
|
|
|
2016-11-04 09:33:38 +01:00
|
|
|
class ImagetwistImageExtractor(ImagehostImageExtractor):
|
|
|
|
"""Extractor for single images from imagetwist.com"""
|
|
|
|
category = "imagetwist"
|
|
|
|
pattern = [r"(?:https?://)?((?:www\.)?imagetwist\.com/([a-z0-9]{12}))"]
|
|
|
|
test = [("http://imagetwist.com/4e46hv31tu0q/test.jpg", {
|
2017-06-24 16:21:00 +02:00
|
|
|
"url": "c999dc1a5dec0525ac9eb8c092f173dfe6dba0b0",
|
2016-11-04 09:33:38 +01:00
|
|
|
"keyword": "30dd34dcb06b5b51c6cfff199c610b24edb7b9bc",
|
|
|
|
"content": "96b1fd099b06faad5879fce23a7e4eb8290d8810",
|
|
|
|
})]
|
2017-06-24 16:21:00 +02:00
|
|
|
https = True
|
2016-11-03 15:46:04 +01:00
|
|
|
params = None
|
|
|
|
|
2017-02-08 22:59:00 +01:00
|
|
|
@property
|
2018-02-22 23:50:50 +01:00
|
|
|
@memcache(maxage=3*60*60)
|
2017-02-08 22:59:00 +01:00
|
|
|
def cookies(self):
|
|
|
|
return self.request(self.url).cookies
|
|
|
|
|
2016-11-03 15:46:04 +01:00
|
|
|
def get_info(self, page):
|
2016-11-04 09:33:38 +01:00
|
|
|
url , pos = text.extract(page, 'center;"><img src="', '"')
|
|
|
|
filename, pos = text.extract(page, ' alt="', '"', pos)
|
2016-11-03 15:46:04 +01:00
|
|
|
return url, filename
|
|
|
|
|
2016-11-04 09:33:38 +01:00
|
|
|
|
|
|
|
class ImgspiceImageExtractor(ImagehostImageExtractor):
|
|
|
|
"""Extractor for single images from imgspice.com"""
|
|
|
|
category = "imgspice"
|
|
|
|
pattern = [r"(?:https?://)?((?:www\.)?imgspice\.com/([^/]+))"]
|
2016-11-05 13:51:52 +01:00
|
|
|
test = [("https://imgspice.com/zop38mvvq29u/", {
|
|
|
|
"url": "a45833733c02b64d105363ffd8fd19f06992a2f7",
|
|
|
|
})]
|
2016-11-04 09:33:38 +01:00
|
|
|
https = True
|
|
|
|
params = None
|
|
|
|
|
|
|
|
def get_info(self, page):
|
|
|
|
filename, pos = text.extract(page, '<td nowrap>', '</td>')
|
2017-09-26 17:08:02 +02:00
|
|
|
url , pos = text.extract(page, '<img src="https://img', '"', pos)
|
2018-03-12 21:25:13 +01:00
|
|
|
return "https://img" + url, text.unescape(filename)
|
2017-03-21 15:47:51 +01:00
|
|
|
|
|
|
|
|
2016-11-09 12:03:14 +01:00
|
|
|
class PixhostImageExtractor(ImagehostImageExtractor):
|
|
|
|
"""Extractor for single images from pixhost.org"""
|
|
|
|
category = "pixhost"
|
|
|
|
pattern = [(r"(?:https?://)?((?:www\.)?pixhost\.org/show/"
|
|
|
|
r"\d+/(\d+)_[^/]+)")]
|
2016-12-06 10:03:33 +01:00
|
|
|
https = True
|
2016-11-09 12:03:14 +01:00
|
|
|
params = None
|
|
|
|
cookies = {"pixhostads": "1", "pixhosttest": "1"}
|
|
|
|
|
|
|
|
def get_info(self, page):
|
2017-04-21 13:54:10 +02:00
|
|
|
url , pos = text.extract(page, "class=\"image-img\" src=\"", "\"")
|
|
|
|
filename, pos = text.extract(page, "alt=\"", "\"", pos)
|
2016-12-06 10:03:33 +01:00
|
|
|
return url, filename
|
2016-11-09 12:03:14 +01:00
|
|
|
|
|
|
|
|
2016-12-06 12:46:41 +01:00
|
|
|
class PostimgImageExtractor(ImagehostImageExtractor):
|
|
|
|
"""Extractor for single images from postimg.org"""
|
|
|
|
category = "postimg"
|
|
|
|
pattern = [(r"(?:https?://)?((?:www\.)?(?:postimg|pixxxels)\.org/"
|
|
|
|
r"image/([^/]+)/?)")]
|
|
|
|
https = True
|
|
|
|
params = None
|
|
|
|
|
|
|
|
def get_info(self, page):
|
|
|
|
url = "https:" + text.extract(page, 'data-full="', '"')[0]
|
|
|
|
return url, url
|
|
|
|
|
|
|
|
|
2016-11-04 09:33:38 +01:00
|
|
|
class TurboimagehostImageExtractor(ImagehostImageExtractor):
|
|
|
|
"""Extractor for single images from turboimagehost.com"""
|
|
|
|
category = "turboimagehost"
|
2016-11-05 13:51:52 +01:00
|
|
|
pattern = [(r"(?:https?://)?((?:www\.)?turboimagehost\.com/p/(\d+)"
|
|
|
|
r"/[^/]+\.html)")]
|
2018-03-12 21:25:13 +01:00
|
|
|
test = [("https://www.turboimagehost.com/p/29690902/test--.png.html", {
|
2017-01-27 22:39:44 +01:00
|
|
|
"url": "ada27a4e04f9ffd5ab7cd787f4559d5b3744520b",
|
2016-11-04 09:33:38 +01:00
|
|
|
"keyword": "a4527f14675e4512ef317ee0401940c711fbe012",
|
|
|
|
"content": "0c8768055e4e20e7c7259608b67799171b691140",
|
|
|
|
})]
|
2018-03-06 14:25:10 +01:00
|
|
|
https = True
|
2016-11-04 09:33:38 +01:00
|
|
|
params = None
|
|
|
|
|
|
|
|
def get_info(self, page):
|
2018-03-06 14:25:10 +01:00
|
|
|
needle = '://www.turboimagehost.com"><img src="'
|
2016-11-04 09:33:38 +01:00
|
|
|
url = text.extract(page, needle, '"')[0]
|
|
|
|
return url, url
|