Showing
1 changed file
with
33 additions
and
0 deletions
src/song.py
0 → 100644
1 | +import requests, re | ||
2 | +from io import BytesIO | ||
3 | +from PIL import Image | ||
4 | +import numpy as np | ||
5 | + | ||
6 | +class Song: | ||
7 | + def __init__(self): | ||
8 | + self.year = 0 | ||
9 | + self.month = 0 | ||
10 | + self.rank = 0 | ||
11 | + self.title = '' | ||
12 | + self.singer = '' | ||
13 | + self.album = '' | ||
14 | + self.genre = '' | ||
15 | + self.date = '' | ||
16 | + self.likes = 0 | ||
17 | + self.lyrics = '' | ||
18 | + self.keywords = [] | ||
19 | + | ||
20 | + def setImage(self, url): | ||
21 | + res = requests.get(url) | ||
22 | + self.img = Image.open(BytesIO(res.content)) | ||
23 | + | ||
24 | + def getRow(self): | ||
25 | + self.title.strip() | ||
26 | + self.album = re.sub(r"[?'/\"*<>:]", "", self.album) | ||
27 | + try: | ||
28 | + return [self.year, self.month, self.rank, self.title, self.singer, self.album, self.genre, self.date, self.likes, self.keywords] | ||
29 | + except: | ||
30 | + return [self.year, self.month, self.rank, self.title, self.singer, self.album, self.genre, self.date, self.likes, []] | ||
31 | + | ||
32 | + def saveImg(self): | ||
33 | + self.img.save('./images/' + self.album + '.jpg') | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment