merge #6191: [cohost] support downloading likes
This commit is contained in:
@@ -191,3 +191,33 @@ class CohostTagExtractor(CohostExtractor):
|
||||
params["refTimestamp"] = pagination["refTimestamp"]
|
||||
params["skipPosts"] = \
|
||||
pagination["currentSkip"] + pagination["idealPageStride"]
|
||||
|
||||
|
||||
class CohostLikesExtractor(CohostExtractor):
|
||||
"""Extractor for liked posts"""
|
||||
subcategory = "likes"
|
||||
pattern = BASE_PATTERN + r"/rc/liked-posts"
|
||||
example = "https://cohost.org/rc/liked-posts"
|
||||
|
||||
def posts(self):
|
||||
url = "{}/rc/liked-posts".format(self.root)
|
||||
params = {}
|
||||
|
||||
while True:
|
||||
page = self.request(url, params=params).text
|
||||
data = util.json_loads(text.extr(
|
||||
page, 'id="__COHOST_LOADER_STATE__">', '</script>'))
|
||||
|
||||
try:
|
||||
feed = data["liked-posts-feed"]
|
||||
except KeyError:
|
||||
feed = data.popitem()[1]
|
||||
|
||||
yield from feed["posts"]
|
||||
|
||||
pagination = feed["paginationMode"]
|
||||
if not pagination.get("morePagesForward"):
|
||||
return
|
||||
params["refTimestamp"] = pagination["refTimestamp"]
|
||||
params["skipPosts"] = \
|
||||
pagination["currentSkip"] + pagination["idealPageStride"]
|
||||
|
||||
Reference in New Issue
Block a user