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