From ba34718e1ef2fb6c0cc955625248411336e8fa40 Mon Sep 17 00:00:00 2001 From: girst Date: Sat, 19 Sep 2020 20:05:22 +0200 Subject: [PATCH] redirect youtube.com/, fix /c/ trailing slash --- app/browse/__init__.py | 4 ++-- app/youtube/__init__.py | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/app/browse/__init__.py b/app/browse/__init__.py index 77fe880..ac3308d 100644 --- a/app/browse/__init__.py +++ b/app/browse/__init__.py @@ -85,9 +85,9 @@ def channel(channel_id, subpage="videos"): page=page, has_more=more) -@frontend.route('/user/') +@frontend.route('/user//') @frontend.route('/user//') -@frontend.route('/c/') +@frontend.route('/c//') @frontend.route('/c//') def channel_redirect(user, subpage=None): """ diff --git a/app/youtube/__init__.py b/app/youtube/__init__.py index ac47fea..37cdc19 100644 --- a/app/youtube/__init__.py +++ b/app/youtube/__init__.py @@ -149,14 +149,16 @@ def watch(): def embed(video_id): return redirect(url_for('youtube.watch', v=video_id)) -@frontend.route('/') -def raw_video_id_url(video_id): - # a "just-a-variable-endpoint" has lowest priority, but we check if it - # looks like a video id anyways, so we can have more than one such endpoint - # in the future. - if not re.match(r"^[-_0-9A-Za-z]{11}$", video_id): # not actually a video id - return fallback_route() - return redirect(url_for('youtube.watch', v=video_id)) +@frontend.route('/') +@frontend.route('//') +def plain_user_or_video(something): + # yt.com redirects those to channels, but we also want to catch invidious + # short-urls. a "just-a-variable-endpoint" has lowest priority, so this + # shouldn't interfere with anything. + if re.match(r"^[-_0-9A-Za-z]{11}$", something): # looks like a video id + return redirect(url_for('.watch', v=something)) + else: # maybe a channel/user name? + return redirect(url_for('.channel', channel_id=something)) @frontend.route('/channel//') @frontend.route('/user//') -- 2.39.3