v0.1
This commit is contained in:
30
nporadio2/radiotrack.py
Normal file
30
nporadio2/radiotrack.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from typing import Optional
|
||||
import requests
|
||||
import tempfile
|
||||
|
||||
|
||||
class RadioTrack:
|
||||
def __init__(self, data: dict) -> None:
|
||||
self.artist = data["artist"]
|
||||
self.title = data["name"]
|
||||
self.cover = data["cover_url"]
|
||||
self.cover_path: Optional[str] = None
|
||||
|
||||
def save_image(self):
|
||||
r = requests.get(self.cover)
|
||||
|
||||
if r.status_code == 200:
|
||||
with tempfile.NamedTemporaryFile("wb", suffix=".jpg", delete=False) as f:
|
||||
f.write(r.content)
|
||||
self.cover_path = f.name
|
||||
else:
|
||||
print(r.status_code)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.artist} - {self.title}"
|
||||
|
||||
def __eq__(self, other: object) -> bool:
|
||||
if isinstance(other, RadioTrack):
|
||||
return self.title == other.title and self.artist == other.artist
|
||||
|
||||
return False
|
||||
Reference in New Issue
Block a user