-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcueparse.py
60 lines (56 loc) · 2.07 KB
/
cueparse.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
#
# cueparse.py
# .cue file parser
#
# Xander Jones [2020]
#
class Cuetrack:
title = None
performer = None
file = None
index = None
def __init__(self, track_title, track_performer, track_file, track_index):
self.title = track_title
self.performer = track_performer
self.file = track_file
self.index = track_index
class Cuefile:
date = None
recorded_by = None
title = None
performer = None
file = None
tracks = []
input_file = None
def _parse_file(self, file):
with open(file, 'r') as f:
track_title = None
track_performer = None
track_file = None
track_index = None
for index, line in enumerate(f):
if line[:8] == "REM DATE":
self.date = line[9:].strip().replace("\"","")
elif line[:15] == "REM RECORDED_BY":
self.recorded_by = line[16:].strip().replace("\"","")
elif line[:5] == "TITLE":
self.title = line[6:].strip().replace("\"","")
elif line[:9] == "PERFORMER":
self.performer = line[10:].strip().replace("\"","")
elif line[:4] == "FILE":
self.file = line[5:-5].strip().replace("\"","")
elif line[:7] == " TITLE":
track_title = line[8:].strip().replace("\"","")
elif line[:11] == " PERFORMER":
track_performer = line[12:].strip().replace("\"","")
elif line[:6] == " FILE":
track_file = line[7:].strip().replace("\"","")
elif line[:7] == " INDEX":
track_index = line[10:].strip().replace("\"","")
self.tracks.append(Cuetrack(track_title, track_performer, track_file, track_index))
track_title = None
track_performer = None
track_file = None
track_index = None
def __init__(self, input_file):
self._parse_file(input_file)