From 0f733ceaaa1cb2c15d9718057860a53d1cf15d3c Mon Sep 17 00:00:00 2001 From: RemixDev Date: Sat, 13 Mar 2021 11:54:01 +0100 Subject: [PATCH] Some rework done on types --- deemix/types/Album.py | 17 ++++++++++------- deemix/types/Artist.py | 4 ++-- deemix/types/Date.py | 2 +- deemix/types/Lyrics.py | 8 +++----- deemix/types/Picture.py | 29 ++++++++++++++--------------- deemix/types/Playlist.py | 27 ++++++++++++++------------- 6 files changed, 44 insertions(+), 43 deletions(-) diff --git a/deemix/types/Album.py b/deemix/types/Album.py index a6472cb..2ac9015 100644 --- a/deemix/types/Album.py +++ b/deemix/types/Album.py @@ -14,19 +14,19 @@ class Album: self.artist = {"Main": []} self.artists = [] self.mainArtist = None - self.dateString = None - self.barcode = "Unknown" self.date = None + self.dateString = None + self.trackTotal = "0" self.discTotal = "0" self.embeddedCoverPath = None self.embeddedCoverURL = None self.explicit = False self.genre = [] + self.barcode = "Unknown" self.label = "Unknown" self.recordType = "album" - self.rootArtist = None - self.trackTotal = "0" self.bitrate = 0 + self.rootArtist = None self.variousArtists = None def parseAlbum(self, albumAPI): @@ -42,9 +42,12 @@ class Album: pic_md5 = artistPicture ) if albumAPI.get('root_artist'): + artistPicture = albumAPI['root_artist']['picture_small'] + artistPicture = artistPicture[artistPicture.find('artist/') + 7:-24] self.rootArtist = Artist( id = albumAPI['root_artist']['id'], - name = albumAPI['root_artist']['name'] + name = albumAPI['root_artist']['name'], + pic_md5 = artistPicture ) for artist in albumAPI['contributors']: @@ -82,7 +85,7 @@ class Album: self.discTotal = albumAPI.get('nb_disk') self.copyright = albumAPI.get('copyright') - if not self.pic.md5: + if self.pic.md5 == "": # Getting album cover MD5 # ex: https://e-cdns-images.dzcdn.net/images/cover/2e018122cb56986277102d2041a592c8/56x56-000000-80-0-0.jpg self.pic.md5 = albumAPI['cover_small'][albumAPI['cover_small'].find('cover/') + 6:-24] @@ -106,7 +109,7 @@ class Album: explicitLyricsStatus = albumAPI_gw.get('EXPLICIT_ALBUM_CONTENT', {}).get('EXPLICIT_LYRICS_STATUS', LyricsStatus.UNKNOWN) self.explicit = explicitLyricsStatus in [LyricsStatus.EXPLICIT, LyricsStatus.PARTIALLY_EXPLICIT] - if not self.pic.md5: + if self.pic.md5 == "": self.pic.md5 = albumAPI_gw['ALB_PICTURE'] if 'PHYSICAL_RELEASE_DATE' in albumAPI_gw: day = albumAPI_gw["PHYSICAL_RELEASE_DATE"][8:10] diff --git a/deemix/types/Artist.py b/deemix/types/Artist.py index 42cb573..cfc49c4 100644 --- a/deemix/types/Artist.py +++ b/deemix/types/Artist.py @@ -2,11 +2,11 @@ from deemix.types.Picture import Picture from deemix import VARIOUS_ARTISTS class Artist: - def __init__(self, id="0", name="", pic_md5="", role=""): + def __init__(self, id="0", name="", role="", pic_md5=""): self.id = str(id) self.name = name self.pic = Picture(md5=pic_md5, type="artist") - self.role = "" + self.role = role self.save = True def isVariousArtists(self): diff --git a/deemix/types/Date.py b/deemix/types/Date.py index b74e04f..061f2eb 100644 --- a/deemix/types/Date.py +++ b/deemix/types/Date.py @@ -1,5 +1,5 @@ class Date(object): - def __init__(self, year="XXXX", month="00", day="00"): + def __init__(self, day="00", month="00", year="XXXX"): self.year = year self.month = month self.day = day diff --git a/deemix/types/Lyrics.py b/deemix/types/Lyrics.py index a21beb1..8a02a4c 100644 --- a/deemix/types/Lyrics.py +++ b/deemix/types/Lyrics.py @@ -1,16 +1,14 @@ class Lyrics: def __init__(self, id="0"): self.id = id - self.sync = None - self.unsync = None - self.syncID3 = None + self.sync = "" + self.unsync = "" + self.syncID3 = [] def parseLyrics(self, lyricsAPI): self.unsync = lyricsAPI.get("LYRICS_TEXT") if "LYRICS_SYNC_JSON" in lyricsAPI: syncLyricsJson = lyricsAPI["LYRICS_SYNC_JSON"] - self.sync = "" - self.syncID3 = [] timestamp = "" milliseconds = 0 for line in range(len(syncLyricsJson)): diff --git a/deemix/types/Picture.py b/deemix/types/Picture.py index ca00f49..6cf3d99 100644 --- a/deemix/types/Picture.py +++ b/deemix/types/Picture.py @@ -1,27 +1,26 @@ class Picture: - def __init__(self, md5="", type=None, url=None): + def __init__(self, md5="", type="", url=None): self.md5 = md5 self.type = type - self.url = url + self.staticUrl = url def generatePictureURL(self, size, format): - if self.url: return self.url + if self.staticUrl: return self.staticUrl + + url = "https://e-cdns-images.dzcdn.net/images/{}/{}/{}x{}".format( + self.type, + self.md5, + size, size + ) + if format.startswith("jpg"): if '-' in format: quality = format[4:] else: quality = 80 format = 'jpg' - return "https://e-cdns-images.dzcdn.net/images/{}/{}/{}x{}-{}".format( - self.type, - self.md5, - size, size, - f'000000-{quality}-0-0.jpg' - ) + return url + f'-000000-{quality}-0-0.jpg' if format == 'png': - return "https://e-cdns-images.dzcdn.net/images/{}/{}/{}x{}-{}".format( - self.type, - self.md5, - size, size, - 'none-100-0-0.png' - ) + return url + '-none-100-0-0.png' + + return url+'.jpg' diff --git a/deemix/types/Playlist.py b/deemix/types/Playlist.py index 9625719..e358674 100644 --- a/deemix/types/Playlist.py +++ b/deemix/types/Playlist.py @@ -4,17 +4,6 @@ from deemix.types.Picture import Picture class Playlist: def __init__(self, playlistAPI): - if 'various_artist' in playlistAPI: - playlistAPI['various_artist']['role'] = "Main" - self.variousArtists = Artist( - id = playlistAPI['various_artist']['id'], - name = playlistAPI['various_artist']['name'], - pic_md5 = playlistAPI['various_artist']['picture_small'][ - playlistAPI['various_artist']['picture_small'].find('artist/') + 7:-24], - role = playlistAPI['various_artist']['role'] - ) - self.mainArtist = self.variousArtists - self.id = "pl_" + str(playlistAPI['id']) self.title = playlistAPI['title'] self.rootArtist = None @@ -30,11 +19,12 @@ class Playlist: year = playlistAPI["creation_date"][0:4] month = playlistAPI["creation_date"][5:7] day = playlistAPI["creation_date"][8:10] - self.date = Date(year, month, day) + self.date = Date(day, month, year) self.discTotal = "1" - self.playlistId = playlistAPI['id'] + self.playlistID = playlistAPI['id'] self.owner = playlistAPI['creator'] + if 'dzcdn.net' in playlistAPI['picture_small']: url = playlistAPI['picture_small'] picType = url[url.find('images/')+7:] @@ -46,3 +36,14 @@ class Playlist: ) else: self.pic = Picture(url = playlistAPI['picture_xl']) + + if 'various_artist' in playlistAPI: + pic_md5 = playlistAPI['various_artist']['picture_small'] + pic_md5 = pic_md5[pic_md5.indexOf('artist/') + 7:-24] + self.variousArtists = Artist( + id = playlistAPI['various_artist']['id'], + name = playlistAPI['various_artist']['name'], + role = "Main", + pic_md5 = pic_md5 + ) + self.mainArtist = self.variousArtists