Skip to content

Commit

Permalink
Extract subpatterns to make regex more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
ihabunek committed Sep 5, 2024
1 parent b14db38 commit 919734e
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions twitchdl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,20 @@ def titlify(value: str) -> str:
return value.strip()


VIDEO_ID_PATTERN = r"(?P<id>\d+)"

VIDEO_PATTERNS = [
r"^(?P<id>\d+)$",
r"^https://(www\.|m\.)?twitch\.tv/videos/(?P<id>\d+)(\?.+)?$",
r"^https://(www\.|m\.)?twitch\.tv/\w+/video/(?P<id>\d+)(\?.+)?$",
rf"^{VIDEO_ID_PATTERN}$",
rf"^https://(www\.|m\.)?twitch\.tv/videos/{VIDEO_ID_PATTERN}(\?.+)?$",
rf"^https://(www\.|m\.)?twitch\.tv/\w+/video/{VIDEO_ID_PATTERN}(\?.+)?$",
]

CLIP_SLUG_PATTERN = r"(?P<slug>[A-Za-z0-9-_]+)"

CLIP_PATTERNS = [
r"^(?P<slug>[A-Za-z0-9-_]+)$",
r"^https://(www\.|m\.)?twitch\.tv/\w+/clip/(?P<slug>[A-Za-z0-9-_]+)(\?.+)?$",
r"^https://clips\.twitch\.tv/(?P<slug>[A-Za-z0-9-_]+)(\?.+)?$",
fr"^{CLIP_SLUG_PATTERN}$",
fr"^https://(www\.|m\.)?twitch\.tv/\w+/clip/{CLIP_SLUG_PATTERN}(\?.+)?$",
fr"^https://clips\.twitch\.tv/{CLIP_SLUG_PATTERN}(\?.+)?$",
]


Expand Down

0 comments on commit 919734e

Please sign in to comment.