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:
mungai-njoroge
2023-11-22 15:44:31 +03:00
parent 52173d4c7e
commit 38650a1a7e
3 changed files with 55 additions and 40 deletions
-33
View File
@@ -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.