♻️ Refactored cover data method to Metadata.
This commit is contained in:
@@ -188,16 +188,6 @@ class Download:
|
|||||||
|
|
||||||
return f"https://resources.tidal.com/images/{sid.replace('-', '/')}/{int(width)}x{int(height)}.jpg"
|
return f"https://resources.tidal.com/images/{sid.replace('-', '/')}/{int(width)}x{int(height)}.jpg"
|
||||||
|
|
||||||
def cover_data(self, sid, width: int = 320, height: int = 320):
|
|
||||||
url = self.cover_url(sid, width, height)
|
|
||||||
|
|
||||||
try:
|
|
||||||
result: str = requests.get(url).content
|
|
||||||
except:
|
|
||||||
result: str = ""
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
def metadata_write(self, track: Track, path_file: str):
|
def metadata_write(self, track: Track, path_file: str):
|
||||||
result: bool = False
|
result: bool = False
|
||||||
release_date: str = track.album.release_date.strftime("%Y-%m-%d") if track.album.release_date else ""
|
release_date: str = track.album.release_date.strftime("%Y-%m-%d") if track.album.release_date else ""
|
||||||
|
|||||||
+19
-11
@@ -72,17 +72,8 @@ class Metadata:
|
|||||||
self.m: mutagen.MP4.MP4 | mutagen.m4a.M4A | mutagen.flac.FLAC | mutagen.mp3.MP3 = mutagen.File(self.path_file)
|
self.m: mutagen.MP4.MP4 | mutagen.m4a.M4A | mutagen.flac.FLAC | mutagen.mp3.MP3 = mutagen.File(self.path_file)
|
||||||
|
|
||||||
def _cover(self) -> bool:
|
def _cover(self) -> bool:
|
||||||
result = False
|
result: bool = False
|
||||||
data_cover = None
|
data_cover: str | bytes = self.cover_data(url=self.url_cover, path_file=self.path_cover)
|
||||||
|
|
||||||
if self.url_cover:
|
|
||||||
try:
|
|
||||||
data_cover = requests.get(self.url_cover).content
|
|
||||||
except:
|
|
||||||
data_cover = ""
|
|
||||||
elif self.path_cover:
|
|
||||||
with open(self.path_cover, "rb") as f:
|
|
||||||
data_cover = f.read()
|
|
||||||
|
|
||||||
if data_cover:
|
if data_cover:
|
||||||
if self.type_audio == "flac":
|
if self.type_audio == "flac":
|
||||||
@@ -161,3 +152,20 @@ class Metadata:
|
|||||||
self.m.tags["\xa9day"] = self.date
|
self.m.tags["\xa9day"] = self.date
|
||||||
self.m.tags["\xa9wrt"] = ", ".join(self.composer)
|
self.m.tags["\xa9wrt"] = ", ".join(self.composer)
|
||||||
self.m.tags["\xa9lyr"] = self.lyrics
|
self.m.tags["\xa9lyr"] = self.lyrics
|
||||||
|
|
||||||
|
def cover_data(self, url: str = None, path_file: str = None) -> str | bytes:
|
||||||
|
result: str | bytes = ""
|
||||||
|
|
||||||
|
if url:
|
||||||
|
try:
|
||||||
|
result = requests.get(url).content
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
elif path_file:
|
||||||
|
try:
|
||||||
|
with open(path_file, "rb") as f:
|
||||||
|
result = f.read()
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return result
|
||||||
|
|||||||
Reference in New Issue
Block a user