You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gallery-dl/gallery_dl/extractor/imagetwist.py

39 lines
1.2 KiB

# -*- 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}_{user}_{filename}"
pattern = [r"(?:https?://)?(?:www\.)?imagetwist\.com/([a-z0-9]{12})"]
def __init__(self, match):
Extractor.__init__(self)
self.token = match.group(1)
def items(self):
page = self.request("http://imagetwist.com/" + self.token).text
url , pos = text.extract(page, '<img src="', '"')
filename, pos = text.extract(page, ' alt="', '"', pos)
userid , pos = text.extract(url , '/', '/', 29)
data = {
"category": self.category,
"token": self.token,
"user": userid,
}
text.nameext_from_url(filename, data)
yield Message.Version, 1
yield Message.Directory, data
yield Message.Url, url, data