-
-
Notifications
You must be signed in to change notification settings - Fork 939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[lightroom] add Lightroom gallery extractor #2263
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -69,6 +69,7 @@ | |
"kemonoparty", | ||
"khinsider", | ||
"komikcast", | ||
"lightroom", | ||
"lineblog", | ||
"livedoor", | ||
"luscious", | ||
|
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,103 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# 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. | ||
|
||
"""Extractors for https://lightroom.adobe.com/""" | ||
|
||
from .common import Extractor, Message | ||
from .. import text | ||
import json | ||
|
||
|
||
class LightroomGalleryExtractor(Extractor): | ||
"""Extractor for an image gallery on lightroom.adobe.com""" | ||
category = "lightroom" | ||
subcategory = "gallery" | ||
directory_fmt = ("{category}", "{user}", "{title}") | ||
filename_fmt = "{num:>04}_{id}.{extension}" | ||
archive_fmt = "{id}" | ||
pattern = r"(?:https?://)?lightroom\.adobe\.com/shares/([0-9a-f]+)" | ||
test = ( | ||
(("https://lightroom.adobe.com/shares/" | ||
"0c9cce2033f24d24975423fe616368bf"), { | ||
"keyword": { | ||
"title": "Sterne und Nachtphotos", | ||
"user": "Christian Schrang", | ||
}, | ||
"count": ">= 55", | ||
}), | ||
(("https://lightroom.adobe.com/shares/" | ||
"7ba68ad5a97e48608d2e6c57e6082813"), { | ||
"keyword": { | ||
"title": "HEBFC Snr/Res v Brighton", | ||
"user": "", | ||
}, | ||
"count": ">= 180", | ||
}), | ||
) | ||
|
||
def __init__(self, match): | ||
Extractor.__init__(self, match) | ||
self.href = match.group(1) | ||
|
||
def items(self): | ||
# Get config | ||
url = "https://lightroom.adobe.com/shares/" + self.href | ||
response = self.request(url) | ||
album = json.loads( | ||
text.extract(response.text, "albumAttributes: ", "\n")[0] | ||
) | ||
|
||
images = self.images(album) | ||
for img in images: | ||
url = img["url"] | ||
yield Message.Directory, img | ||
yield Message.Url, url, text.nameext_from_url(url, img) | ||
|
||
def metadata(self, album): | ||
payload = album["payload"] | ||
story = payload.get("story") or {} | ||
return { | ||
"gallery_id": self.href, | ||
"user": story.get("author", ""), | ||
"title": story.get("title", payload["name"]), | ||
} | ||
|
||
def images(self, album): | ||
album_md = self.metadata(album) | ||
base_url = album["base"] | ||
next_url = album["links"]["/rels/space_album_images_videos"]["href"] | ||
num = 1 | ||
|
||
while next_url: | ||
url = base_url + next_url | ||
page = self.request(url).text | ||
# skip 1st line as it's a JS loop | ||
data = json.loads(page[page.index("\n") + 1:]) | ||
|
||
base_url = data["base"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This overrides the |
||
for res in data["resources"]: | ||
img_url, img_size = None, 0 | ||
for key, value in res["asset"]["links"].items(): | ||
if not key.startswith("/rels/rendition_type/"): | ||
continue | ||
size = text.parse_int(key.split("/")[-1]) | ||
if size > img_size: | ||
img_size = size | ||
img_url = value["href"] | ||
|
||
if img_url: | ||
img = { | ||
"id": res["asset"]["id"], | ||
"num": num, | ||
"url": base_url + img_url, | ||
} | ||
img.update(album_md) | ||
yield img | ||
num += 1 | ||
try: | ||
next_url = data["links"]["next"]["href"] | ||
except KeyError: | ||
next_url = None |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't hurt having
(?:www\.)?
just in case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
www
subdomain doesn't exist, so such an URL wouldn't work anyway.