mirror of
https://github.com/rakuri255/UltraSinger.git
synced 2026-11-20 13:07:52 +09:00
Merge pull request #110 from rakuri255/format_separated_string
Format separated string
This commit is contained in:
3 files changed
+33
-1
No files matched your search
@@ -1,6 +1,7 @@
|
||||
Version: 0.0.5
|
||||
Date: 2023.12.23
|
||||
Changes:
|
||||
- Format GENRE string
|
||||
- Extract year from date
|
||||
|
||||
Version: 0.0.4
|
||||
|
||||
@@ -1,7 +1,17 @@
|
||||
"""Tests for UltraSinger.py"""
|
||||
|
||||
import unittest
|
||||
from src.UltraSinger import format_separated_string
|
||||
from src.UltraSinger import extract_year
|
||||
|
||||
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')
|
||||
|
||||
def test_extract_year(self):
|
||||
years = {extract_year("2023-12-31"), extract_year("2023-12-31 23:59:59"), extract_year("2023/12/31"),
|
||||
|
||||
+22
-1
@@ -587,7 +587,7 @@ def create_ultrastar_txt_from_automation(
|
||||
if year is not None:
|
||||
ultrastar_header.year = extract_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(
|
||||
@@ -625,6 +625,27 @@ def extract_year(date: str) -> str:
|
||||
else:
|
||||
return date
|
||||
|
||||
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