[imagefap] deal with long filenames

This commit is contained in:
Mike Fährmann 2016-08-11 15:50:32 +02:00
parent 406add217c
commit fa14ef17ea
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

View File

@ -31,40 +31,44 @@ class ImagefapGalleryExtractor(Extractor):
self.gid = match.group(1)
def items(self):
imgurl_fmt = ("http://x.imagefapusercontent.com/u/{uploader}/"
"{gallery-id}/{image-id}/{filename}")
url = "http://www.imagefap.com/pictures/" + self.gid + "/?view=2"
url = "http://www.imagefap.com/pictures/" + self.gid + "/"
page = self.request(url).text
data = self.get_job_metadata(page)
yield Message.Version, 1
yield Message.Directory, data
for image in self.get_images(page):
for url, image in self.get_images(int(data["count"])):
data.update(image)
yield Message.Url, imgurl_fmt.format(**data), data
yield Message.Url, url, data
def get_job_metadata(self, page):
"""Collect metadata for extractor-job"""
data = text.extract_all(page, (
data, pos = text.extract_all(page, (
("section" , '<meta name="description" content="', '"'),
("title" , '<title>Porn pics of ', ' (Page 1)</title>'),
("uploader", '>Uploaded by ', '</font>'),
("count" , ' 1 of ', ' pics"'),
), values={"category": self.category, "gallery-id": self.gid})[0]
), values={"category": self.category, "gallery-id": self.gid})
self.image_id = text.extract(page, 'id="img_ed_', '"', pos)[0]
data["title"] = text.unescape(data["title"])
return data
@staticmethod
def get_images(page):
"""Collect image-metadata"""
pos = 0
def get_images(self, count):
"""Collect image-urls and -metadata"""
num = 0
url = "http://www.imagefap.com/photo/" + self.image_id + "/"
params = {"gid": self.gid, "idx": 0, "partial": "true"}
while True:
imgid, pos = text.extract(page, '<td id="', '"', pos)
if not imgid:
return
name , pos = text.extract(page, '<i>', '</i>', pos)
num += 1
yield text.nameext_from_url(name, {"image-id": imgid, "num": num})
pos = 0
page = self.request(url, params=params).text
for i in range(24):
imgurl, pos = text.extract(page, '<a href="', '"', pos)
num += 1
_, imgid, name = imgurl.rsplit("/", 2)
data = {"image-id": imgid, "num": num}
yield imgurl, text.nameext_from_url(name, data)
if num >= count:
return
params["idx"] += 24