File size: 3,151 Bytes
f1d4767
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from pathlib import Path
import pandas as pd
import shutil

metadata = pd.read_csv("gaps_metadata.csv")

audio_files = list(Path("./audio").glob("*.wav"))
midi_files = list(Path("./midi").glob("*-fine-aligned.mid"))
syncpoint_files = list(Path("./syncpoints").glob("*-syncpoints.json"))
xml_files = list(Path("./musicxml").glob("*.xml"))
match_files = list(Path("./match").glob("*.match"))

row_dicts = [r[1].to_dict() for r in metadata.iterrows()]

for row in row_dicts:
    scorehash = row["scorehash"]
    target_audio_path = row["audio_path"]
    target_midi_path = row["midi_path"]
    target_syncpoint_path = f"syncpoints/{row['id']}.json"
    target_xml_path = f"musicxml/{row['id']}.xml"
    target_match_path = f"match/{row['id']}.match"

    if not Path(target_audio_path).exists():
        try:
            source_audio_path = [a for a in audio_files if a.stem == scorehash]
            if len(source_audio_path) == 0:
                print(f"Audio not found for {scorehash}")
                continue
            else:
                source_audio_path = source_audio_path[0]

            shutil.move(str(source_audio_path), target_audio_path)
        except:
            print("audio")
            breakpoint()

    if not Path(target_midi_path).exists():
        try: 
            source_midi_path = [m for m in midi_files if m.stem.replace("-fine-aligned", "") == scorehash]
            if len(source_midi_path) == 0:
                print(f"midi not found for {scorehash}")
                continue
            else:
                source_midi_path = source_midi_path[0]
            shutil.move(str(source_midi_path), target_midi_path)
        except:
            print("midi")
            breakpoint()
    
    if not Path(target_syncpoint_path).exists():
        try:
            source_syncpoint_path = [s for s in syncpoint_files if s.stem.replace("-syncpoints", "") == scorehash]
            if len(source_syncpoint_path) == 0:
                print(f"Syncpoints not found for {scorehash}")
                continue
            else:
                source_syncpoint_path = source_syncpoint_path[0]
            shutil.move(str(source_syncpoint_path), target_syncpoint_path)
        except:
            print("syncpoint")
            breakpoint()
    
    if not Path(target_xml_path).exists():
        try:
            source_xml_path = [x for x in xml_files if x.stem == scorehash]
            if len(source_xml_path) == 0:
                print(f"xml not found for {scorehash}")
                continue
            else:
                source_xml_path = source_xml_path[0]
            shutil.move(str(source_xml_path), target_xml_path)
        except:
            print("xml")
            breakpoint()
    
    if not Path(target_match_path).exists():
        try:
            source_match_path = [m for m in match_files if m.stem == scorehash]
            if len(source_match_path) == 0:
                continue
            else:
                source_match_path = source_audio_path[0]
            shutil.move(str(source_match_path), target_match_path)
        except:
            print("match")
            breakpoint()