mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-25 12:12:34 +01:00
[imgur] add 'favorite-folder' extractor (#4016)
This commit is contained in:
parent
4c1f3b2160
commit
8520de57f0
@ -388,7 +388,7 @@ Consider all sites to be NSFW unless otherwise known.
|
||||
<tr>
|
||||
<td>imgur</td>
|
||||
<td>https://imgur.com/</td>
|
||||
<td>Albums, Favorites, Galleries, individual Images, Search Results, Subreddits, Tag Searches, User Profiles</td>
|
||||
<td>Albums, Favorites, Favorites Folders, Galleries, individual Images, Search Results, Subreddits, Tag Searches, User Profiles</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
@ -285,7 +285,7 @@ class ImgurUserExtractor(ImgurExtractor):
|
||||
class ImgurFavoriteExtractor(ImgurExtractor):
|
||||
"""Extractor for a user's favorites"""
|
||||
subcategory = "favorite"
|
||||
pattern = BASE_PATTERN + r"/user/([^/?#]+)/favorites"
|
||||
pattern = BASE_PATTERN + r"/user/([^/?#]+)/favorites/?$"
|
||||
test = ("https://imgur.com/user/Miguenzo/favorites", {
|
||||
"range": "1-100",
|
||||
"count": 100,
|
||||
@ -296,6 +296,28 @@ class ImgurFavoriteExtractor(ImgurExtractor):
|
||||
return self._items_queue(self.api.account_favorites(self.key))
|
||||
|
||||
|
||||
class ImgurFavoriteFolderExtractor(ImgurExtractor):
|
||||
"""Extractor for a user's favorites folder"""
|
||||
subcategory = "favorite-folder"
|
||||
pattern = BASE_PATTERN + r"/user/([^/?#]+)/favorites/folder/(\d+)"
|
||||
test = (
|
||||
("https://imgur.com/user/mikf1/favorites/folder/11896757/public", {
|
||||
"count": 3,
|
||||
}),
|
||||
("https://imgur.com/user/mikf1/favorites/folder/11896741/private", {
|
||||
"count": 5,
|
||||
}),
|
||||
)
|
||||
|
||||
def __init__(self, match):
|
||||
ImgurExtractor.__init__(self, match)
|
||||
self.folder_id = match.group(2)
|
||||
|
||||
def items(self):
|
||||
return self._items_queue(self.api.account_favorites_folder(
|
||||
self.key, self.folder_id))
|
||||
|
||||
|
||||
class ImgurSubredditExtractor(ImgurExtractor):
|
||||
"""Extractor for a subreddits's imgur links"""
|
||||
subcategory = "subreddit"
|
||||
@ -346,15 +368,18 @@ class ImgurAPI():
|
||||
"""
|
||||
def __init__(self, extractor):
|
||||
self.extractor = extractor
|
||||
self.headers = {
|
||||
"Authorization": "Client-ID " + (
|
||||
extractor.config("client-id") or "546c25a59c58ad7"),
|
||||
}
|
||||
self.client_id = extractor.config("client-id") or "546c25a59c58ad7"
|
||||
self.headers = {"Authorization": "Client-ID " + self.client_id}
|
||||
|
||||
def account_favorites(self, account):
|
||||
endpoint = "/3/account/{}/gallery_favorites".format(account)
|
||||
return self._pagination(endpoint)
|
||||
|
||||
def account_favorites_folder(self, account, folder_id):
|
||||
endpoint = "/3/account/{}/folders/{}/favorites".format(
|
||||
account, folder_id)
|
||||
return self._pagination_v2(endpoint)
|
||||
|
||||
def gallery_search(self, query):
|
||||
endpoint = "/3/gallery/search"
|
||||
params = {"q": query}
|
||||
@ -386,12 +411,12 @@ class ImgurAPI():
|
||||
endpoint = "/post/v1/posts/" + gallery_hash
|
||||
return self._call(endpoint)
|
||||
|
||||
def _call(self, endpoint, params=None):
|
||||
def _call(self, endpoint, params=None, headers=None):
|
||||
while True:
|
||||
try:
|
||||
return self.extractor.request(
|
||||
"https://api.imgur.com" + endpoint,
|
||||
params=params, headers=self.headers,
|
||||
params=params, headers=(headers or self.headers),
|
||||
).json()
|
||||
except exception.HttpError as exc:
|
||||
if exc.status not in (403, 429) or \
|
||||
@ -410,3 +435,23 @@ class ImgurAPI():
|
||||
return
|
||||
yield from data
|
||||
num += 1
|
||||
|
||||
def _pagination_v2(self, endpoint, params=None, key=None):
|
||||
if params is None:
|
||||
params = {}
|
||||
params["client_id"] = self.client_id
|
||||
params["page"] = 0
|
||||
params["sort"] = "newest"
|
||||
|
||||
headers = {
|
||||
"Referer": "https://imgur.com/",
|
||||
"Origin": "https://imgur.com",
|
||||
}
|
||||
|
||||
while True:
|
||||
data = self._call(endpoint, params, headers)["data"]
|
||||
if not data:
|
||||
return
|
||||
yield from data
|
||||
|
||||
params["page"] += 1
|
||||
|
@ -183,6 +183,9 @@ SUBCATEGORY_MAP = {
|
||||
"hentaifoundry": {
|
||||
"story": "",
|
||||
},
|
||||
"imgur": {
|
||||
"favorite-folder": "Favorites Folders",
|
||||
},
|
||||
"instagram": {
|
||||
"posts": "",
|
||||
"saved": "Saved Posts",
|
||||
|
Loading…
Reference in New Issue
Block a user