-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_sample.py
63 lines (43 loc) · 1.42 KB
/
gen_sample.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
import random
import sys
import linecache
import shutil
# Command-line arguments
survivor = os.sys.argv[1]
character = os.sys.argv[2]
# Define metadata path
file_list = os.path.join("meta", "fl")
# Check if meta directory exists
if not os.path.exists(file_list):
print(f"Error: '{file_list}' does not exist.")
sys.exit(69)
# Assumes character has a generic folder
gen_dir = os.path.join(character, "generic")
# Check if generic directory exists
if not os.path.exists(gen_dir):
print(f"Error: '{gen_dir}' does not exist.")
sys.exit(69)
# Create a directory with the name specified in 'survivor'
os.makedirs(survivor, exist_ok=True)
# Determine the number of lines in the 'fl' file
with open(file_list, 'r') as file:
loop_end = sum(1 for _ in file)
# Define the RNG function
def rng():
return random.randint(0, len(os.listdir(gen_dir)) - 1)
counter = 1
while counter <= loop_end:
seed = rng()
audio = linecache.getline(file_list, counter).strip()
vline = os.path.join(gen_dir, f"{character}{seed}.wav")
destination_path = os.path.join(survivor, audio)
# Copy the audio file to the 'survivor' directory
try:
shutil.copy2(vline, destination_path)
print(f"Copied: {vline} to {destination_path}")
except FileNotFoundError:
print(f"Error: File not found - {vline}")
counter += 1
print(f"Generic {survivor} has been created.")
sys.exit(0)