This commit is contained in:
Cainan 2024-06-24 20:04:46 +01:00
parent 473f5d01fe
commit 5ac874ef8e
2 changed files with 44 additions and 7 deletions

View File

@ -593,6 +593,7 @@ def export_data():
if custom_songs: if custom_songs:
for item_id in selected_items: for item_id in selected_items:
song_id = tree.item(item_id)["values"][2] song_id = tree.item(item_id)["values"][2]
custom_fumen_folder_path = os.path.join(custom_data_dir, "fumen", str(song_id)) custom_fumen_folder_path = os.path.join(custom_data_dir, "fumen", str(song_id))
if os.path.exists(custom_fumen_folder_path): if os.path.exists(custom_fumen_folder_path):
@ -797,8 +798,20 @@ def export_data():
# Find the wordlist items corresponding to song variations # Find the wordlist items corresponding to song variations
word_keys = [f"song_{song_id}", f"song_sub_{song_id}", f"song_detail_{song_id}"] word_keys = [f"song_{song_id}", f"song_sub_{song_id}", f"song_detail_{song_id}"]
for key in word_keys:
def find_word_info(key, word_lists):
for word_list in word_lists:
word_info = next((item for item in word_list["items"] if item["key"] == key), None) word_info = next((item for item in word_list["items"] if item["key"] == key), None)
if word_info:
return word_info
return None
word_lists = [word_list]
if custom_songs:
word_lists.append(custom_word_list)
for key in word_keys:
word_info = find_word_info(key, word_lists)
if word_info: if word_info:
selected_wordlist.append(word_info) selected_wordlist.append(word_info)
@ -834,8 +847,6 @@ def export_data():
if os.path.exists(f"song_{song_id}.mp3.at9"): if os.path.exists(f"song_{song_id}.mp3.at9"):
os.remove(f"song_{song_id}.mp3.at9") os.remove(f"song_{song_id}.mp3.at9")
print(f"Deleted song_{song_id}.mp3.at9") print(f"Deleted song_{song_id}.mp3.at9")
else:
print(f"Error: File song_{song_id}.mp3.at9 not found.")
# Check if preview_pos or custom_preview_pos is not None and run conversion # Check if preview_pos or custom_preview_pos is not None and run conversion
if preview_pos is not None or (custom_songs and custom_preview_pos is not None): if preview_pos is not None or (custom_songs and custom_preview_pos is not None):
@ -899,8 +910,6 @@ def export_data():
if os.path.exists(f"song_{song_id}.mp3.idsp"): if os.path.exists(f"song_{song_id}.mp3.idsp"):
os.remove(f"song_{song_id}.mp3.idsp") os.remove(f"song_{song_id}.mp3.idsp")
print(f"Deleted song_{song_id}.mp3.idsp") print(f"Deleted song_{song_id}.mp3.idsp")
else:
print(f"Error: File song_{song_id}.mp3.idsp not found.")
# Check if preview_pos or custom_preview_pos is not None and run conversion # Check if preview_pos or custom_preview_pos is not None and run conversion
if preview_pos is not None or (custom_songs and custom_preview_pos is not None): if preview_pos is not None or (custom_songs and custom_preview_pos is not None):

View File

@ -4,6 +4,7 @@ import shutil
from pydub import AudioSegment from pydub import AudioSegment
import subprocess import subprocess
import concurrent.futures import concurrent.futures
from concurrent.futures import ThreadPoolExecutor
import argparse import argparse
import logging import logging
from threading import Lock from threading import Lock
@ -238,10 +239,20 @@ def move_and_rename_bin_files(tja_path, output_dir, unique_id):
output_path = os.path.join(output_dir, f"fumen/cs{unique_id:04d}") output_path = os.path.join(output_dir, f"fumen/cs{unique_id:04d}")
os.makedirs(output_path, exist_ok=True) os.makedirs(output_path, exist_ok=True)
for difficulty in ["_e", "_n", "_h", "_x", "_m"]: difficulties = ["_e", "_n", "_h", "_x", "_m"]
any_bin_file_moved = False
for difficulty in difficulties:
bin_file = f"{os.path.splitext(tja_path)[0]}{difficulty}.bin" bin_file = f"{os.path.splitext(tja_path)[0]}{difficulty}.bin"
if os.path.exists(bin_file): if os.path.exists(bin_file):
shutil.move(bin_file, os.path.join(output_path, f"cs{unique_id:04d}{difficulty}.bin")) shutil.move(bin_file, os.path.join(output_path, f"cs{unique_id:04d}{difficulty}.bin"))
any_bin_file_moved = True
if not any_bin_file_moved:
# Move the generic .bin file as cs{unique_id:04d}_m.bin
generic_bin_file = f"{os.path.splitext(tja_path)[0]}.bin"
if os.path.exists(generic_bin_file):
shutil.move(generic_bin_file, os.path.join(output_path, f"cs{unique_id:04d}_m.bin"))
def process_song_charts(dir_path, file, output_folder, unique_id): def process_song_charts(dir_path, file, output_folder, unique_id):
tja_path = os.path.join(dir_path, file) tja_path = os.path.join(dir_path, file)
@ -253,15 +264,32 @@ def process_song_metadata(dir_path, file, genre_no, unique_id, output_folder):
info = parse_tja(tja_path) info = parse_tja(tja_path)
create_json_files(info, genre_no, unique_id, output_folder) create_json_files(info, genre_no, unique_id, output_folder)
#def process_song_audio(dir_path, file, unique_id, output_folder):
# tja_path = os.path.join(dir_path, file)
# info = parse_tja(tja_path)
# convert_audio(os.path.join(dir_path, info['WAVE']), os.path.join(output_folder, f"sound/song_cs{unique_id:04d}.mp3"))
def process_song_audio(dir_path, file, unique_id, output_folder): def process_song_audio(dir_path, file, unique_id, output_folder):
tja_path = os.path.join(dir_path, file) tja_path = os.path.join(dir_path, file)
info = parse_tja(tja_path) info = parse_tja(tja_path)
convert_audio(os.path.join(dir_path, info['WAVE']), os.path.join(output_folder, f"sound/song_cs{unique_id:04d}.mp3")) convert_audio(os.path.join(dir_path, info['WAVE']), os.path.join(output_folder, f"sound/song_cs{unique_id:04d}.mp3"))
def process_songs_multithreaded(dir_path, files, output_folder):
with ThreadPoolExecutor() as executor:
futures = []
for unique_id, file in enumerate(files):
futures.append(executor.submit(process_song_audio, dir_path, file, unique_id, output_folder))
# Optionally, wait for all futures to complete
for future in futures:
future.result()
def process_song(dir_path, file, genre_no, unique_id, output_folder): def process_song(dir_path, file, genre_no, unique_id, output_folder):
try: try:
process_song_charts(dir_path, file, output_folder, unique_id)
process_song_audio(dir_path, file, unique_id, output_folder) process_song_audio(dir_path, file, unique_id, output_folder)
process_song_charts(dir_path, file, output_folder, unique_id)
process_song_metadata(dir_path, file, genre_no, unique_id, output_folder) process_song_metadata(dir_path, file, genre_no, unique_id, output_folder)
#logging.info(f"Processed {file} successfully.") #logging.info(f"Processed {file} successfully.")
except Exception as e: except Exception as e: