-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalbum.py
57 lines (44 loc) · 1.69 KB
/
album.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
import re
CSV_CAN_HANDLE_UTF8 = False
def removeUTF8Char(string):
if CSV_CAN_HANDLE_UTF8:
return string
else:
return re.sub(r'[^\x00-\x7f]', r'', string)
class Album():
attributeList = ['artist', 'title', 'rating', 'genre']
def __init__(self, videoSnippet, playlistGenre):
artist, title = '', ''
artistAndAlbum = videoSnippet['title'].replace("ALBUM REVIEW", "").split('-')
if len(artistAndAlbum) < 2:
artistAndAlbum = videoSnippet['title'].replace("ALBUM REVIEW", "").split('|')
try:
# remove any unicode char from artist and title
# so we can print the album in to a csv
artist = removeUTF8Char(artistAndAlbum[0].strip())
title = removeUTF8Char(artistAndAlbum[1].strip())
except IndexError:
artist = removeUTF8Char(artistAndAlbum[0].strip())
title = removeUTF8Char(artistAndAlbum[0].strip())
print('Error artist name and title are not parse-able:', artistAndAlbum)
rating = []
for line in videoSnippet['description'].split('\n'):
if len(score := re.findall('.*/10', line)) > 0:
rating = score
if len(rating) > 0:
rating = removeUTF8Char(rating[0])
else:
rating = 'NO SCORE'
self.artist = artist
self.title = title
self.rating = rating
self.genre = playlistGenre
return
def __str__(self):
return \
'Artist: ' + self.artist + \
'\nTitle: ' + self.title + \
'\nRating: ' + self.rating + \
'\nGenre: ' + self.genre
def getCsvRow(self):
return self.__dict__