From ff262dadb71b035d5e54496c007a4388fb5c5887 Mon Sep 17 00:00:00 2001 From: girst Date: Sun, 4 Oct 2020 15:35:17 +0200 Subject: [PATCH] implement pagination of channel/ucid/playlists (VERY HACKY) i'm less ashamed of this code as i should be. --- app/browse/__init__.py | 16 +++++++++++++++- app/browse/templates/channel.html.j2 | 4 +++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/browse/__init__.py b/app/browse/__init__.py index debc741..b3eea72 100644 --- a/app/browse/__init__.py +++ b/app/browse/__init__.py @@ -49,7 +49,7 @@ def channel(channel_id, subpage="videos"): sort_by = request.args.get('sort') or "newest" query = None elif subpage == "playlists": - page = None # TODO: cursor + page = request.args.get('cursor') sort_by = request.args.get('sort', "modified") query = None elif subpage == "search": @@ -89,6 +89,20 @@ def channel(channel_id, subpage="videos"): """, (channel_id, token)) (is_subscribed,) = c.fetchone() + # XXX: ad-hoc protobuf ctoken extractor: This is one big hack that needs to + # get cleanded up. Since the ctoken only has fileds with rigid lengths, we + # can just extract the bytes at the correct position to get at the cursor + # token we need. + if subpage == "playlists": + page = result[1].get('response',{}).get('continuationContents',{}) \ + .get('sectionListContinuation',{}).get('continuations',[{}])[0] \ + .get('nextContinuationData',{}).get('continuation') + if page: + import base64 + page = base64.urlsafe_b64decode(page+u'===')[34:] + page = base64.urlsafe_b64decode(page+b'===')[21:] + page = page[:102].decode('ascii') + # end XXX return render_template('channel.html.j2', title=title, subpage=subpage, diff --git a/app/browse/templates/channel.html.j2 b/app/browse/templates/channel.html.j2 index fe724ca..6f0303b 100644 --- a/app/browse/templates/channel.html.j2 +++ b/app/browse/templates/channel.html.j2 @@ -45,7 +45,9 @@ {% if not rows|length %}no more results{% endif %}
-{% if page is not none %} +{% if subpage == "playlists" %} + {{ macros.pagination("more", {'cursor': page}, +1) if has_more}} +{% else %} {{ macros.pagination("previous", {'page':(-1,1)}, -1) if page > 1 }} {{ macros.pagination("next", {'page':(+1,1)}, +1) if has_more}} {% endif %} -- 2.39.3