Skip to content

Commit

Permalink
[imagefap] deal with long filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Aug 11, 2016
1 parent 406add2 commit fa14ef1
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions gallery_dl/extractor/imagefap.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,40 +31,44 @@ def __init__(self, match):
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



Expand Down

0 comments on commit fa14ef1

Please sign in to comment.