[photobucket] download subalbums (#117)

This commit is contained in:
Mike Fährmann
2019-01-21 19:55:05 +01:00
parent d19bac71be
commit b50b30f1c9
2 changed files with 49 additions and 10 deletions

View File

@@ -14,43 +14,53 @@ import json
class PhotobucketAlbumExtractor(Extractor):
"""Extractor for albums on slideshare.net"""
"""Extractor for albums on photobucket.com"""
category = "photobucket"
subcategory = "album"
directory_fmt = ["{category}", "{username}", "{location}"]
filename_fmt = "{offset:>03}_{pictureId}{title:?_//}.{extension}"
filename_fmt = "{offset:>03}{pictureId:?_//}_{titleOrFilename}.{extension}"
archive_fmt = "{id}"
pattern = [r"(?:https?://)?(?:[^.]+\.)?photobucket\.com"
pattern = [r"(?:https?://)?((?:[^.]+\.)?photobucket\.com)"
r"/user/[^/?&#]+/library/[^?&#]*"]
test = [
("http://s258.photobucket.com/user/focolandia/library/", {
"pattern": r"http://i\d+.photobucket.com/albums/hh280/focolandia",
"count": ">= 39"
}),
("http://s271.photobucket.com/user/lakerfanryan/library/", {
"options": (("image-filter", "False"),),
"pattern": "http://s271.photobucket.com/user/lakerfanryan/library",
"count": ">= 22",
}),
("http://s1110.photobucket.com/user/chndrmhn100/library/"
"Chandu%20is%20the%20King?sort=3&page=1", None),
]
def __init__(self, match):
Extractor.__init__(self)
self.album_path = ""
self.url = match.group(0)
def items(self):
# prevent watermarks
self.root = "http://" + match.group(1)
self.session.headers["Referer"] = self.url
def items(self):
yield Message.Version, 1
for image in self.images():
image["titleOrFilename"] = text.unescape(image["titleOrFilename"])
image["title"] = text.unescape(image["title"])
image["extension"] = image["ext"]
yield Message.Directory, image
yield Message.Url, image["fullsizeUrl"], image
def images(self):
params = {"sort": "3", "page": 1}
return self._pagination(self.url, params)
if self.config("subalbums", True):
for album in self.subalbums():
yield Message.Queue, album["url"], album
def images(self):
"""Yield all images of the current album"""
url = self.url
params = {"sort": "3", "page": 1}
def _pagination(self, url, params):
while True:
page = self.request(url, params=params).text
data = json.loads(text.extract(page, "collectionData:", ",\n")[0])
@@ -58,5 +68,25 @@ class PhotobucketAlbumExtractor(Extractor):
yield from data["items"]["objects"]
if data["total"] <= data["offset"] + data["pageSize"]:
self.album_path = data["currentAlbumPath"]
return
params["page"] += 1
def subalbums(self):
"""Yield all subalbum URLs"""
url = self.root + "/component/Albums-SubalbumList"
params = {"albumPath": self.album_path, "json": "1"}
data = self.request(url, params=params).json()
albums = data["body"]["subAlbums"]
albums.reverse()
while albums:
album = albums.pop()
subs = album.pop("subAlbums")
if subs:
subs.reverse()
albums.extend(subs)
yield album