26
26
Testing code to identify possible edit flags.
27
27
'''
28
28
29
+ # pylint: disable=too-many-public-methods
30
+
29
31
import re
30
32
from musicscan .data .cd import Album
31
- from musicscan .data .flags import FlagCodes
33
+ from musicscan .data .flags import AlbumFlagCodes , TrackFlagCodes
32
34
from musicscan .data .track import Track
33
35
34
36
@@ -42,11 +44,25 @@ def main_test(self, in_album: Album):
42
44
'''
43
45
Main album testing routine.
44
46
'''
47
+ self .album_tests (in_album )
48
+ self .track_tests (in_album )
49
+ self .album_closing_tests (in_album )
50
+
51
+ def album_tests (self , in_album : Album ):
52
+ '''
53
+ Perform tests against the album.
54
+ '''
45
55
self .check_album_values (in_album )
46
56
self .test_album_title (in_album )
47
57
self .test_album_artist (in_album )
48
58
self .test_soundtrack (in_album )
49
59
self .test_score (in_album )
60
+ self .test_tribute (in_album )
61
+
62
+ def track_tests (self , in_album : Album ):
63
+ '''
64
+ Perform tests against every track.
65
+ '''
50
66
for dsc in sorted (in_album .discs ):
51
67
for trk in sorted (in_album .discs [dsc ].tracks ,
52
68
key = lambda x : x .track_no ):
@@ -57,6 +73,15 @@ def main_test(self, in_album: Album):
57
73
self .test_track_genre (trk )
58
74
self .test_album_track_blank (trk )
59
75
self .test_album_track_bonus (trk )
76
+ self .test_album_track_intro (trk )
77
+ self .test_album_track_reprise (trk )
78
+
79
+ def album_closing_tests (self , in_album : Album ):
80
+ '''
81
+ Perform additional tests after all
82
+ tracks are analzed.
83
+ '''
84
+ self .test_intro_reprise_presence (in_album )
60
85
61
86
def check_album_values (self , in_album : Album ):
62
87
'''
@@ -65,7 +90,7 @@ def check_album_values(self, in_album: Album):
65
90
'''
66
91
if not in_album .title :
67
92
in_album .title = 'PLACEHOLDER ALBUM TITLE'
68
- in_album .flags .add_flag (FlagCodes .m_album_title )
93
+ in_album .flags .add_flag (TrackFlagCodes .m_album_title )
69
94
70
95
def check_track_values (self , in_track : Track ):
71
96
'''
@@ -74,7 +99,7 @@ def check_track_values(self, in_track: Track):
74
99
'''
75
100
if not in_track .artist :
76
101
in_track .artist = 'PLACEHOLDER TRACK ARTIST'
77
- in_track .flags .add_flag (FlagCodes .m_track_artist )
102
+ in_track .flags .add_flag (TrackFlagCodes .m_track_artist )
78
103
79
104
def test_album_title (self , in_album : Album ):
80
105
'''
@@ -84,9 +109,9 @@ def test_album_title(self, in_album: Album):
84
109
greatest_p = re .compile (r'Greatest' , re .IGNORECASE )
85
110
hits_p = re .compile (r'\s+Hit' , re .IGNORECASE )
86
111
if greatest_p .search (in_album .title ):
87
- in_album .flags .add_flag (FlagCodes .p_greatest )
112
+ in_album .flags .add_flag (AlbumFlagCodes .p_greatest )
88
113
if hits_p .search (in_album .title ):
89
- in_album .flags .add_flag (FlagCodes .p_hits_compo )
114
+ in_album .flags .add_flag (AlbumFlagCodes .p_hits_compo )
90
115
91
116
def test_soundtrack (self , in_album : Album ):
92
117
'''
@@ -96,10 +121,10 @@ def test_soundtrack(self, in_album: Album):
96
121
first_track = in_album .first_track ()
97
122
soundtrack_p = re .compile (r'\s+Soundtrack\s+' , re .IGNORECASE )
98
123
if soundtrack_p .search (in_album .title ):
99
- in_album .flags .add_flag (FlagCodes .p_soundtrack )
124
+ in_album .flags .add_flag (AlbumFlagCodes .p_soundtrack )
100
125
if first_track .genre == 'Soundtrack' :
101
- if FlagCodes .p_soundtrack not in in_album .flags .flags :
102
- in_album .flags .add_flag (FlagCodes .p_soundtrack )
126
+ if AlbumFlagCodes .p_soundtrack not in in_album .flags .flags :
127
+ in_album .flags .add_flag (AlbumFlagCodes .p_soundtrack )
103
128
104
129
def test_score (self , in_album : Album ):
105
130
'''
@@ -108,7 +133,16 @@ def test_score(self, in_album: Album):
108
133
'''
109
134
score_p = re .compile (r'\s+Score\s+' , re .IGNORECASE )
110
135
if score_p .search (in_album .title ):
111
- in_album .flags .add_flag (FlagCodes .p_score )
136
+ in_album .flags .add_flag (AlbumFlagCodes .p_score )
137
+
138
+ def test_tribute (self , in_album : Album ):
139
+ '''
140
+ Test if the album title suggests that it is a
141
+ tribute to another artist.
142
+ '''
143
+ tribute_p = re .compile (r'\s+Tribute\s+' , re .IGNORECASE )
144
+ if tribute_p .search (in_album .title ):
145
+ in_album .flags .add_flag (AlbumFlagCodes .p_tribute )
112
146
113
147
def test_album_artist (self , in_album : Album ):
114
148
'''
@@ -117,17 +151,17 @@ def test_album_artist(self, in_album: Album):
117
151
'''
118
152
and_p = re .compile (r'\s+and\s+' , re .IGNORECASE )
119
153
if and_p .search (str (in_album .artist )):
120
- in_album .flags .add_flag (FlagCodes .l_group )
154
+ in_album .flags .add_flag (TrackFlagCodes .l_group )
121
155
122
156
def test_album_track_chrs (self , in_track : Track ):
123
157
'''
124
158
Test the track title to indicate metadata may
125
159
have been embeded in the track name in parenthesis.
126
160
'''
127
161
if '[' in in_track .title or ']' in in_track .title :
128
- in_track .flags .add_flag (FlagCodes .d_sq_brackets )
162
+ in_track .flags .add_flag (TrackFlagCodes .d_sq_brackets )
129
163
if '(' in in_track .title or ')' in in_track .title :
130
- in_track .flags .add_flag (FlagCodes .d_parenthesis )
164
+ in_track .flags .add_flag (TrackFlagCodes .d_parenthesis )
131
165
132
166
def test_album_track_featured (self , in_track : Track ):
133
167
'''
@@ -137,9 +171,9 @@ def test_album_track_featured(self, in_track: Track):
137
171
feature_p = re .compile (r'Feat' , re .IGNORECASE )
138
172
with_p = re .compile (r'With\s+' , re .IGNORECASE )
139
173
if feature_p .search (in_track .title ) or with_p .search (in_track .title ):
140
- in_track .flags .add_flag (FlagCodes .p_feat_artist )
174
+ in_track .flags .add_flag (TrackFlagCodes .p_feat_artist )
141
175
if feature_p .search (in_track .artist ) or with_p .search (in_track .artist ):
142
- in_track .flags .add_flag (FlagCodes .p_feat_artist )
176
+ in_track .flags .add_flag (TrackFlagCodes .p_feat_artist )
143
177
144
178
def test_album_track_live (self , in_track : Track ):
145
179
'''
@@ -148,7 +182,7 @@ def test_album_track_live(self, in_track: Track):
148
182
'''
149
183
live_p = re .compile (r'Live\s+' , re .IGNORECASE )
150
184
if live_p .search (in_track .title ):
151
- in_track .flags .add_flag (FlagCodes .p_live )
185
+ in_track .flags .add_flag (TrackFlagCodes .p_live )
152
186
153
187
def test_track_genre (self , in_track : Track ):
154
188
'''
@@ -157,7 +191,7 @@ def test_track_genre(self, in_track: Track):
157
191
country_p = re .compile (r'Country & Folk' , re .IGNORECASE )
158
192
if in_track .genre :
159
193
if country_p .search (in_track .genre ):
160
- in_track .flags .add_flag (FlagCodes .p_genre_country_folk )
194
+ in_track .flags .add_flag (TrackFlagCodes .p_genre_country_folk )
161
195
162
196
def test_album_track_demo (self , in_track : Track ):
163
197
'''
@@ -166,7 +200,7 @@ def test_album_track_demo(self, in_track: Track):
166
200
'''
167
201
demo_p = re .compile (r'Demo' , re .IGNORECASE )
168
202
if demo_p .search (in_track .title ):
169
- in_track .flags .add_flag (FlagCodes .p_demo )
203
+ in_track .flags .add_flag (TrackFlagCodes .p_demo )
170
204
171
205
def test_album_track_blank (self , in_track : Track ):
172
206
'''
@@ -175,7 +209,7 @@ def test_album_track_blank(self, in_track: Track):
175
209
'''
176
210
blank_p = re .compile (r'Blank' , re .IGNORECASE )
177
211
if blank_p .search (in_track .title ):
178
- in_track .flags .add_flag (FlagCodes .p_blank_track )
212
+ in_track .flags .add_flag (TrackFlagCodes .p_blank_track )
179
213
180
214
def test_album_track_bonus (self , in_track : Track ):
181
215
'''
@@ -185,4 +219,42 @@ def test_album_track_bonus(self, in_track: Track):
185
219
'''
186
220
bonus_p = re .compile (r'\W+Bonus' , re .IGNORECASE )
187
221
if bonus_p .search (in_track .title ):
188
- in_track .flags .add_flag (FlagCodes .p_bonus_track )
222
+ in_track .flags .add_flag (TrackFlagCodes .p_bonus_track )
223
+
224
+ def test_album_track_intro (self , in_track : Track ):
225
+ '''
226
+ Test the track to see if it is an introduction to
227
+ another track, or possibly for the album itself.
228
+ '''
229
+ intro_p = re .compile (r'[\s\W]?Intro' , re .IGNORECASE )
230
+ if intro_p .search (in_track .title ):
231
+ in_track .flags .add_flag (TrackFlagCodes .p_intro )
232
+
233
+ def test_album_track_reprise (self , in_track : Track ):
234
+ '''
235
+ Test the track to see if it is labeled as a
236
+ reprise, either to the album, or to a previous
237
+ track on the album.
238
+ '''
239
+ reprise_p = re .compile (r'[\s\W]?Reprise' , re .IGNORECASE )
240
+ if reprise_p .search (in_track .title ):
241
+ in_track .flags .add_flag (TrackFlagCodes .p_reprise )
242
+
243
+ def test_intro_reprise_presence (self , in_album : Album ):
244
+ '''
245
+ Test to see if both an intro and reprise is
246
+ contained in the album, and add an additional
247
+ album level flag to identify it.
248
+ '''
249
+ reprise = False
250
+ intro = False
251
+ for dsc in sorted (in_album .discs ):
252
+ for trk in sorted (in_album .discs [dsc ].tracks ,
253
+ key = lambda x : x .track_no ):
254
+ if TrackFlagCodes .p_intro in trk .flags :
255
+ intro = True
256
+ if TrackFlagCodes .p_reprise in trk .flags :
257
+ reprise = True
258
+ if intro and reprise :
259
+ in_album .flags .add_flag (AlbumFlagCodes .p_intro_reprise )
260
+ break
0 commit comments