aboutsummaryrefslogtreecommitdiffstats
path: root/gallery_dl/extractor/photovogue.py
blob: cb16b232513e03d9f15006161453fe989ba2f814 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# -*- 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.com/photovogue/"""

from .common import Extractor, Message
from .. import text

BASE_PATTERN = r"(?:https?://)?(?:www\.)?vogue\.com/photovogue"


class PhotovogueUserExtractor(Extractor):
    category = "photovogue"
    subcategory = "user"
    directory_fmt = ("{category}", "{photographer[id]} {photographer[name]}")
    filename_fmt = "{id} {title}.{extension}"
    archive_fmt = "{id}"
    pattern = rf"{BASE_PATTERN}/photographers/(\d+)"
    example = "https://www.vogue.com/photovogue/photographers/12345"

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

    def items(self):
        for photo in self.photos():
            url = photo["gallery_image"]
            photo["title"] = photo["title"].strip()
            photo["date"] = self.parse_datetime_iso(photo["date"])

            yield Message.Directory, "", photo
            yield Message.Url, url, text.nameext_from_url(url, photo)

    def photos(self):
        url = "https://api.vogue.com/production/photos"
        params = {
            "count": "50",
            "order_by": "DESC",
            "page": 0,
            "photographer_id": self.user_id,
        }

        while True:
            data = self.request_json(url, params=params)
            yield from data["items"]

            if not data["has_next"]:
                break
            params["page"] += 1