mirror of
https://github.com/rakuri255/UltraSinger.git
synced 2026-11-20 13:07:52 +09:00
Format GENRE string
This commit is contained in:
1 parent
e39cfa0c9b
commit
bdcfdd1bb5
3 files changed
+40
-1
No files matched your search
@@ -1,3 +1,8 @@
|
||||
Version: 0.0.5
|
||||
Date: 2023.12.23
|
||||
Changes:
|
||||
- Format GENRE string
|
||||
|
||||
Version: 0.0.4
|
||||
Date: 2023.12.16
|
||||
Changes:
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
"""Tests for UltraSinger.py"""
|
||||
|
||||
import unittest
|
||||
from src.UltraSinger import format_separated_string
|
||||
class TestUltraSinger(unittest.TestCase):
|
||||
def test_format_separated_string(self):
|
||||
|
||||
self.assertEqual(format_separated_string('rock,pop,rock-pop,'), 'Rock, Pop, Rock-Pop')
|
||||
self.assertEqual(format_separated_string('rock;pop;rock-pop,'), 'Rock, Pop, Rock-Pop')
|
||||
self.assertEqual(format_separated_string('rock/pop/rock-pop,'), 'Rock, Pop, Rock-Pop')
|
||||
self.assertEqual(format_separated_string('rock,pop/rock-pop;80s,'), 'Rock, Pop, Rock-Pop, 80s')
|
||||
self.assertEqual(format_separated_string('rock, pop, rock-pop, '), 'Rock, Pop, Rock-Pop')
|
||||
+23
-1
@@ -4,6 +4,7 @@ import copy
|
||||
import getopt
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
|
||||
import Levenshtein
|
||||
import librosa
|
||||
@@ -586,7 +587,7 @@ def create_ultrastar_txt_from_automation(
|
||||
if year is not None:
|
||||
ultrastar_header.year = year
|
||||
if genre is not None:
|
||||
ultrastar_header.genre = genre
|
||||
ultrastar_header.genre = format_separated_string(genre)
|
||||
|
||||
real_bpm = get_bpm_from_file(ultrastar_audio_input_path)
|
||||
ultrastar_file_output = os.path.join(
|
||||
@@ -618,6 +619,27 @@ def create_ultrastar_txt_from_automation(
|
||||
return real_bpm, ultrastar_file_output
|
||||
|
||||
|
||||
def format_separated_string(data: str) -> str:
|
||||
temp = re.sub(r'[;/]', ',', data)
|
||||
words = temp.split(',')
|
||||
words = [s for s in words if s.strip()]
|
||||
|
||||
for i, word in enumerate(words):
|
||||
if "-" not in word:
|
||||
words[i] = word.strip().capitalize() + ', '
|
||||
else:
|
||||
dash_words = word.split('-')
|
||||
capitalized_dash_words = [dash_word.strip().capitalize() for dash_word in dash_words]
|
||||
formatted_dash_word = '-'.join(capitalized_dash_words) + ', '
|
||||
words[i] = formatted_dash_word
|
||||
|
||||
formatted_string = ''.join(words)
|
||||
|
||||
if formatted_string.endswith(', '):
|
||||
formatted_string = formatted_string[:-2]
|
||||
|
||||
return formatted_string
|
||||
|
||||
def infos_from_audio_input_file() -> tuple[str, str, str, tuple[str, str, str, str]]:
|
||||
"""Infos from audio input file"""
|
||||
basename = os.path.basename(settings.input_file_path)
|
||||
|
||||
Reference in new issue
Block a user