From 2db4be26dafd225c097dc53964c27b80a7101112 Mon Sep 17 00:00:00 2001 From: AbdullahM0hamed <25087116+AbdullahM0hamed@users.noreply.github.com> Date: Mon, 23 Nov 2020 19:27:56 +0000 Subject: [PATCH 1/4] Throw UsageError if episode flag is used incorrectly --- anime_downloader/commands/dl.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/anime_downloader/commands/dl.py b/anime_downloader/commands/dl.py index e705066..cf3794e 100644 --- a/anime_downloader/commands/dl.py +++ b/anime_downloader/commands/dl.py @@ -3,10 +3,12 @@ import os import click import requests_cache +import re from anime_downloader import session, util from anime_downloader.__version__ import __version__ from anime_downloader.sites import get_anime_class, ALL_ANIME_SITES, exceptions +from click import UsageError logger = logging.getLogger(__name__) @@ -85,6 +87,10 @@ def command(ctx, anime_url, episode_range, url, player, skip_download, quality, external_downloader, chunk_size, disable_ssl, fallback_qualities, choice, skip_fillers, speed_limit): """ Download the anime using the url or search for it. """ + + if not re.compile("^[0-9:]+$").search(episode_range): + raise UsageError("Invalid value for '--episode' / '-e': {} is not a valid range".format(episode_range)) + query = anime_url[:] util.print_info(__version__) From 55cbcf25d43d91f314878e59f5794700d4f85e17 Mon Sep 17 00:00:00 2001 From: AbdullahM0hamed <25087116+AbdullahM0hamed@users.noreply.github.com> Date: Mon, 23 Nov 2020 23:06:03 +0000 Subject: [PATCH 2/4] Check if episode_range exists before checking that it's correct --- anime_downloader/commands/dl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/anime_downloader/commands/dl.py b/anime_downloader/commands/dl.py index cf3794e..ea0c16a 100644 --- a/anime_downloader/commands/dl.py +++ b/anime_downloader/commands/dl.py @@ -88,7 +88,7 @@ def command(ctx, anime_url, episode_range, url, player, skip_download, quality, """ Download the anime using the url or search for it. """ - if not re.compile("^[0-9:]+$").search(episode_range): + if episode_range and not re.compile("^[0-9:]+$").search(episode_range): raise UsageError("Invalid value for '--episode' / '-e': {} is not a valid range".format(episode_range)) query = anime_url[:] From 97adb94b7d1ef48fa73ad979d90c9a6db3eb878f Mon Sep 17 00:00:00 2001 From: AbdullahM0hamed <25087116+AbdullahM0hamed@users.noreply.github.com> Date: Sun, 14 Feb 2021 23:12:56 +0000 Subject: [PATCH 3/4] Improve regex and add more conditions to statement --- anime_downloader/commands/dl.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/anime_downloader/commands/dl.py b/anime_downloader/commands/dl.py index ea0c16a..529dc4f 100644 --- a/anime_downloader/commands/dl.py +++ b/anime_downloader/commands/dl.py @@ -88,8 +88,12 @@ def command(ctx, anime_url, episode_range, url, player, skip_download, quality, """ Download the anime using the url or search for it. """ - if episode_range and not re.compile("^[0-9:]+$").search(episode_range): - raise UsageError("Invalid value for '--episode' / '-e': {} is not a valid range".format(episode_range)) + if episode_range: + regexed_range = re.compile("^:?(\d+)?:?(\d+)?$").search(episode_range) + # Prevent such cases as: :5: and :1:1 + if not regexed_range or (len(regexed_range.groups()) >= episode_range.count(":") and episode_range.count(":") != 1): + raise UsageError( + "Invalid value for '--episode' / '-e': {} is not a valid range".format(episode_range)) query = anime_url[:] From 8ea70f60de82a64a1066a1f8cdcab206a98b6744 Mon Sep 17 00:00:00 2001 From: Arjix <53124886+ArjixWasTaken@users.noreply.github.com> Date: Sat, 16 Oct 2021 13:54:48 +0300 Subject: [PATCH 4/4] removed unnecessary import --- anime_downloader/commands/dl.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/anime_downloader/commands/dl.py b/anime_downloader/commands/dl.py index 4717ab7..ca831f2 100644 --- a/anime_downloader/commands/dl.py +++ b/anime_downloader/commands/dl.py @@ -8,7 +8,6 @@ import re from anime_downloader import session, util from anime_downloader.__version__ import __version__ from anime_downloader.sites import get_anime_class, ALL_ANIME_SITES, exceptions -from click import UsageError logger = logging.getLogger(__name__) @@ -98,7 +97,7 @@ def command(ctx, anime_url, episode_range, url, player, skip_download, quality, regexed_range = re.compile("^:?(\d+)?:?(\d+)?$").search(episode_range) # Prevent such cases as: :5: and :1:1 if not regexed_range or (len(regexed_range.groups()) >= episode_range.count(":") and episode_range.count(":") != 1): - raise UsageError( + raise click.UsageError( "Invalid value for '--episode' / '-e': {} is not a valid range".format(episode_range)) if sub and dub: