fix: simulate pagination for clients that rely on it

some clients (like clipious) use pagination on playlists and rely on
videos field to tell if the playlist has no more videos.
here all videos are returned for non-paginated queries, with empty video
field returned for every paginated query, which page is not equal to "1"
This commit is contained in:
2025-10-02 02:27:51 +02:00
parent 5bb542826e
commit e7ae42f289

View File

@@ -890,8 +890,8 @@ def playlists(data, req, only_json: bool = False):
# todo: make clipious stop spamming requests for paginated response
page = req.args.get('page')
if page is not None and page != '1':
return send(404, {"error": "Paginated queries are not supported."})
# if page is not None and page != '1':
# return send(404, {"error": "Paginated queries are not supported."})
plid = data[3]
@@ -907,7 +907,9 @@ def playlists(data, req, only_json: bool = False):
# check if request has been cached within the last hour
if ythdd_globals.config['general']['cache'] and plid in ythdd_globals.general_cache['playlists']:
if ythdd_globals.general_cache['playlists'][plid]['cacheTime'] + 1 * 60 * 60 > time():
response = ythdd_globals.general_cache['playlists'][plid]
response = ythdd_globals.general_cache['playlists'][plid].copy()
if page is not None and page != '1':
response['videos'] = []
if only_json:
return response
else:
@@ -979,9 +981,12 @@ def playlists(data, req, only_json: bool = False):
# todo: cache videos and metadata separately, so that paginated queries can be supported as well
if ythdd_globals.config['general']['cache']:
ythdd_globals.general_cache['playlists'][plid] = response
ythdd_globals.general_cache['playlists'][plid] = response.copy()
ythdd_globals.general_cache['playlists'][plid]['cacheTime'] = time()
if page is not None or page == '1':
response['videos'] = []
if only_json:
return response