-
Notifications
You must be signed in to change notification settings - Fork 3
/
Track.py
38 lines (29 loc) · 943 Bytes
/
Track.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
import requests
import logging
from dataclasses import dataclass
from pathlib import Path
from os.path import expanduser
@dataclass
class Track:
title: str
artist: str
album: str
length: str
artworkURL: str
uniqueId: str
ignore: bool
def fetchArtwork(self, coverImagePath):
logger = logging.getLogger("track base class")
p = Path(f'{expanduser(coverImagePath)}/{self.uniqueId}.jpg')
if(p.is_file() == False):
with p.open(mode='wb') as handle:
response = requests.get(self.artworkURL, stream=True)
if not response.ok:
return False
for block in response.iter_content(1024):
if not block:
return False
handle.write(block)
else:
logger.debug("Artwork file already exists. Skipping")
return str(p)