Skip to content

Commit 0b49712

Browse files
authored
[tiktok] use time cursor for story requests (#8991)
1 parent 614e1a5 commit 0b49712

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

gallery_dl/extractor/tiktok.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -914,19 +914,22 @@ def next_page(self, data, query_parameters):
914914

915915

916916
class TiktokTimeCursor(TiktokPaginationCursor):
917-
def __init__(self, *, reverse=True):
917+
def __init__(self, *, reverse=True, has_more_attribute="hasMore",
918+
cursor_attribute="cursor"):
918919
super().__init__()
919920
self.cursor = 0
920921
# If we expect the cursor to go up or down as we go to the next page.
921922
# True for down, False for up.
922923
self.reverse = reverse
924+
self.has_more_key = has_more_attribute
925+
self.cursor_key = cursor_attribute
923926

924927
def current_page(self):
925928
return self.cursor
926929

927930
def next_page(self, data, query_parameters):
928931
skip_fallback_logic = self.cursor == 0
929-
new_cursor = int(data.get("cursor", 0))
932+
new_cursor = int(data.get(self.cursor_key, 0))
930933
no_cursor = not new_cursor
931934
if not skip_fallback_logic:
932935
# If the new cursor doesn't go in the direction we expect, use the
@@ -938,7 +941,7 @@ def next_page(self, data, query_parameters):
938941
elif no_cursor:
939942
raise exception.ExtractionError("Could not extract next cursor")
940943
self.cursor = new_cursor
941-
return not data.get("hasMore", False)
944+
return not data.get(self.has_more_key, False)
942945

943946
def fallback_cursor(self, data):
944947
try:
@@ -968,6 +971,12 @@ def fallback_cursor(self, data):
968971
return -50_000
969972

970973

974+
class TiktokStoryTimeCursor(TiktokTimeCursor):
975+
def __init__(self):
976+
super().__init__(reverse=False, has_more_attribute="HasMoreAfter",
977+
cursor_attribute="MaxCursor")
978+
979+
971980
class TiktokLegacyTimeCursor(TiktokPaginationCursor):
972981
def __init__(self):
973982
super().__init__()
@@ -1472,7 +1481,7 @@ def validate_query_parameters(self, query_parameters):
14721481
assert query_parameters["loadBackward"] in ["true", "false"]
14731482

14741483
def cursor_type(self, query_parameters):
1475-
return TiktokItemCursor
1484+
return TiktokStoryTimeCursor
14761485

14771486

14781487
class TiktokStoryBatchItemListRequest(TiktokItemListRequest):

0 commit comments

Comments
 (0)