Debian Codegraph @

gallery_dl/extractor/photovogue.py

raw
1 # -*- coding: utf-8 -*-
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License version 2 as
5 # published by the Free Software Foundation.
6
7 """Extractors for https://www.vogue.com/photovogue/"""
8
9 from .common import Extractor, Message
10 from .. import text
11
12 BASE_PATTERN = r"(?:https?://)?(?:www\.)?vogue\.com/photovogue"
13
14
15 class PhotovogueUserExtractor(Extractor):
16 category = "photovogue"
17 subcategory = "user"
18 directory_fmt = ("{category}", "{photographer[id]} {photographer[name]}")
19 filename_fmt = "{id} {title}.{extension}"
20 archive_fmt = "{id}"
21 pattern = BASE_PATTERN + r"/photographers/(\d+)"
22 example = "https://www.vogue.com/photovogue/photographers/12345"
23
24 def __init__(self, match):
25 Extractor.__init__(self, match)
26 self.user_id = match[1]
27
28 def items(self):
29 for photo in self.photos():
30 url = photo["gallery_image"]
31 photo["title"] = photo["title"].strip()
32 photo["date"] = self.parse_datetime_iso(photo["date"])
33
34 yield Message.Directory, "", photo
35 yield Message.Url, url, text.nameext_from_url(url, photo)
36
37 def photos(self):
38 url = "https://api.vogue.com/production/photos"
39 params = {
40 "count": "50",
41 "order_by": "DESC",
42 "page": 0,
43 "photographer_id": self.user_id,
44 }
45
46 while True:
47 data = self.request_json(url, params=params)
48 yield from data["items"]
49
50 if not data["has_next"]:
51 break
52 params["page"] += 1