Skip to content
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

[photovogue] added portfolio extractor #1253

Merged
merged 1 commit into from
Jan 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/supportedsites.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Nyafuu Archive https://archive.nyafuu.org/ Boards, Search Results,
Patreon https://www.patreon.com/ Creators, Posts, User Profiles `Cookies <https://github.com/mikf/gallery-dl#cookies>`__
Pawoo https://pawoo.net/ Images from Statuses, User Profiles `OAuth <https://github.com/mikf/gallery-dl#oauth>`__
Photobucket https://photobucket.com/ Albums, individual Images
PhotoVogue https://www.vogue.it/en/photovogue/ User profiles
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The contents of this file are auto-generated by supportedsites.py
Update CATEGORY_MAP in there if necessary and run it once.

Piczel https://piczel.tv/ Folders, individual Images, User Profiles
Pinterest https://www.pinterest.com/ |pinterest-C| Supported
Pixiv https://www.pixiv.net/ |pixiv-C| Required
Expand Down
1 change: 1 addition & 0 deletions gallery_dl/extractor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"paheal",
"patreon",
"photobucket",
"photovogue",
"piczel",
"pinterest",
"pixiv",
Expand Down
70 changes: 70 additions & 0 deletions gallery_dl/extractor/photovogue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# -*- 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://www.vogue.it/en/photovogue/"""

from .common import Extractor, Message
from datetime import datetime

BASE_PATTERN = r"(?:https?://)?(?:www.vogue.it(?:/en)?/photovogue)"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
BASE_PATTERN = r"(?:https?://)?(?:www.vogue.it(?:/en)?/photovogue)"
BASE_PATTERN = r"(?:https?://)?(?:www\.)?vogue\.it/(?:en/)?photovogue"

This would also allow non-www URLs



class PhotovogueUserExtractor(Extractor):
category = "photovogue"
subcategory = "user"
directory_fmt = ("{category}", "{photographer[id]}_{photographer[name]}")
filename_fmt = "{id}_{title}.{extension}"
archive_fmt = "{id}"
root = "https://www.vogue.it/en/photovogue/"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
root = "https://www.vogue.it/en/photovogue/"
root = "https://www.vogue.it/en/photovogue"

by convention, root doesn't end with a /

pattern = BASE_PATTERN + r"/portfolio/\?id=(\d+)"
test = (
("https://www.vogue.it/en/photovogue/portfolio/?id=221252",),
("https://www.vogue.it/photovogue/portfolio/?id=221252",),
Comment on lines +24 to +25
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
("https://www.vogue.it/en/photovogue/portfolio/?id=221252",),
("https://www.vogue.it/photovogue/portfolio/?id=221252",),
("https://www.vogue.it/en/photovogue/portfolio/?id=221252"),
("https://vogue.it/photovogue/portfolio/?id=221252"),

Tests should either be a single string or a (url, results) tuple.
python test_results.py photovogue fails when they are single-element tuples.

)

def __init__(self, match):
Extractor.__init__(self, match)
self.user_id = match.group(1)

def _photos(self):
page = 0

while True:
res = self.request(
"https://api.vogue.it/production/photos",
params={
"count": 50,
"order_by": "DESC",
"page": page,
"photographer_id": self.user_id,
},
).json()
Comment on lines +36 to +44
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just personal preference, but I'd prepare url and params before the loop, and then just call
res = self.request(url, params=params).json() inside the loop.

This would also get rid of the page variable, since you could just do params["page"] += 1 instead.


for item in res["items"]:
item["extension"] = "jpg"
item["title"] = item["title"].strip()
item["_mtime"] = datetime.fromisoformat(
item["date"].replace("Z", "+00:00")
).timestamp()

yield item
Comment on lines +46 to +53
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just do a yield from res["items"] and do all other processing outside.

Speaking of.

  • add from .. import text at the very top
  • item["extension"] = "jpg" -> text.nameext_from_url(<image url>, item)
  • item["_mtime"] = … -> item["date"] = text.parse_datetime(item["date"], "%Y-%m-%dT%H:%M:%S.%f%z")
    • by convention, date is a datetime object
    • photovogue images have a Last-Modified header, so mtime modification should happen automatically. If you want the contents of date as mtime, use --mtime-from-date or the mtime post processor.


if not res["has_next"]:
break

page += 1

def items(self):
yield Message.Version, 1

yielded_dir = False

for photo in self._photos():
if not yielded_dir:
yield Message.Directory, photo
yielded_dir = True

yield Message.Url, photo["gallery_image"], photo