mirror of
https://github.com/rakuri255/UltraSinger.git
synced 2026-11-20 13:07:52 +09:00
Merge pull request #68 from rakuri255/additional_song_info_musicbrainz
Additional song info musicbrainz
This commit is contained in:
7 files changed
+127
-10
No files matched your search
+2
-1
@@ -21,4 +21,5 @@ Pillow~=9.5.0
|
||||
isort==5.12
|
||||
black==23.3
|
||||
pylint==2.17
|
||||
pytest~=7.3.1
|
||||
pytest~=7.3.1
|
||||
musicbrainzngs~=0.7.1
|
||||
+61
-6
@@ -53,6 +53,7 @@ from src.modules.Ultrastar.ultrastar_txt import UltrastarTxtValue
|
||||
from Settings import Settings
|
||||
from src.modules.Speech_Recognition.TranscribedData import TranscribedData
|
||||
from src.modules.plot import plot
|
||||
from modules.musicbrainz_client import get_music_infos
|
||||
|
||||
settings = Settings()
|
||||
|
||||
@@ -258,6 +259,7 @@ def run() -> None:
|
||||
is_audio = ".txt" not in settings.input_file_path
|
||||
ultrastar_class = None
|
||||
real_bpm = None
|
||||
(title, artist, year, genre) = (None, None, None, None)
|
||||
|
||||
if not is_audio: # Parse Ultrastar txt
|
||||
print(
|
||||
@@ -278,6 +280,7 @@ def run() -> None:
|
||||
basename_without_ext,
|
||||
song_output,
|
||||
ultrastar_audio_input_path,
|
||||
(title, artist, year, genre)
|
||||
) = download_from_youtube()
|
||||
else: # Audio File
|
||||
print(
|
||||
@@ -287,6 +290,7 @@ def run() -> None:
|
||||
basename_without_ext,
|
||||
song_output,
|
||||
ultrastar_audio_input_path,
|
||||
(title, artist, year, genre)
|
||||
) = infos_from_audio_input_file()
|
||||
|
||||
cache_path = os.path.join(song_output, "cache")
|
||||
@@ -353,6 +357,10 @@ def run() -> None:
|
||||
ultrastar_audio_input_path,
|
||||
ultrastar_note_numbers,
|
||||
language,
|
||||
title,
|
||||
artist,
|
||||
year,
|
||||
genre
|
||||
)
|
||||
else:
|
||||
ultrastar_file_output = create_ultrastar_txt_from_ultrastar_data(
|
||||
@@ -503,6 +511,10 @@ def create_ultrastar_txt_from_automation(
|
||||
ultrastar_audio_input_path: str,
|
||||
ultrastar_note_numbers: list[int],
|
||||
language: str,
|
||||
title: str,
|
||||
artist: str,
|
||||
year: str,
|
||||
genre: []
|
||||
):
|
||||
"""Create Ultrastar txt from automation"""
|
||||
ultrastar_header = UltrastarTxtValue()
|
||||
@@ -518,6 +530,20 @@ def create_ultrastar_txt_from_automation(
|
||||
else None
|
||||
)
|
||||
|
||||
# Additional data
|
||||
if title is not None:
|
||||
ultrastar_header.title = title
|
||||
if artist is not None:
|
||||
ultrastar_header.artist = artist
|
||||
if year is not None:
|
||||
ultrastar_header.year = year
|
||||
if genre:
|
||||
genre_str = ""
|
||||
for g in genre:
|
||||
genre_str += g + ", "
|
||||
genre_str = genre_str[:-1]
|
||||
ultrastar_header.genre = genre_str
|
||||
|
||||
real_bpm = get_bpm_from_file(ultrastar_audio_input_path)
|
||||
ultrastar_file_output = os.path.join(
|
||||
song_output, basename_without_ext + ".txt"
|
||||
@@ -548,16 +574,37 @@ def create_ultrastar_txt_from_automation(
|
||||
return real_bpm, ultrastar_file_output
|
||||
|
||||
|
||||
def infos_from_audio_input_file() -> tuple[str, str, str]:
|
||||
def infos_from_audio_input_file() -> tuple[str, str, str, tuple[str, str, str, []]]:
|
||||
"""Infos from audio input file"""
|
||||
basename = os.path.basename(settings.input_file_path)
|
||||
basename_without_ext = os.path.splitext(basename)[0]
|
||||
|
||||
artist, title = None, None
|
||||
if " - " in basename_without_ext:
|
||||
artist, title = basename_without_ext.split(" - ", 1)
|
||||
search_string = f"{artist} - {title}"
|
||||
else:
|
||||
search_string = basename_without_ext
|
||||
|
||||
# Get additional data for song
|
||||
(title_info, artist_info, year_info, genre_info) = get_music_infos(search_string)
|
||||
|
||||
if title_info is not None:
|
||||
title = title_info
|
||||
artist = artist_info
|
||||
|
||||
if artist is not None and title is not None:
|
||||
basename_without_ext = f"{artist} - {title}"
|
||||
extension = os.path.splitext(basename)[1]
|
||||
basename = f"{basename_without_ext}{extension}"
|
||||
|
||||
song_output = os.path.join(settings.output_file_path, basename_without_ext)
|
||||
song_output = get_unused_song_output_dir(song_output)
|
||||
os_helper.create_folder(song_output)
|
||||
os_helper.copy(settings.input_file_path, song_output)
|
||||
os_helper.rename(os.path.join(song_output, os.path.basename(settings.input_file_path)), os.path.join(song_output, basename))
|
||||
ultrastar_audio_input_path = os.path.join(song_output, basename)
|
||||
return basename_without_ext, song_output, ultrastar_audio_input_path
|
||||
return basename_without_ext, song_output, ultrastar_audio_input_path, (title, artist, year_info, genre_info)
|
||||
|
||||
|
||||
FILENAME_REPLACEMENTS = (('?:"', ""), ("<", "("), (">", ")"), ("/\\|*", "-"))
|
||||
@@ -573,10 +620,18 @@ def sanitize_filename(fname: str) -> str:
|
||||
return fname
|
||||
|
||||
|
||||
def download_from_youtube() -> tuple[str, str, str]:
|
||||
def download_from_youtube() -> tuple[str, str, str, tuple[str, str, str, []]]:
|
||||
"""Download from YouTube"""
|
||||
title = get_youtube_title(settings.input_file_path)
|
||||
basename_without_ext = sanitize_filename(title)
|
||||
(artist, title) = get_youtube_title(settings.input_file_path)
|
||||
|
||||
# Get additional data for song
|
||||
(title_info, artist_info, year_info, genre_info) = get_music_infos(f"{artist} - {title}")
|
||||
|
||||
if title_info is not None:
|
||||
title = title_info
|
||||
artist = artist_info
|
||||
|
||||
basename_without_ext = sanitize_filename(f"{artist} - {title}")
|
||||
basename = basename_without_ext + ".mp3"
|
||||
song_output = os.path.join(settings.output_file_path, basename_without_ext)
|
||||
song_output = get_unused_song_output_dir(song_output)
|
||||
@@ -591,7 +646,7 @@ def download_from_youtube() -> tuple[str, str, str]:
|
||||
settings.input_file_path, basename_without_ext, song_output
|
||||
)
|
||||
ultrastar_audio_input_path = os.path.join(song_output, basename)
|
||||
return basename_without_ext, song_output, ultrastar_audio_input_path
|
||||
return basename_without_ext, song_output, ultrastar_audio_input_path, (title, artist, year_info, genre_info)
|
||||
|
||||
|
||||
def parse_ultrastar_txt() -> tuple[str, float, str, str, UltrastarTxtValue]:
|
||||
|
||||
@@ -9,7 +9,7 @@ from PIL import Image
|
||||
from src.modules.console_colors import ULTRASINGER_HEAD
|
||||
|
||||
|
||||
def get_youtube_title(url: str) -> str:
|
||||
def get_youtube_title(url: str) -> tuple[str, str]:
|
||||
"""Get the title of the YouTube video"""
|
||||
|
||||
ydl_opts = {}
|
||||
@@ -18,7 +18,11 @@ def get_youtube_title(url: str) -> str:
|
||||
url, download=False # We just want to extract the info
|
||||
)
|
||||
|
||||
return result["title"]
|
||||
if "artist" in result:
|
||||
return result["artist"], result["track"]
|
||||
if " - " in result["title"]:
|
||||
return result["title"].split(" - ")[0], result["title"].split(" - ")[1]
|
||||
return result["channel"], result["title"]
|
||||
|
||||
|
||||
def download_youtube_audio(url: str, clear_filename: str, output_path: str):
|
||||
|
||||
@@ -59,6 +59,8 @@ class UltrastarTxtValue:
|
||||
|
||||
artist = ""
|
||||
title = ""
|
||||
year = ""
|
||||
genre = ""
|
||||
mp3 = ""
|
||||
video = None
|
||||
gap = ""
|
||||
|
||||
@@ -69,6 +69,10 @@ def create_ultrastar_txt_from_automation(
|
||||
file.write(f"#{UltrastarTxtTag.BPM}:{round(ultrastar_bpm, 2)}\n") # not the real BPM!
|
||||
file.write(f"#{UltrastarTxtTag.GAP}:{int(gap * 1000)}\n")
|
||||
file.write(f"#{UltrastarTxtTag.COMMENT}:{ultrastar_class.comment}\n")
|
||||
if ultrastar_class.year is not None:
|
||||
file.write(f"#{UltrastarTxtTag.YEAR}:{ultrastar_class.year}\n")
|
||||
if ultrastar_class.genre:
|
||||
file.write(f"#{UltrastarTxtTag.GENRE}:{ultrastar_class.genre}\n")
|
||||
|
||||
# Write the singing part
|
||||
previous_end_beat = 0
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import musicbrainzngs
|
||||
import string
|
||||
from src.modules.console_colors import ULTRASINGER_HEAD, blue_highlighted, red_highlighted
|
||||
|
||||
|
||||
def get_music_infos(search_string: str) -> tuple[str, str, str, []]:
|
||||
print(f"{ULTRASINGER_HEAD} Searching song in {blue_highlighted('musicbrainz')}")
|
||||
# https://python-musicbrainzngs.readthedocs.io/en/v0.7.1/usage/#searching
|
||||
|
||||
musicbrainzngs.set_useragent("UltraSinger", "0.1", "https://github.com/rakuri255/UltraSinger")
|
||||
|
||||
artists = musicbrainzngs.search_artists(search_string)
|
||||
artist = artists['artist-list'][0]['name']
|
||||
release_groups = musicbrainzngs.search_release_groups(search_string, artist=artist)
|
||||
release = release_groups['release-group-list'][0]
|
||||
|
||||
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()
|
||||
if clean_release_title in clean_search_string:
|
||||
title = release['title']
|
||||
else:
|
||||
print(
|
||||
f"{ULTRASINGER_HEAD} cant find title {red_highlighted(release['title'])} in {red_highlighted(search_string)}")
|
||||
|
||||
if 'artist-credit-phrase' in release:
|
||||
artist = release['artist-credit-phrase']
|
||||
|
||||
if title is None or artist is None:
|
||||
print(f"{ULTRASINGER_HEAD} {red_highlighted('No match found')}")
|
||||
return None, None, None, []
|
||||
|
||||
print(f"{ULTRASINGER_HEAD} Found and using {blue_highlighted(title)} by {blue_highlighted(artist)}")
|
||||
|
||||
year = None
|
||||
if 'first-release-date' in release:
|
||||
year = release['first-release-date']
|
||||
print(f"{ULTRASINGER_HEAD} Release year: {blue_highlighted(year)}")
|
||||
|
||||
genre = []
|
||||
if 'tag-list' in release:
|
||||
for tag in release['tag-list']:
|
||||
genre.append(tag['name'])
|
||||
|
||||
return title, artist, year, genre
|
||||
@@ -19,11 +19,16 @@ def move(original: str, target: str) -> None:
|
||||
shutil.move(original, target)
|
||||
|
||||
|
||||
def copy(original:str, target: str) -> None:
|
||||
def copy(original: str, target: str) -> None:
|
||||
"""Copies a file from one location to another."""
|
||||
shutil.copy(original, target)
|
||||
|
||||
|
||||
def rename(original: str, target: str) -> None:
|
||||
"""Renames a file."""
|
||||
os.rename(original, target)
|
||||
|
||||
|
||||
def current_executor_path() -> str:
|
||||
"""Current executor path"""
|
||||
return os.getcwd()
|
||||
|
||||
Reference in new issue
Block a user