-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
71 lines (56 loc) · 2.45 KB
/
main.py
File metadata and controls
71 lines (56 loc) · 2.45 KB
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
import os
import guitarpro
def merge_gp5_files(input_files, output_file):
"""
Merge multiple Guitar Pro 5 files into a single GP5 file.
Args:
input_files (list): List of paths to input GP5 files
output_file (str): Path where the merged file will be saved
"""
if not input_files:
raise ValueError("No input files provided")
try:
merged_song = guitarpro.parse(input_files[0])
merged_song.title = "Setlist - " + merged_song.title
merged_song.version = "FICHIER GUITAR PRO v5.00"
except Exception as e:
raise Exception(f"Error loading first file {input_files[0]}: {str(e)}")
for file_path in input_files[1:]:
try:
current_song = guitarpro.parse(file_path)
if len(merged_song.tracks[0].measures) > 0:
last_measure = merged_song.tracks[0].measures[-1]
last_measure.header.isDoubleBar = True
for track_idx, track in enumerate(current_song.tracks):
if track_idx < len(merged_song.tracks):
merged_song.tracks[track_idx].measures.extend(track.measures)
else:
merged_song.tracks.append(track)
first_new_measure = len(merged_song.tracks[0].measures) - len(current_song.tracks[0].measures)
if first_new_measure >= 0:
measure = merged_song.tracks[0].measures[first_new_measure]
text = guitarpro.models.Text()
text.value = f"--- {current_song.title} ---"
measure.text = text
except Exception as e:
print(f"Warning: Error processing {file_path}: {str(e)}")
continue
try:
if not output_file.lower().endswith('.gp5'):
output_file = output_file.rsplit('.', 1)[0] + '.gp5'
guitarpro.write(merged_song, output_file)
print(f"Successfully created merged file: {output_file}")
except Exception as e:
raise Exception(f"Error saving merged file: {str(e)}")
if __name__ == "__main__":
folder_path = "setlist_songs/"
gp5_files = [
os.path.join(folder_path, f)
for f in os.listdir(folder_path)
if f.lower().endswith('.gp5')
]
gp5_files.sort()
try:
merge_gp5_files(gp5_files, "merged_setlist.gp5")
except Exception as e:
print(f"Error: {str(e)}")