-
-
Notifications
You must be signed in to change notification settings - Fork 950
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[photobucket] add 'album' extractor (#117)
- Loading branch information
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,7 @@ | |
"nijie", | ||
"nyafuu", | ||
"paheal", | ||
"photobucket", | ||
"piczel", | ||
"pinterest", | ||
"pixiv", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright 2019 Mike Fährmann | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License version 2 as | ||
# published by the Free Software Foundation. | ||
|
||
"""Extract images from http://photobucket.com/""" | ||
|
||
from .common import Extractor, Message | ||
from .. import text | ||
import json | ||
|
||
|
||
class PhotobucketAlbumExtractor(Extractor): | ||
"""Extractor for albums on slideshare.net""" | ||
category = "photobucket" | ||
subcategory = "album" | ||
directory_fmt = ["{category}", "{username}", "{location}"] | ||
filename_fmt = "{offset:>03}_{pictureId}{title:?_//}.{extension}" | ||
archive_fmt = "{id}" | ||
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://s1110.photobucket.com/user/chndrmhn100/library/" | ||
"Chandu%20is%20the%20King?sort=3&page=1", None), | ||
] | ||
|
||
def __init__(self, match): | ||
Extractor.__init__(self) | ||
self.url = match.group(0) | ||
|
||
def items(self): | ||
# prevent watermarks | ||
self.session.headers["Referer"] = self.url | ||
|
||
yield Message.Version, 1 | ||
for image in self.images(): | ||
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) | ||
|
||
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"]: | ||
return | ||
params["page"] += 1 |