diff --git a/music_kraken/utils/string_processing.py b/music_kraken/utils/string_processing.py index 15ff683..d21b367 100644 --- a/music_kraken/utils/string_processing.py +++ b/music_kraken/utils/string_processing.py @@ -1,4 +1,4 @@ -from typing import Tuple, Union +from typing import Tuple, Union, Optional from pathlib import Path import string from functools import lru_cache @@ -53,7 +53,7 @@ def fit_to_file_system(string: Union[str, Path]) -> Union[str, Path]: return fit_string(string) -def clean_song_title(raw_song_title: str, artist_name: str) -> str: +def clean_song_title(raw_song_title: str, artist_name: Optional[str] = None) -> str: """ This function cleans common naming "conventions" for non clean song titles, like the title of youtube videos @@ -65,19 +65,22 @@ def clean_song_title(raw_song_title: str, artist_name: str) -> str: - `song (prod. some producer)` """ raw_song_title = raw_song_title.strip() - artist_name = artist_name.strip() # Clean official Video appendix for dirty_appendix in COMMON_TITLE_APPENDIX_LIST: if raw_song_title.lower().endswith(dirty_appendix): raw_song_title = raw_song_title[:-len(dirty_appendix)].strip() - # Remove artist from the start of the title - if raw_song_title.lower().startswith(artist_name.lower()): - raw_song_title = raw_song_title[len(artist_name):].strip() + # everything that requires the artist name + if artist_name is not None: + artist_name = artist_name.strip() - if raw_song_title.startswith("-"): - raw_song_title = raw_song_title[1:].strip() + # Remove artist from the start of the title + if raw_song_title.lower().startswith(artist_name.lower()): + raw_song_title = raw_song_title[len(artist_name):].strip() + + if raw_song_title.startswith("-"): + raw_song_title = raw_song_title[1:].strip() return raw_song_title.strip()