51 lines
1.6 KiB
Python
Raw Normal View History

2015-12-04 20:33:04 +01:00
# -*- coding: utf-8 -*-
2016-08-03 16:41:45 +02:00
# Copyright 2015,2016 Mike Fährmann
2015-12-04 20:33: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.
"""Extract images from http://chronos.to/"""
from .common import Extractor, Message
from .. import text
2016-08-03 16:41:45 +02:00
class ChronosImageExtractor(Extractor):
2016-09-07 09:40:46 +02:00
"""Extractor for single images from chronos.to"""
2015-12-04 20:33:04 +01:00
category = "chronos"
subcategory = "image"
2015-12-04 20:33:04 +01:00
directory_fmt = ["{category}"]
filename_fmt = "{filename}"
pattern = [r"(?:https?://)?(?:www\.)?chronos\.to/([a-z0-9]{12})"]
2016-09-07 09:40:46 +02:00
url_base = "http://chronos.to/"
2016-08-03 16:41:45 +02:00
test = [("http://chronos.to/bdrmq7rw7v4y", {
"url": "7fcb3fe315c94283644d25ef47a644c2dc8da944",
"keyword": "9c364ef9bd962fe70eca49ef74c1c424486514f9",
"content": "0c8768055e4e20e7c7259608b67799171b691140",
})]
2015-12-04 20:33:04 +01:00
def __init__(self, match):
Extractor.__init__(self)
self.token = match.group(1)
def items(self):
2016-08-03 16:41:45 +02:00
data = {
"category": self.category,
"token": self.token,
}
2015-12-04 20:33:04 +01:00
params = {
"op": "view",
"id": self.token,
"pre": 1,
2016-08-03 16:41:45 +02:00
"next": "Continue+to+image.",
2015-12-04 20:33:04 +01:00
}
2016-09-07 09:40:46 +02:00
page = self.request(self.url_base + self.token, method="post",
2015-12-04 20:33:04 +01:00
data=params).text
2016-08-03 16:41:45 +02:00
url , pos = text.extract(page, '<br><img src="', '"')
2015-12-04 20:33:04 +01:00
filename, pos = text.extract(page, ' alt="', '"', pos)
text.nameext_from_url(filename, data)
yield Message.Version, 1
yield Message.Directory, data
yield Message.Url, url, data