1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
|
3
|
1 |
|
import pytest |
4
|
1 |
|
|
5
|
1 |
|
from music_album_creation.audio_segmentation import Timestamp |
6
|
1 |
|
from music_album_creation.audio_segmentation.data import to_timestamps_info |
7
|
|
|
from music_album_creation.tracks_parsing import StringParser |
8
|
|
|
|
9
|
1 |
|
|
10
|
|
|
@pytest.fixture(scope='module') |
11
|
1 |
|
def track_durations(): |
12
|
|
|
return ["0:12", "0:38", "0:20", "0:25", "0:10", "0:30", "1:00"] |
13
|
|
|
|
14
|
1 |
|
|
15
|
|
|
@pytest.fixture(scope='module') |
16
|
1 |
|
def track_timestamps(): |
17
|
|
|
return ["0:00", "0:12", "0:50", "1:10", "1:35", "1:45", "2:15"] |
18
|
1 |
|
|
19
|
|
|
|
20
|
1 |
|
@pytest.fixture(scope='module') |
21
|
|
|
def delimeters1(): |
22
|
|
|
return ['. ', ' - ', '. ', ' - ', '. '] |
23
|
|
|
|
24
|
1 |
|
|
25
|
|
|
# TODO make sure that all track_names are tested regardless of their order |
26
|
1 |
|
@pytest.fixture(scope='module') |
27
|
|
|
def track_names(): |
28
|
|
|
return [ |
29
|
|
|
'a,b', |
30
|
|
|
'SOS: edw', |
31
|
|
|
'Delta-v', |
32
|
|
|
'Uber en Colère', |
33
|
|
|
# 'Ζόμπι, το Ξύπνημα των Νεκρών', |
34
|
|
|
'Ζόμπι', |
35
|
|
|
"Bowie’s Last Breath", |
36
|
|
|
"I’m Not A Real Indian (But I Play One On TV)", |
37
|
|
|
'24', |
38
|
|
|
'Στενές Επαφές Τρίτου Τύπου (Disco Tsoutsouni)', |
39
|
|
|
'SOS: Πεντάγωνο καλεί Μόσχα (Νύχτες της Μόσχας)', |
40
|
|
|
'Οικογενειακή Συνωμοσία', |
41
|
1 |
|
] |
42
|
|
|
|
43
|
1 |
|
|
44
|
|
|
@pytest.fixture(scope='module') |
45
|
1 |
|
def delimeters2(): |
46
|
|
|
return [' ', ' - ', ' - ', ' - ', ' - '] |
47
|
1 |
|
|
48
|
|
|
|
49
|
1 |
|
@pytest.fixture(scope='module') |
50
|
|
|
def timestamps_info_string(delimeters1, track_names, delimeters2, track_timestamps): |
51
|
1 |
|
return build_string(delimeters1, track_names, delimeters2, track_timestamps) |
52
|
|
|
|
53
|
|
|
|
54
|
1 |
|
@pytest.fixture(scope='module') |
55
|
1 |
|
def durations_info_string(delimeters1, track_names, delimeters2, track_durations): |
56
|
|
|
return build_string(delimeters1, track_names, delimeters2, track_durations) + '\n' |
57
|
|
|
|
58
|
1 |
|
|
59
|
|
|
def build_string(dels1, names, dels2, hhmmss_list): |
60
|
1 |
|
return '\n'.join( |
61
|
1 |
|
[ |
62
|
|
|
'{}{}{}{}{}'.format( |
63
|
1 |
|
i + 1, dels1[i % len(dels1)], x[0], dels2[i % len(dels2)], x[1] |
64
|
1 |
|
) |
65
|
|
|
for i, x in enumerate(zip(names, hhmmss_list)) |
66
|
1 |
|
] |
67
|
1 |
|
) |
68
|
|
|
|
69
|
1 |
|
|
70
|
1 |
|
class TestSplitters: |
71
|
|
|
def test_parsing_timestamps_tracks_info( |
72
|
1 |
|
self, timestamps_info_string, track_names, track_timestamps |
73
|
|
|
): |
74
|
|
|
assert StringParser().parse_hhmmss_string(timestamps_info_string) == [ |
75
|
|
|
[x, y] for x, y in zip(track_names, track_timestamps) |
76
|
|
|
] |
77
|
|
|
|
78
|
|
|
def test_parsing_durations_tracks_info( |
79
|
1 |
|
self, durations_info_string, track_names, track_durations |
80
|
|
|
): |
81
|
1 |
|
assert StringParser().parse_hhmmss_string(durations_info_string) == [ |
82
|
|
|
[x, y] for x, y in zip(track_names, track_durations) |
83
|
|
|
] |
84
|
|
|
|
85
|
|
|
def test_durations_list_converion(self, track_durations, track_timestamps): |
86
|
|
|
assert [ |
87
|
|
|
int(Timestamp(_[1])) |
88
|
|
|
for _ in to_timestamps_info([['a', x] for x in track_durations]) |
89
|
|
|
] == [int(Timestamp(_)) for _ in track_timestamps] |
90
|
|
|
|
91
|
|
|
def test_convert_to_timestamps(self, durations_info_string, track_timestamps, track_names): |
92
|
|
|
assert list( |
93
|
|
|
map(Timestamp, StringParser().convert_to_timestamps(durations_info_string)) |
94
|
|
|
) == list(map(Timestamp, track_timestamps[: len(track_names)])) |
95
|
|
|
|
96
|
|
|
@pytest.mark.parametrize( |
97
|
|
|
"video_title, artist, album, year", |
98
|
|
|
[ |
99
|
|
|
( |
100
|
|
|
"Alber Jupiter - We Are Just Floating In Space (2019) (New Full Album)", |
101
|
|
|
"Alber Jupiter", |
102
|
1 |
|
"We Are Just Floating In Space", |
103
|
|
|
"2019", |
104
|
|
|
), |
105
|
1 |
|
("My Artist - My Album (2001)", "My Artist", "My Album", "2001"), |
106
|
1 |
|
("Composer A - Metro 2033 (2010)", "Composer A", "Metro 2033", "2010"), |
107
|
1 |
|
], |
108
|
1 |
|
) |
109
|
1 |
|
def test_youtube_video_title_parsing(self, video_title, artist, album, year): |
110
|
1 |
|
assert StringParser().parse_album_info(video_title) == { |
111
|
1 |
|
'artist': artist, |
112
|
1 |
|
'album': album, |
113
|
1 |
|
'year': year, |
114
|
|
|
} |
115
|
1 |
|
|
116
|
|
|
@pytest.mark.parametrize( |
117
|
|
|
"track_file, track_number, track_name", |
118
|
|
|
[ |
119
|
|
|
( |
120
|
|
|
"Thievery Corporation/The Cosmic Game (2005)/14 - The Supreme Illusion (Feat- Gunjan).mp3", |
121
|
|
|
'14', |
122
|
|
|
'The Supreme Illusion (Feat- Gunjan)', |
123
|
|
|
), |
124
|
|
|
( |
125
|
|
|
"Monster Magnet/Dopes to Infinity (Single) 1995/02 - Forbidden Planet.mp3", |
126
|
|
|
'02', |
127
|
|
|
'Forbidden Planet', |
128
|
|
|
), |
129
|
|
|
("Monster Magnet/Greatest Hits 2003/02 - Medicine.mp3", '02', 'Medicine'), |
130
|
|
|
( |
131
|
|
|
"Porcupine Tree/On The Sunday Of Life/07 - Message Form A Self-Destructing Turnip.mp3", |
132
|
|
|
'07', |
133
|
|
|
'Message Form A Self-Destructing Turnip', |
134
|
|
|
), |
135
|
|
|
("Rotor/Rotor 2001/06 A Madrugada.mp3", '06', 'A Madrugada'), |
136
|
|
|
("Karma To Burn/Arc Stanton 2014/02 56.mp3", '02', '56'), |
137
|
|
|
( |
138
|
|
|
"Cesaria Evora/Cesaria Evora - Cabo Verde/06-Mar e Morada De Sodade.mp3", |
139
|
|
|
'06', |
140
|
|
|
'Mar e Morada De Sodade', |
141
|
|
|
), |
142
|
|
|
("Sungrazer/Sungrazer - Mirador (2011)/06.Mirador.mp3", '06', 'Mirador'), |
143
|
|
|
( |
144
|
|
|
"SadhuS (The Smoking Community)/Sadhus The smoking community/06 Bampoola.mp3", |
145
|
|
|
'06', |
146
|
|
|
'Bampoola', |
147
|
|
|
), |
148
|
|
|
( |
149
|
|
|
"Remember Me - Original Soundtrack (2013)/12. The Ego Room.mp3", |
150
|
|
|
'12', |
151
|
|
|
'The Ego Room', |
152
|
|
|
), |
153
|
|
|
( |
154
|
|
|
"Queens of the Stone Age/Like a Clockwork/02 I Sat By the Ocean.mp3", |
155
|
|
|
'02', |
156
|
|
|
'I Sat By the Ocean', |
157
|
|
|
), |
158
|
|
|
("Ill Nino/[2010] Dead New World/05 - Bleed Like You.mp3", '05', 'Bleed Like You'), |
159
|
|
|
( |
160
|
|
|
"Urban Dance Squad/Urban Dance Squad - Life 'n Perspectives of a Genuine Crossover/03. Life 'n Perspectives I.mp3", |
161
|
|
|
'03', |
162
|
|
|
"Life 'n Perspectives I", |
163
|
|
|
), |
164
|
|
|
( |
165
|
|
|
"Cesaria Evora/Cesaria Evora - Cafe Atlantico/06-Carnaval De Sao Vicente.mp3", |
166
|
|
|
'06', |
167
|
|
|
'Carnaval De Sao Vicente', |
168
|
|
|
), |
169
|
|
|
("Dala Sun/Sala Dun (2010)/04 - Fuck It Away.mp3", '04', 'Fuck It Away'), |
170
|
|
|
("In This Moment/Blood (2012)/01- Rise With Me.mp3", '01', 'Rise With Me'), |
171
|
|
|
], |
172
|
|
|
) |
173
|
|
|
def test_mp3_files_parsing(self, track_file, track_number, track_name): |
174
|
|
|
assert StringParser().parse_track_number_n_name(track_file) == { |
175
|
|
|
'track_number': track_number, |
176
|
|
|
'track_name': track_name, |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
|
180
|
|
|
def test_timestamp(): |
181
|
|
|
assert Timestamp('45:17') <= Timestamp('50:00') and Timestamp('0:0:34') < Timestamp('1:34') |
182
|
|
|
assert Timestamp('1:0:34') >= Timestamp('56:36') and Timestamp('1:1:34') > Timestamp('0:4') |
183
|
|
|
assert Timestamp('12') == Timestamp('0:12') == Timestamp('00:0:12') == Timestamp('00:12') |
184
|
|
|
assert ( |
185
|
|
|
Timestamp('9') |
186
|
|
|
== Timestamp('0:09') |
187
|
|
|
== Timestamp('09') |
188
|
|
|
== Timestamp('00:09') |
189
|
|
|
== Timestamp('00:9') |
190
|
|
|
) |
191
|
|
|
assert ( |
192
|
|
|
Timestamp('0:0:9') |
193
|
|
|
== Timestamp('0:0:09') |
194
|
|
|
== Timestamp('00:0:09') |
195
|
|
|
== Timestamp('0:0:09') |
196
|
|
|
== Timestamp('09') |
197
|
|
|
) |
198
|
|
|
assert ( |
199
|
|
|
hash(Timestamp('12')) |
200
|
|
|
== hash(Timestamp('0:12')) |
201
|
|
|
== hash(Timestamp('00:0:12')) |
202
|
|
|
== hash(Timestamp('00:12')) |
203
|
|
|
) |
204
|
|
|
assert ( |
205
|
|
|
hash(Timestamp('9')) |
206
|
|
|
== hash(Timestamp('0:09')) |
207
|
|
|
== hash(Timestamp('09')) |
208
|
|
|
== hash(Timestamp('00:09')) |
209
|
|
|
== hash(Timestamp('00:9')) |
210
|
|
|
) |
211
|
|
|
assert ( |
212
|
|
|
hash(Timestamp('0:0:9')) |
213
|
|
|
== hash(Timestamp('0:0:09')) |
214
|
|
|
== hash(Timestamp('00:0:09')) |
215
|
|
|
== hash(Timestamp('0:0:09')) |
216
|
|
|
== hash(Timestamp('09')) |
217
|
|
|
) |
218
|
|
|
|
219
|
|
|
assert int(Timestamp('23:57') - Timestamp('16:43')) == 434 |
220
|
|
|
|