From 834e9000377ddad3f1f1727ec05187292a6e99c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sun, 12 Jun 2022 18:26:20 +0200 Subject: [PATCH] =?UTF-8?q?[unsplash]=20add=20collection=5Ftitle=20and=20?= =?UTF-8?q?=E2=80=A6=5Fid=20metadata=20fields=20(#2670)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gallery_dl/extractor/unsplash.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/gallery_dl/extractor/unsplash.py b/gallery_dl/extractor/unsplash.py index ad1617c0..c29d730d 100644 --- a/gallery_dl/extractor/unsplash.py +++ b/gallery_dl/extractor/unsplash.py @@ -30,12 +30,16 @@ class UnsplashExtractor(Extractor): def items(self): fmt = self.config("format") or "raw" + metadata = self.metadata() + for photo in self.photos(): util.delete_items( photo, ("current_user_collections", "related_collections")) url = photo["urls"][fmt] text.nameext_from_url(url, photo) + if metadata: + photo.update(metadata) photo["extension"] = "jpg" photo["date"] = text.parse_datetime(photo["created_at"]) if "tags" in photo: @@ -44,6 +48,10 @@ class UnsplashExtractor(Extractor): yield Message.Directory, photo yield Message.Url, url, photo + @staticmethod + def metadata(): + return None + def skip(self, num): pages = num // self.per_page self.page_start += pages @@ -172,17 +180,27 @@ class UnsplashFavoriteExtractor(UnsplashExtractor): class UnsplashCollectionExtractor(UnsplashExtractor): """Extractor for an unsplash collection""" subcategory = "collection" - pattern = BASE_PATTERN + r"/collections/([^/?#]+)" + pattern = BASE_PATTERN + r"/collections/([^/?#]+)(?:/([^/?#]+))?" test = ( ("https://unsplash.com/collections/3178572/winter", { "pattern": r"https://images\.unsplash\.com/(photo-\d+-\w+" r"|reserve/[^/?#]+)\?ixid=\w+&ixlib=rb-1\.2\.1$", + "keyword": {"collection_id": "3178572", + "collection_title": "winter"}, "range": "1-30", "count": 30, }), + ("https://unsplash.com/collections/3178572/"), ("https://unsplash.com/collections/_8qJQ2bCMWE/2021.05"), ) + def __init__(self, match): + UnsplashExtractor.__init__(self, match) + self.title = match.group(2) or "" + + def metadata(self): + return {"collection_id": self.item, "collection_title": self.title} + def photos(self): url = "{}/napi/collections/{}/photos".format(self.root, self.item) params = {"order_by": "latest"}