mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-24 19:52:32 +01:00
[imagebam] update to new extractor interface
This commit is contained in:
parent
758fe00441
commit
e41768d969
@ -1,20 +1,48 @@
|
||||
from .common import AsyncExtractor
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
class Extractor(AsyncExtractor):
|
||||
# Copyright 2014, 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 galleries at http://www.imagebam.com/"""
|
||||
|
||||
from .common import AsynchronousExtractor
|
||||
from .common import Message
|
||||
from .common import filename_from_url
|
||||
|
||||
info = {
|
||||
"category": "imagebam",
|
||||
"extractor": "ImagebamExtractor",
|
||||
"directory": ["{category}", "{title} - {key}"],
|
||||
"filename": "{num:>03}-{name}",
|
||||
"pattern": [
|
||||
r"(?:https?://)?(?:www\.)?imagebam\.com/(gallery)/([^/]+).*",
|
||||
],
|
||||
}
|
||||
|
||||
class ImagebamExtractor(AsynchronousExtractor):
|
||||
|
||||
url_base = "http://www.imagebam.com"
|
||||
|
||||
def __init__(self, match, config):
|
||||
AsyncExtractor.__init__(self, config)
|
||||
title, key = self.get_title(match)
|
||||
self.category = "imagebam"
|
||||
self.directory = title + " - " + key
|
||||
AsynchronousExtractor.__init__(self, config)
|
||||
self.match = match
|
||||
self.num = 0
|
||||
self.metadata = {}
|
||||
|
||||
def images(self):
|
||||
next_url = self.url
|
||||
num = 1
|
||||
def items(self):
|
||||
self.num = 0
|
||||
self.metadata = self.get_job_metadata()
|
||||
yield Message.Version, 1
|
||||
yield Message.Directory, self.metadata
|
||||
|
||||
next_url = self.metadata["first-url"]
|
||||
done = False
|
||||
while not done:
|
||||
# get current page
|
||||
text = self.request("http://www.imagebam.com" + next_url).text
|
||||
text = self.request(self.url_base + next_url).text
|
||||
|
||||
# get url for next page
|
||||
next_url, pos = self.extract(text, "<a class='buttonblue' href='", "'")
|
||||
@ -24,24 +52,30 @@ class Extractor(AsyncExtractor):
|
||||
done = True
|
||||
|
||||
# get image url
|
||||
img_url , pos = self.extract(text, 'onclick="scale(this);" src="', '"', pos)
|
||||
img_url, pos = self.extract(text, 'onclick="scale(this);" src="', '"', pos)
|
||||
|
||||
# extract filename from image url
|
||||
name = img_url[img_url.rindex("/")+1:]
|
||||
yield Message.Url, img_url, self.get_file_metadata(img_url)
|
||||
|
||||
yield img_url, "{:>03}-{}".format(num, name)
|
||||
num += 1
|
||||
def get_job_metadata(self):
|
||||
"""Collect metadata for extractor-job"""
|
||||
gallery_key = self.match.group(2)
|
||||
text = self.request(self.url_base + "/gallery/" + gallery_key).text
|
||||
_ , pos = self.extract(text, "<img src='/img/icons/photos.png'", "")
|
||||
title, pos = self.extract(text, "'> ", " <", pos)
|
||||
count, pos = self.extract(text, "'>", " images", pos)
|
||||
url , pos = self.extract(text, "<a href='http://www.imagebam.com", "'", pos)
|
||||
return {
|
||||
"category": info["category"],
|
||||
"key": gallery_key,
|
||||
"title": title,
|
||||
"count": count,
|
||||
"first-url": url,
|
||||
}
|
||||
|
||||
def get_title(self, match):
|
||||
if match.group(1) == "image":
|
||||
text = self.request(match.group(0)).text
|
||||
gallery_url, _ = self.extract(text, "class='gallery_title'><a href='", "'")
|
||||
gallery_key = gallery_url.split("/")[-2]
|
||||
else:
|
||||
gallery_key = match.group(2)
|
||||
|
||||
text = self.request("http://www.imagebam.com/gallery/" + gallery_key).text
|
||||
_ , pos = self.extract(text, "<img src='/img/icons/photos.png'", "")
|
||||
title , pos = self.extract(text, "'> ", " <", pos)
|
||||
self.url, pos = self.extract(text, "<a href='http://www.imagebam.com", "'", pos)
|
||||
return title, gallery_key
|
||||
def get_file_metadata(self, url):
|
||||
"""Collect metadata for a downloadable file"""
|
||||
self.num += 1
|
||||
data = self.metadata.copy()
|
||||
data["num"] = self.num
|
||||
data["name"] = filename_from_url(url)
|
||||
return data
|
||||
|
Loading…
Reference in New Issue
Block a user