mirror of
https://github.com/rakuri255/UltraSinger.git
synced 2026-11-20 13:07:52 +09:00
Merge pull request #109 from rakuri255/Extract-year-form-string
Extract year from date
This commit is contained in:
3 files changed
+27
-1
No files matched your search
@@ -1,3 +1,8 @@
|
||||
Version: 0.0.5
|
||||
Date: 2023.12.23
|
||||
Changes:
|
||||
- Extract year from date
|
||||
|
||||
Version: 0.0.4
|
||||
Date: 2023.12.16
|
||||
Changes:
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import unittest
|
||||
from src.UltraSinger import extract_year
|
||||
|
||||
class TestUltraSinger(unittest.TestCase):
|
||||
|
||||
def test_extract_year(self):
|
||||
years = {extract_year("2023-12-31"), extract_year("2023-12-31 23:59:59"), extract_year("2023/12/31"),
|
||||
extract_year("2023\\12\\31"), extract_year("2023.12.31"), extract_year("2023 12 31"),
|
||||
extract_year("12-31-2023"), extract_year("12/31/2023"), extract_year("12\\31\\2023"),
|
||||
extract_year("12.31.2023"), extract_year("12 31 2023"), extract_year("12-2023"),
|
||||
extract_year("12/2023"), extract_year("2023")}
|
||||
|
||||
for year in years:
|
||||
self.assertEqual(year, "2023")
|
||||
+8
-1
@@ -4,6 +4,7 @@ import copy
|
||||
import getopt
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
|
||||
import Levenshtein
|
||||
import librosa
|
||||
@@ -584,7 +585,7 @@ def create_ultrastar_txt_from_automation(
|
||||
if artist is not None:
|
||||
ultrastar_header.artist = artist
|
||||
if year is not None:
|
||||
ultrastar_header.year = year
|
||||
ultrastar_header.year = extract_year(year)
|
||||
if genre is not None:
|
||||
ultrastar_header.genre = genre
|
||||
|
||||
@@ -617,6 +618,12 @@ def create_ultrastar_txt_from_automation(
|
||||
)
|
||||
return real_bpm, ultrastar_file_output
|
||||
|
||||
def extract_year(date: str) -> str:
|
||||
match = re.search(r'\b\d{4}\b', date)
|
||||
if match:
|
||||
return match.group(0)
|
||||
else:
|
||||
return date
|
||||
|
||||
def infos_from_audio_input_file() -> tuple[str, str, str, tuple[str, str, str, str]]:
|
||||
"""Infos from audio input file"""
|
||||
|
||||
Reference in new issue
Block a user