Skip to content

Commit

Permalink
[photobucket] download subalbums (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Jan 22, 2019
1 parent d19bac7 commit b50b30f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 8 deletions.
9 changes: 9 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,15 @@ Description Controls how a user is directed to an OAuth authorization site.
=========== =====


extractor.photobucket.subalbums
-------------------------------
=========== =====
Type ``bool``
Default ``true``
Description Download subalbums.
=========== =====


extractor.pixiv.ugoira
----------------------
=========== =====
Expand Down
46 changes: 38 additions & 8 deletions gallery_dl/extractor/photobucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,49 +14,79 @@


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

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}
return self._pagination(self.url, params)

def _pagination(self, url, params):
while True:
page = self.request(url, params=params).text
data = json.loads(text.extract(page, "collectionData:", ",\n")[0])

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

0 comments on commit b50b30f

Please sign in to comment.