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] 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[:]