1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 02:32:33 +01:00

[imagetwist] add extractor

This commit is contained in:
Mike Fährmann 2015-12-03 00:16:36 +01:00
parent 810aa4e146
commit 56876b76f1
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
2 changed files with 39 additions and 0 deletions

View File

@ -25,6 +25,7 @@ modules = [
"hentaifoundry",
"hitomi",
"imagebam",
"imagetwist",
"imgbox",
"imgchili",
"imgth",

View File

@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
# Copyright 2015 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.
"""Extract images from http://imagetwist.com/"""
from .common import Extractor, Message
from .. import text
class ImagetwistExtractor(Extractor):
category = "imagetwist"
directory_fmt = ["{category}"]
filename_fmt = "{category}_{index}_{filename}"
pattern = [r"(?:https?://)?(?:www\.)?imagetwist\.com/([^/]+)"]
def __init__(self, match):
Extractor.__init__(self)
self.token = match.group(1)
def items(self):
yield Message.Version, 1
page = self.request("http://imagetwist.com/" + self.token).text
url , pos = text.extract(page, '<img src="', '"')
filename, pos = text.extract(page, ' alt="', '"', pos)
index , pos = text.extract(url , '/', '/', 29)
data = {
"category": self.category,
"token": self.token,
"index": index,
}
text.nameext_from_url(filename, data)
yield Message.Directory, data
yield Message.Url, url, data