1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-23 19:22:32 +01:00
gallery-dl/gallery_dl/extractor/imagehosts.py

356 lines
12 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
# Copyright 2016-2018 Mike Fährmann
#
# 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"""
from .common import Extractor, Message
from .. import text, exception
2017-02-08 22:59:00 +01:00
from ..cache import cache
from os.path import splitext
2016-11-28 22:30:00 +01:00
from urllib.parse import urljoin
2017-02-01 00:53:19 +01:00
class ImagehostImageExtractor(Extractor):
2016-11-03 18:14:33 +01:00
"""Base class for single-image extractors for various imagehosts"""
subcategory = "image"
archive_fmt = "{token}"
https = False
method = "post"
params = "simple"
2016-11-09 12:03:14 +01:00
cookies = None
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"
def items(self):
2016-11-09 12:03:14 +01:00
page = self.request(self.url, method=self.method, data=self.params,
cookies=self.cookies).text
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:]
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"""
return "url", "filename"
class ImgytImageExtractor(ImagehostImageExtractor):
"""Extractor for single images from img.yt"""
category = "imgyt"
pattern = [r"(?:https?://)?((?:www\.)?img\.yt/img-([a-z0-9]+)\.html)"]
test = [
("https://img.yt/img-57a2050547b97.html", {
"url": "6801fac1ff8335bd27a1665ad27ad64cace2cd84",
"keyword": "7548cc9915f90f5d7ffbafa079085457ae34562c",
"content": "54592f2635674c25677c6872db3709d343cdf92f",
}),
("https://img.yt/img-57a2050547b98.html", {
"exception": exception.NotFoundError,
}),
]
https = True
def get_info(self, page):
2017-09-14 14:59:04 +02:00
url, pos = text.extract(page, "<img class='centred' src='", "'")
if not url:
raise exception.NotFoundError("image")
2017-09-14 14:59:04 +02:00
filename, pos = text.extract(page, " alt='", "'", pos)
filename = (filename + splitext(url)[1]) if filename else url
return url, filename
2017-02-01 00:53:19 +01:00
2017-03-21 15:47:51 +01:00
class ImgcandyImageExtractor(ImgytImageExtractor):
"""Extractor for single images from imgcandy.net"""
category = "imgcandy"
pattern = [(r"(?:https?://)?((?:www\.)?imgcandy\.net/img-([a-z0-9]+))"
r"(?:_.+)?\.html")]
test = [("http://imgcandy.net/img-57d02527efee8_test.png.html", {
"url": "bc3c9207b10dbfe8e65ccef5b9e3194a7427b4fa",
"keyword": "d3157ff8a33c56a8ec12931a3c098068e5a35cf5",
"content": "0c8768055e4e20e7c7259608b67799171b691140",
})]
https = False
def __init__(self, match):
ImgytImageExtractor.__init__(self, match)
self.url = "http://" + match.group(1) + ".html"
class RapidimgImageExtractor(ImgytImageExtractor):
"""Extractor for single images from rapidimg.net"""
category = "rapidimg"
2017-02-01 00:53:19 +01:00
pattern = [r"(?:https?://)?((?:www\.)?rapidimg\.net/"
r"img-([a-z0-9]+)\.html)"]
test = []
https = False
2017-02-01 00:53:19 +01:00
2016-12-07 08:45:52 +01:00
class FapatImageExtractor(ImgytImageExtractor):
"""Extractor for single images from fapat.me"""
category = "fapat"
pattern = [r"(?:https?://)?((?:www\.)?fapat\.me/img-([a-z0-9]+)\.html)"]
test = []
https = False
2017-09-09 15:17:51 +02:00
class AcidimgImageExtractor(ImgytImageExtractor):
"""Extractor for single images from acidimg.cc"""
category = "acidimg"
pattern = [r"(?:https?://)?((?:www\.)?acidimg\.cc/img-([a-z0-9]+)\.html)"]
test = []
2016-11-03 18:14:33 +01:00
class ChronosImageExtractor(ImagehostImageExtractor):
"""Extractor for single images from chronos.to"""
category = "chronos"
pattern = [r"(?:https?://)?((?:www\.)?chronos\.to/([a-z0-9]{12}))"]
test = [
("http://chronos.to/bdrmq7rw7v4y", {
"url": "7fcb3fe315c94283644d25ef47a644c2dc8da944",
"keyword": "04dbc71a1154728d01c931308184050d61c5da55",
"content": "0c8768055e4e20e7c7259608b67799171b691140",
}),
("http://chronos.to/bdrmq7rw7v4z", {
"exception": exception.NotFoundError,
}),
]
2016-11-03 18:14:33 +01:00
https = False
params = "complex"
def get_info(self, page):
url, pos = text.extract(page, '<br><img src="', '"')
if not url:
raise exception.NotFoundError("image")
2016-11-03 18:14:33 +01:00
filename, pos = text.extract(page, ' alt="', '"', pos)
return url, filename
2017-02-01 00:53:19 +01:00
2016-11-03 18:14:33 +01:00
class CoreimgImageExtractor(ChronosImageExtractor):
"""Extractor for single images from coreimg.net"""
category = "coreimg"
pattern = [r"(?:https?://)?((?:www\.)?coreimg\.net/([a-z0-9]{12}))"]
test = [("http://coreimg.net/ykcl5al8uzvg", {
"url": "2b32596a2ea66b7cc784e20f3749f75f20998d78",
"keyword": "8d71e5b820bc7177baee33ca529c91ae4521299f",
"content": "0c8768055e4e20e7c7259608b67799171b691140",
})]
2017-02-01 00:53:19 +01:00
2016-11-08 00:17:10 +01:00
class ImgmaidImageExtractor(ChronosImageExtractor):
"""Extractor for single images from imgmaid.net"""
category = "imgmaid"
pattern = [r"(?:https?://)?((?:www\.)?imgmaid\.net/([a-z0-9]{12}))"]
test = []
https = True
2017-02-01 00:53:19 +01:00
2016-11-03 18:14:33 +01:00
class PicmaniacImageExtractor(ChronosImageExtractor):
"""Extractor for single images from pic-maniac.com"""
category = "picmaniac"
pattern = [r"(?:https?://)?((?:www\.)?pic-maniac\.com/([a-z0-9]{12}))"]
test = []
class HosturimageImageExtractor(ImagehostImageExtractor):
"""Extractor for single images from hosturimage.com"""
category = "hosturimage"
2016-11-05 13:51:52 +01:00
pattern = [(r"(?:https?://)?((?:www\.)?hosturimage\.com/"
r"img-([a-z0-9]+)\.html)")]
test = [("https://hosturimage.com/img-581ca97112bf8.html", {
"url": "c672a3fd7fd48e5506d020aa19c4ac91ba078671",
"keyword": "c3c94340b8e395e07b5145cf17534b5871ec8593",
"content": "0c8768055e4e20e7c7259608b67799171b691140",
})]
https = True
def get_info(self, page):
pos = page.index("<img class='centred")
url = text.extract(page, " src='", "'", pos)[0]
return url, url
2017-02-01 00:53:19 +01:00
class ImageontimeImageExtractor(HosturimageImageExtractor):
"""Extractor for single images from imageontime.org"""
category = "imageontime"
2016-11-05 13:51:52 +01:00
pattern = [(r"(?:https?://)?((?:www\.)?imageontime\.org/"
r"img-([a-z0-9]+)\.html)")]
test = []
https = False
2017-02-01 00:53:19 +01:00
2016-11-08 00:16:47 +01:00
class Img4everImageExtractor(HosturimageImageExtractor):
"""Extractor for single images from img4ever.net"""
category = "img4ever"
pattern = [(r"(?:https?://)?((?:www\.)?img4ever\.net/"
r"img-([a-z0-9]+)\.html)")]
test = []
https = True
2017-02-01 00:53:19 +01:00
class ImguploadImageExtractor(HosturimageImageExtractor):
"""Extractor for single images from imgupload.yt"""
category = "imgupload"
2016-11-05 13:51:52 +01:00
pattern = [(r"(?:https?://)?((?:www\.)?imgupload\.yt/"
r"img-([a-z0-9]+)\.html)")]
test = []
https = True
2016-11-13 21:24:38 +01:00
class ImgspotImageExtractor(ImagehostImageExtractor):
"""Extractor for single images from imgspot.org"""
category = "imgspot"
pattern = [r"(?:https?://)?((?:www\.)?imgspot\.org/img-([a-z0-9]+)\.html)"]
https = False
def get_info(self, page):
url = text.extract(page, "<img class='centred_resized' src='", "'")[0]
return url, url
2017-02-01 00:53:19 +01:00
2016-11-13 21:25:37 +01:00
class ImgtrialImageExtractor(ImgspotImageExtractor):
"""Extractor for single images from imgtrial.com"""
category = "imgtrial"
2017-02-01 00:53:19 +01:00
pattern = [r"(?:https?://)?((?:www\.)?imgtrial\.com"
r"/img-([a-z0-9]+)\.html)"]
2016-11-13 21:25:37 +01:00
2016-11-13 21:24:38 +01: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
params = None
2017-02-08 22:59:00 +01:00
@property
@cache(maxage=3*60*60)
def cookies(self):
return self.request(self.url).cookies
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)
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)
2016-11-29 17:11:41 +01:00
return "http://img" + url, text.unescape(filename)
2016-11-04 09:33:38 +01:00
2017-03-21 15:47:51 +01:00
class ImgtrexImageExtractor(ImagehostImageExtractor):
"""Extractor for single images from imgtrex.com"""
category = "imgtrex"
pattern = [r"(?:https?://)?((?:www\.)?imgtrex\.com/([^/]+))"]
2017-03-28 13:12:44 +02:00
test = [("http://imgtrex.com/im0ypxq0rke4/test-&<a>.png", {
2017-03-21 15:47:51 +01:00
"url": "c000618bddda42bd599a590b7972c7396d19d8fe",
"keyword": "58905795a9cd3f17d5ff024fc4d63645795ba23c",
"content": "0c8768055e4e20e7c7259608b67799171b691140",
})]
params = None
def get_info(self, page):
filename, pos = text.extract(page, '<title>ImgTrex: ', '</title>')
url , pos = text.extract(page, '<br>\n<img src="', '"', pos)
return url, filename
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)")]
2016-11-04 09:33:38 +01:00
test = [("http://www.turboimagehost.com/p/29690902/test--.png.html", {
"url": "ada27a4e04f9ffd5ab7cd787f4559d5b3744520b",
2016-11-04 09:33:38 +01:00
"keyword": "a4527f14675e4512ef317ee0401940c711fbe012",
"content": "0c8768055e4e20e7c7259608b67799171b691140",
})]
params = None
def get_info(self, page):
needle = '<a href="http://www.turboimagehost.com"><img src="'
url = text.extract(page, needle, '"')[0]
return url, url