From f9cf069689f6c037c4056465288096346a3eb17a Mon Sep 17 00:00:00 2001 From: girst Date: Sat, 29 Aug 2020 11:18:59 +0200 Subject: [PATCH] more lenient channel redirection, catch not existing channels --- app/dangerous/__init__.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/dangerous/__init__.py b/app/dangerous/__init__.py index e592752..ee9b77b 100644 --- a/app/dangerous/__init__.py +++ b/app/dangerous/__init__.py @@ -3,6 +3,7 @@ #, so i hope™ this works. if not, that's why it's in the 'dangerous' blueprint import requests from flask import Blueprint, render_template, request, flash, g, url_for, redirect +from werkzeug.exceptions import NotFound from ..common.common import * from ..common.innertube import * @@ -59,6 +60,10 @@ def channel(channel_id, subpage="videos"): else: # we don't support /home, /about, ..., so redirect to /videos. return redirect(url_for('.channel', channel_id=channel_id)) + # best effort; if it fails, it fails in the redirect. + 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)) # Note: as of 2020-08-15, using the v1 format sometimes returns an error. if that's the case, try v2. @@ -92,6 +97,8 @@ def channel_redirect(user, subpage=None): The browse_ajax 'API' needs the UCID. We can get that from the RSS feeds. """ xmlfeed = fetch_xml("user", user) + if not xmlfeed: + raise NotFound("channel appears to not exist") _, _, _, channel_id, _ = parse_xml(xmlfeed) return redirect( url_for('.channel', channel_id=channel_id, subpage=subpage), 308 -- 2.39.3