From 214a2488213a89d7cc69b9cfc5afa7b2fc4370db Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 23 Sep 2021 10:50:44 +0700 Subject: [PATCH] better error handeling in add to download form --- tubearchivist/home/src/helper.py | 3 +++ tubearchivist/home/views.py | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/tubearchivist/home/src/helper.py b/tubearchivist/home/src/helper.py index 80ff11f..de41757 100644 --- a/tubearchivist/home/src/helper.py +++ b/tubearchivist/home/src/helper.py @@ -46,6 +46,9 @@ def process_url_list(url_str): url_list = re.split("\n+", url_str[0]) youtube_ids = [] for url in url_list: + if "/c/" in url or "/user/" in url: + raise ValueError("user name is not unique, use channel ID") + url_clean = url.strip().strip("/").split("/")[-1] for i in to_replace: url_clean = url_clean.replace(i, "") diff --git a/tubearchivist/home/views.py b/tubearchivist/home/views.py index dfd8aa3..a64e0aa 100644 --- a/tubearchivist/home/views.py +++ b/tubearchivist/home/views.py @@ -195,16 +195,16 @@ class DownloadView(View): download_post = dict(request.POST) if "vid-url" in download_post.keys(): url_str = download_post["vid-url"] - print("adding to queue") - youtube_ids = process_url_list(url_str) - if not youtube_ids: + try: + youtube_ids = process_url_list(url_str) + except ValueError: # failed to process - print(url_str) + print(f"failed to parse: {url_str}") mess_dict = { "status": "downloading", "level": "error", "title": "Failed to extract links.", - "message": "", + "message": "Not a video, channel or playlist ID or URL", } set_message("progress:download", mess_dict) return redirect("downloads")