mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 20:43:04 +00:00
Refactor file: taglib.py and utils/parsers.py
Add dataclass and pathlib imports in taglib.py Add clean_filename, ParseData, and extract_artist_title functions in taglib.py Modify get_tags function in taglib.py to use extract_artist_title function Modify LyricsProvider class in lyrics.py to add timeout parameter in session.get Remove parse_artist_from_filename and parse_title_from_filename functions in utils/parsers.py Add split_artists function in utils/parsers.py Remove parse_artist_from_filename and parse_title_from_filename functions in utils/parsers.py Add remove_prod function in utils/parsers.py Refactor code and improve code readability
This commit is contained in:
@@ -18,39 +18,6 @@ def split_artists(src: str):
|
||||
return [a for a in artists if a]
|
||||
|
||||
|
||||
def parse_artist_from_filename(title: str):
|
||||
"""
|
||||
Extracts artist names from a song title using regex.
|
||||
"""
|
||||
|
||||
regex = r"^(.+?)\s*[-–—]\s*(?:.+?)$"
|
||||
match = re.search(regex, title, re.IGNORECASE)
|
||||
|
||||
if not match:
|
||||
return []
|
||||
|
||||
artists = match.group(1)
|
||||
artists = split_artists(artists)
|
||||
return artists
|
||||
|
||||
|
||||
def parse_title_from_filename(title: str):
|
||||
"""
|
||||
Extracts track title from a song title using regex.
|
||||
"""
|
||||
|
||||
regex = r"^(?:.+?)\s*[-–—]\s*(.+?)$"
|
||||
match = re.search(regex, title, re.IGNORECASE)
|
||||
|
||||
if not match:
|
||||
return title
|
||||
|
||||
res = match.group(1)
|
||||
# remove text in brackets starting with "official" case-insensitive
|
||||
res = re.sub(r"\s*\([^)]*official[^)]*\)", "", res, flags=re.IGNORECASE)
|
||||
return res.strip()
|
||||
|
||||
|
||||
def remove_prod(title: str) -> str:
|
||||
"""
|
||||
Removes the producer string in a track title using regex.
|
||||
|
||||
Reference in New Issue
Block a user