Skip to content

Commit

Permalink
internal: fix regex performance
Browse files Browse the repository at this point in the history
  • Loading branch information
snejus committed Mar 16, 2024
1 parent 39a3edc commit e883d4a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions beetsplug/bandcamp/album.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ class AlbumName:
SERIES = re.compile(rf"{_series}[ ]?[A-Z\d.-]+\b")
SERIES_FMT = re.compile(rf"^(.+){_series} *0*")
INCL = re.compile(r"[^][\w]*inc[^()]+mix(es)?[^()-]*\W?", re.I)
CLEAN_EPLP = re.compile(r"\S*(?:Double )?(\b[EL]P\b)\S*", re.I)
CLEAN_EPLP = re.compile(r"\S*(?:Double )*(\b[EL]P\b)\S*", re.I)
EPLP_ALBUM = re.compile(
r"(((&|#?\b(?!Double|VA|Various)(\w|[^\w| -])+) )+[EL]P[^[(-]+)"
r"(((&|#?\b(?!Double|VA|Various)(\w|\W[| -])+) )+[EL]P[^[(-]+)"
)
IN_QUOTES = re.compile(r"((['\"])([^'\"]+)\2( VA\d+)*)( |$)")
WITHOUT_QUOTES = re.compile(r"^['\"](.+)['\"]$")
CLEAN_VA_EXCLUDE = re.compile(r"\w various artists \w", re.I)
CLEAN_VA = re.compile(
r"""
(?<=^)v/?a\b(?![ ]\w)\W*
| \W*Various[ ]Artists?\b(?![ ][A-z])([ ]\d+)?[^(\w]*
(?<=^)v/?a\b(?!\ \w)\W*
| \W*Various\ Artists?\b(?!\ [A-z])(\ \d+)?[^(\w]*
| \bva(?=$)
""",
re.IGNORECASE + re.MULTILINE + re.VERBOSE,
Expand Down
2 changes: 1 addition & 1 deletion beetsplug/bandcamp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def split_artist_title(m: re.Match) -> str:
(re.compile(rf"(\({_remix_pat})$", re.I), r"\1)"), # bye - (Some Mix -> bye - (Some Mix) # noqa
(re.compile(rf"- *({_remix_pat})$", re.I), r"(\1)"), # bye - Some Mix -> bye (Some Mix) # noqa
(re.compile(r'(^|- )[“"]([^”"]+)[”"]( \(|$)'), r"\1\2\3"), # "bye" -> bye; hi - "bye" -> hi - bye # noqa
(re.compile(r"\((?i:(the )?(remixes))\)"), r"\2"), # Album (Remixes) -> Album Remixes # noqa
(re.compile(r"\((the )?(remixes)\)", re.I), r"\2"), # Album (Remixes) -> Album Remixes # noqa
(re.compile(r"examine-.+CD\d+_([^_-]+)[_-](.*)"), split_artist_title), # See https://examine-archive.bandcamp.com/album/va-examine-archive-international-sampler-xmn01 # noqa
]
# fmt: on
Expand Down

0 comments on commit e883d4a

Please sign in to comment.