-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathget_instruments.py
More file actions
35 lines (32 loc) · 1.27 KB
/
Copy pathget_instruments.py
File metadata and controls
35 lines (32 loc) · 1.27 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
"""Scrapes the General MIDI Wikipedia article for a list of
instrument types and outputs a list of instrument tuples.
Needs the 'wikipedia' library.
"""
import wikipedia
import string
print("instruments = [")
gmidi = wikipedia.page("General MIDI")
last_header = "broken lol"
for line in gmidi.content.split("\n"):
if len(line) > 0 and line[0] in string.digits:
try:
parts = line.split()
if last_header == "percussion":
if int(parts[0]) < 81:
print(" ({}, \"{}\"),".format(parts[0], " ".join(parts[1:])))
elif int(parts[0]) == 81:
print(" ({}, \"{}\")".format(parts[0], " ".join(parts[1:])))
print("]")
break
else:
if int(parts[0]) < 128:
print(" ({}, \"{}\", \"{}\"),".format(parts[0], " ".join(parts[1:]), last_header))
elif int(parts[0]) == 128:
print(" ({}, \"{}\", \"{}\")".format(parts[0], " ".join(parts[1:]), last_header))
print("]")
print()
print("percussion = [")
except:
pass
elif line.startswith("="):
last_header = " ".join(line.split()[1:-1]).lower()