From 20d6c32b7d5c288e3d5068e838c98c739341d02e Mon Sep 17 00:00:00 2001 From: girst Date: Sat, 12 Dec 2020 20:32:50 +0100 Subject: [PATCH] fix channel playlists tab now uses v3 formatted protobuf. --- app/browse/__init__.py | 22 ++++------------------ app/browse/protobuf.py | 4 ++-- app/browse/templates/channel.html.j2 | 4 ---- 3 files changed, 6 insertions(+), 24 deletions(-) diff --git a/app/browse/__init__.py b/app/browse/__init__.py index c90d83c..36e4065 100644 --- a/app/browse/__init__.py +++ b/app/browse/__init__.py @@ -48,16 +48,16 @@ def search(): def channel(channel_id, subpage="videos"): token = getattr(current_user, 'token', 'guest') if subpage == "videos": - page = int(request.args.get('page', 1)) + page = int(request.args.get('page') or 1) sort_by = request.args.get('sort') or "newest" query = None elif subpage == "playlists": - page = request.args.get('cursor') + page = int(request.args.get('page') or 1) sort_by = request.args.get('sort', "modified") query = None elif subpage == "search": query = request.args.get('q') - page = int(request.args.get('page', 1)) + page = int(request.args.get('page') or 1) sort_by = None else: # we don't support /home, /about, ..., so redirect to /videos. return redirect(url_for('.channel', channel_id=channel_id)) @@ -66,7 +66,7 @@ def channel(channel_id, subpage="videos"): if not re.match(r"(UC[A-Za-z0-9_-]{22})", channel_id): return redirect(url_for('.channel_redirect', user=channel_id)) - result = fetch_ajax(make_channel_params(channel_id, subpage, page, sort_by, query, v3=(subpage == "videos"))) + result = fetch_ajax(make_channel_params(channel_id, subpage, page, sort_by, query, v3=(subpage != "search"))) title, descr, thumb, rows, more = prepare_channel(result, channel_id) @@ -92,20 +92,6 @@ 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/protobuf.py b/app/browse/protobuf.py index 277328f..4d9e11d 100644 --- a/app/browse/protobuf.py +++ b/app/browse/protobuf.py @@ -101,13 +101,13 @@ def make_channel_params(subject, typ="videos", page=1, sort=None, query=None, v3 typeint = dict(videos=0, playlists=1, search=None) # not supporting autogen'd sortorder = dict(popular=1, oldest=2, newest=3) if typ == "playlists": - sortorder = dict(oldest=2, newest=3, modified=4) + sortorder = dict(newest=3, modified=4) elif typ == "search": sortorder = dict() - _page = str(page) if not v3 and page else None if page and typ=="search": _page = b64e(SearchOffset(offset=(page-1)*30).dumps(), padding=False) + else: _page = None return b64e(Continuation( params=Params( diff --git a/app/browse/templates/channel.html.j2 b/app/browse/templates/channel.html.j2 index 1ccc499..d4e0c21 100644 --- a/app/browse/templates/channel.html.j2 +++ b/app/browse/templates/channel.html.j2 @@ -45,11 +45,7 @@ {% if not rows|length %}no more results{% endif %}
-{% 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 %}
{% endblock %} -- 2.39.3