[Instagram] Add support for user's saved collection (#2769)
* [Instagram] Add support for user's saved collection * [Instagram] Run formatter * [Instagram] Simplify collection_id retrieval and add metadata * [Instagram] Fix bug when params is not passed to _pagination_api
This commit is contained in:
@@ -376,7 +376,7 @@ Consider all sites to be NSFW unless otherwise known.
|
||||
<tr>
|
||||
<td>Instagram</td>
|
||||
<td>https://www.instagram.com/</td>
|
||||
<td>Channels, Highlights, Posts, Reels, Saved Posts, Stories, Tag Searches, Tagged Posts, User Profiles</td>
|
||||
<td>Channels, Collections, Highlights, Posts, Reels, Saved Posts, Stories, Tag Searches, Tagged Posts, User Profiles</td>
|
||||
<td>Supported</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
||||
@@ -398,7 +398,7 @@ class InstagramExtractor(Extractor):
|
||||
variables["after"] = self._cursor = info["end_cursor"]
|
||||
self.log.debug("Cursor: %s", self._cursor)
|
||||
|
||||
def _pagination_api(self, endpoint, params=None):
|
||||
def _pagination_api(self, endpoint, params={}):
|
||||
while True:
|
||||
data = self._request_api(endpoint, params=params)
|
||||
yield from data["items"]
|
||||
@@ -509,7 +509,7 @@ class InstagramChannelExtractor(InstagramExtractor):
|
||||
class InstagramSavedExtractor(InstagramExtractor):
|
||||
"""Extractor for ProfilePage saved media"""
|
||||
subcategory = "saved"
|
||||
pattern = USER_PATTERN + r"/saved"
|
||||
pattern = USER_PATTERN + r"/saved/?$"
|
||||
test = ("https://www.instagram.com/instagram/saved/",)
|
||||
|
||||
def posts(self):
|
||||
@@ -518,6 +518,30 @@ class InstagramSavedExtractor(InstagramExtractor):
|
||||
return self._pagination_graphql(query_hash, variables)
|
||||
|
||||
|
||||
class InstagramCollectionExtractor(InstagramExtractor):
|
||||
"""Extractor for ProfilePage saved collection media"""
|
||||
subcategory = "collection"
|
||||
pattern = USER_PATTERN + r"/saved/([^/?#]+)/([^/?#]+)"
|
||||
test = (
|
||||
"https://www.instagram.com/instagram/saved/collection_name/123456789/",
|
||||
)
|
||||
|
||||
def __init__(self, match):
|
||||
InstagramExtractor.__init__(self, match)
|
||||
self.user, self.collection_name, self.collection_id = match.groups()
|
||||
|
||||
def metadata(self):
|
||||
return {
|
||||
"collection_id" : self.collection_id,
|
||||
"collection_name": text.unescape(self.collection_name),
|
||||
}
|
||||
|
||||
def posts(self):
|
||||
endpoint = "/v1/feed/collection/{}/posts/".format(self.collection_id)
|
||||
for item in self._pagination_api(endpoint):
|
||||
yield item["media"]
|
||||
|
||||
|
||||
class InstagramTagExtractor(InstagramExtractor):
|
||||
"""Extractor for TagPage"""
|
||||
subcategory = "tag"
|
||||
|
||||
Reference in New Issue
Block a user