-
Notifications
You must be signed in to change notification settings - Fork 0
/
regex.py
41 lines (29 loc) · 901 Bytes
/
regex.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
import re
def get_bpm_key (path:str):
txt = path.split("\\")[-1]
# \ masks symbol in order to use it in the regex
w = re.search(r"\[.*\]", txt)
number = w.group().strip()
#print(number)
txt = txt.replace(w.group(), "")
# \s matches any white space character
x = re.search(r"\s.*(Minor|Major)", txt)
key = x.group().strip()
# Name fix
try:
key = key.split("/")[1].strip()
except:
pass
#print(key)
txt = txt.replace(x.group(), "")
y = re.search(r"\s.*BPM", txt.strip())
bpm = y.group().strip().replace("BPM", "")
#print(bpm)
txt = path.split("\\")[-1]
#print(txt)
# (?<={key}) positive lookbehind = beginning of string
# (?={bpm} positive lookahead = end of string
z = re.search(fr"(?<=BPM )(.*?)(?= \(Prod)", txt)
name = z.group().strip()
#print(name)
return bpm, key, name