-
Notifications
You must be signed in to change notification settings - Fork 0
/
CH Song Tool - V2.0.py
202 lines (173 loc) · 8.23 KB
/
CH Song Tool - V2.0.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import os
import shutil
def clear_console():
os.system('cls' if os.name == 'nt' else 'clear')
def show_help():
clear_console()
print("Help:")
print("This script organizes folders into a structure based on band names and song names.")
print("\nFolder Setup:")
print("1. Your music folder should contain subfolders named in the format 'Band - Song Name'.")
print("2. For example, if you have a band named 'The Great Band' and a song named 'Hit Single',")
print(" you should have a folder named 'The Great Band - Hit Single'.")
print("\nHow the Script Works:")
print("1. The script will iterate through each folder in the specified music folder.")
print("2. It will split the folder names based on ' - ' to determine the band name and song name.")
print("3. It will create a new folder for each band if it doesn't already exist.")
print("4. The script will move each song folder into the corresponding band folder.")
print("5. If a folder with the same name already exists, you will be given options to:")
print(" - Overwrite the existing folder")
print(" - Skip moving the folder")
print(" - Delete the existing folder")
print("\nOptions:")
print("1. Sort songs into band folders: Organizes your folders as described.")
print("2. Fix Bad Songs: Handles issues listed in pasted content.")
print("3. Exit: Closes the script.")
print("h: Show this help text.")
print("\nInfo:")
print("If you run into any problems, please contact maxthespy on Discord.")
print("Use at your own risk.")
input("Hit Enter to return to the menu...")
def sort_songs_into_band_folders():
clear_console()
source_directory = input('Path to your music folder: ').strip()
if not os.path.isdir(source_directory):
print("The provided path is not a directory or does not exist.")
input("Hit Enter to return to the menu...")
return
for folder_name in os.listdir(source_directory):
folder_path = os.path.join(source_directory, folder_name)
if os.path.isdir(folder_path):
split_name = folder_name.split(' - ')
if len(split_name) > 1:
parent_folder_name = split_name[0].strip()
parent_folder_path = os.path.join(source_directory, parent_folder_name)
if not os.path.exists(parent_folder_path):
os.makedirs(parent_folder_path)
destination_path = os.path.join(parent_folder_path, folder_name)
if os.path.exists(destination_path):
while True:
choice = input(f"The folder '{folder_name}' already exists in '{parent_folder_name}'. Overwrite, skip, or delete? (o/s/d): ").lower()
if choice == 'o':
try:
shutil.rmtree(destination_path)
shutil.move(folder_path, destination_path)
print(f"Overwritten and moved {folder_name} to {parent_folder_name}/")
break
except Exception as e:
print(f"An error occurred while overwriting: {e}")
elif choice == 's':
print(f"Skipped moving {folder_name}.")
break
elif choice == 'd':
try:
shutil.rmtree(folder_path)
print(f"Deleted {folder_name}.")
break
except Exception as e:
print(f"An error occurred while deleting: {e}")
else:
print("Invalid choice. Please enter 'o', 's', or 'd'.")
else:
try:
shutil.move(folder_path, destination_path)
print(f"Moved {folder_name} to {parent_folder_name}/")
except Exception as e:
print(f"An error occurred while moving: {e}")
print("Sorting complete.")
input("Hit Enter to return to the menu...")
import os
import shutil
def clear_console():
os.system('cls' if os.name == 'nt' else 'clear')
def fix_bad_songs():
clear_console()
print("Please copy and paste everything under 'ERROR: These folders contain charts that another song has (duplicate charts)!'")
print("When finished pasting, type 'fix' and press Enter:")
bad_songs_content = []
while True:
line = input()
if line.strip().lower() == 'fix':
break
bad_songs_content.append(line.strip())
if not bad_songs_content:
print("No content provided.")
input("Hit Enter to return to the menu...")
return
for line in bad_songs_content:
if not line:
continue
try:
# Find the split point for the path
split_point = line.find('(')
if split_point == -1:
print(f"Line '{line}' is not in the expected format.")
continue
original_path = line[:split_point].strip()
duplicate_path = line[split_point:].strip()
# Remove leading '(' and trailing ')' from the duplicate path
if duplicate_path.startswith('('):
duplicate_path = duplicate_path[1:].strip()
if duplicate_path.endswith(')'):
duplicate_path = duplicate_path[:-1].strip()
# Check for additional unwanted text at the beginning of the duplicate path
# Remove the text before the actual path if it's not part of the file name
start_index = duplicate_path.find('c:\\')
if start_index != -1:
duplicate_path = duplicate_path[start_index:]
print(f"\n1. Original Path: {original_path}")
print(f"2. Duplicate Path: {duplicate_path}")
while True:
choice = input("Which path do you want to delete? (1 for Original Path, 2 for Duplicate Path, or n to skip): ").strip().lower()
if choice == '1':
if os.path.isdir(original_path):
try:
shutil.rmtree(original_path)
print(f"Deleted {original_path}.")
except Exception as e:
print(f"An error occurred while deleting {original_path}: {e}")
else:
print(f"The path '{original_path}' does not exist.")
break
elif choice == '2':
if os.path.isdir(duplicate_path):
try:
shutil.rmtree(duplicate_path)
print(f"Deleted {duplicate_path}.")
except Exception as e:
print(f"An error occurred while deleting {duplicate_path}: {e}")
else:
print(f"The path '{duplicate_path}' does not exist.")
break
elif choice == 'n':
print("Skipped deletion.")
break
else:
print("Invalid choice. Please enter '1', '2', or 'n'.")
except Exception as e:
print(f"An error occurred while processing the line '{line}': {e}")
print("Fixing complete.")
input("Hit Enter to return to the menu...")
def main():
while True:
clear_console()
print("What would you like to do?")
print("1. Sort Songs Into Band Folders")
print("2. Fix Bad Songs")
print("h. Help")
print("e. Exit")
choice = input("Enter your choice (1, 2, 3, or h): ").strip().lower()
if choice == '1':
sort_songs_into_band_folders()
elif choice == '2':
fix_bad_songs()
elif choice == 'e':
print("Goodbye!")
break
elif choice == 'h':
show_help()
else:
print("Invalid choice. Please enter '1', '2', '3', or 'h'.")
input("Hit Enter to continue...")
if __name__ == "__main__":
main()