mirror of
https://github.com/rakuri255/UltraSinger.git
synced 2026-12-06 09:57:39 +09:00
fix whitespaces in title and artist
This commit is contained in:
1 parent
baeb3d2776
commit
9d00ed2f93
6 files changed
+117
-16
No files matched your search
@@ -9,6 +9,7 @@ from PIL import Image
|
||||
from modules.console_colors import ULTRASINGER_HEAD
|
||||
from modules.Image.image_helper import crop_image_to_square
|
||||
|
||||
|
||||
def get_youtube_title(url: str) -> tuple[str, str]:
|
||||
"""Get the title of the YouTube video"""
|
||||
|
||||
@@ -19,10 +20,10 @@ def get_youtube_title(url: str) -> tuple[str, str]:
|
||||
)
|
||||
|
||||
if "artist" in result:
|
||||
return result["artist"], result["track"]
|
||||
return result["artist"].strip(), result["track"].strip()
|
||||
if "-" in result["title"]:
|
||||
return result["title"].split("-")[0], result["title"].split("-")[1]
|
||||
return result["channel"], result["title"]
|
||||
return result["title"].split("-")[0].strip(), result["title"].split("-")[1].strip()
|
||||
return result["channel"].strip(), result["title"].strip()
|
||||
|
||||
|
||||
def download_youtube_audio(url: str, clear_filename: str, output_path: str):
|
||||
|
||||
@@ -11,26 +11,26 @@ def get_music_infos(search_string: str) -> tuple[str, str, str, str]:
|
||||
|
||||
# search for artist and titel to get release on the first place
|
||||
artists = musicbrainzngs.search_artists(search_string)
|
||||
artist = artists['artist-list'][0]['name']
|
||||
artist = artists['artist-list'][0]['name'].strip()
|
||||
release_groups = musicbrainzngs.search_release_groups(search_string, artist=artist)
|
||||
release = release_groups['release-group-list'][0]
|
||||
|
||||
if 'artist-credit-phrase' in release:
|
||||
artist = release['artist-credit-phrase']
|
||||
artist = release['artist-credit-phrase'].strip()
|
||||
|
||||
title = None
|
||||
if 'title' in release:
|
||||
clean_search_string = search_string.translate(str.maketrans('', '', string.punctuation)).lower()
|
||||
clean_release_title = release['title'].translate(str.maketrans('', '', string.punctuation)).lower()
|
||||
clean_artist = artist.translate(str.maketrans('', '', string.punctuation)).lower()
|
||||
clean_search_string = search_string.translate(str.maketrans('', '', string.punctuation)).lower().strip()
|
||||
clean_release_title = release['title'].translate(str.maketrans('', '', string.punctuation)).lower().strip()
|
||||
clean_artist = artist.translate(str.maketrans('', '', string.punctuation)).lower().strip()
|
||||
|
||||
# prepare search string when title and artist are the same
|
||||
if clean_release_title == clean_artist:
|
||||
# remmove the first acurance of the artist
|
||||
# remove the first appearance of the artist
|
||||
clean_search_string = clean_search_string.replace(clean_artist, "", 1)
|
||||
|
||||
if clean_release_title in clean_search_string:
|
||||
title = release['title']
|
||||
title = release['title'].strip()
|
||||
else:
|
||||
print(
|
||||
f"{ULTRASINGER_HEAD} cant find title {red_highlighted(clean_release_title)} in {red_highlighted(clean_search_string)}")
|
||||
@@ -43,14 +43,14 @@ def get_music_infos(search_string: str) -> tuple[str, str, str, str]:
|
||||
|
||||
year = None
|
||||
if 'first-release-date' in release:
|
||||
year = release['first-release-date']
|
||||
year = release['first-release-date'].strip()
|
||||
print(f"{ULTRASINGER_HEAD} Found release year: {blue_highlighted(year)}")
|
||||
|
||||
genres = None
|
||||
if 'tag-list' in release:
|
||||
genres = ""
|
||||
for tag in release['tag-list']:
|
||||
genres += f"{tag['name']},"
|
||||
genres += f"{tag['name'].strip()},"
|
||||
print(f"{ULTRASINGER_HEAD} Found genres: {blue_highlighted(genres)}")
|
||||
|
||||
return title, artist, year, genres
|
||||
Reference in new issue
Block a user