Skip to content

Commit

Permalink
[photobucket] improve subalbum extraction (#117)
Browse files Browse the repository at this point in the history
The former implementation would produce a complete list of all subalbums
for each (sub)album extraction. This would for example result in a
level 2 subalbum getting "extracted" twice: once through the root-album
(level 0) and once through its parent album on level 1.

In the current implementation only the next level of subalbums are
returned, which themselves will handle their next level in a recursive
fashion.
  • Loading branch information
mikf committed Jan 22, 2019
1 parent ecad691 commit c5559fa
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions gallery_dl/extractor/photobucket.py
Expand Up @@ -30,8 +30,12 @@ class PhotobucketAlbumExtractor(Extractor):
}),
("http://s271.photobucket.com/user/lakerfanryan/library/", {
"options": (("image-filter", "False"),),
"pattern": "http://s271.photobucket.com/user/lakerfanryan/library",
"count": ">= 22",
"pattern": pattern[0],
"count": 1,
}),
("http://s271.photobucket.com/user/lakerfanryan/library/Basketball", {
"pattern": pattern[0],
"count": ">= 9",
}),
("http://s1110.photobucket.com/user/chndrmhn100/library/"
"Chandu%20is%20the%20King?sort=3&page=1", None),
Expand Down Expand Up @@ -74,23 +78,17 @@ def images(self):
params["page"] += 1

def subalbums(self):
"""Yield all subalbum URLs"""
"""Return all subalbum objects"""
url = self.root + "/component/Albums-SubalbumList"
params = {"albumPath": self.album_path, "json": "1"}
params = {
"albumPath": self.album_path,
"fetchSubAlbumsOnly": "true",
"deferCollapsed": "true",
"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
return data["body"]["subAlbums"]


class PhotobucketImageExtractor(Extractor):
Expand Down

0 comments on commit c5559fa

Please sign in to comment.