[unsplash] add 'collection' extractor (#1197)

This commit is contained in:
Mike Fährmann
2021-01-21 22:27:43 +01:00
parent 247cc73446
commit 3188ac16d1

View File

@@ -59,7 +59,7 @@ class UnsplashExtractor(Extractor):
class UnsplashImageExtractor(UnsplashExtractor):
"""Extractor for a single unsplash photo"""
subcategory = "image"
pattern = BASE_PATTERN + r"/photos/(\w+)"
pattern = BASE_PATTERN + r"/photos/([^/?#]+)"
test = ("https://unsplash.com/photos/lsoogGC_5dg", {
"url": "00accb0a64d5a0df0db911f8b425892718dce524",
"keyword": {
@@ -160,6 +160,23 @@ class UnsplashFavoriteExtractor(UnsplashExtractor):
return self._pagination(url, params)
class UnsplashCollectionExtractor(UnsplashExtractor):
"""Extractor for an unsplash collection"""
subcategory = "collection"
pattern = BASE_PATTERN + r"/collections/(\d+)"
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$",
"range": "1-30",
"count": 30,
})
def photos(self):
url = "{}/napi/collections/{}/photos".format(self.root, self.item)
params = {"order_by": "latest"}
return self._pagination(url, params)
class UnsplashSearchExtractor(UnsplashExtractor):
"""Extractor for unsplash search results"""
subcategory = "search"