Code cleanup with pylint
This commit is contained in:
@ -7,8 +7,8 @@ from deemix.types.Picture import Picture
|
||||
from deemix.types import VARIOUS_ARTISTS
|
||||
|
||||
class Album:
|
||||
def __init__(self, id="0", title="", pic_md5=""):
|
||||
self.id = id
|
||||
def __init__(self, alb_id="0", title="", pic_md5=""):
|
||||
self.id = alb_id
|
||||
self.title = title
|
||||
self.pic = Picture(md5=pic_md5, type="cover")
|
||||
self.artist = {"Main": []}
|
||||
@ -24,11 +24,15 @@ class Album:
|
||||
self.genre = []
|
||||
self.barcode = "Unknown"
|
||||
self.label = "Unknown"
|
||||
self.copyright = None
|
||||
self.recordType = "album"
|
||||
self.bitrate = 0
|
||||
self.rootArtist = None
|
||||
self.variousArtists = None
|
||||
|
||||
self.playlistId = None
|
||||
self.owner = None
|
||||
|
||||
def parseAlbum(self, albumAPI):
|
||||
self.title = albumAPI['title']
|
||||
|
||||
@ -80,7 +84,7 @@ class Album:
|
||||
day = albumAPI["release_date"][8:10]
|
||||
month = albumAPI["release_date"][5:7]
|
||||
year = albumAPI["release_date"][0:4]
|
||||
self.date = Date(year, month, day)
|
||||
self.date = Date(day, month, year)
|
||||
|
||||
self.discTotal = albumAPI.get('nb_disk')
|
||||
self.copyright = albumAPI.get('copyright')
|
||||
@ -115,7 +119,7 @@ class Album:
|
||||
day = albumAPI_gw["PHYSICAL_RELEASE_DATE"][8:10]
|
||||
month = albumAPI_gw["PHYSICAL_RELEASE_DATE"][5:7]
|
||||
year = albumAPI_gw["PHYSICAL_RELEASE_DATE"][0:4]
|
||||
self.date = Date(year, month, day)
|
||||
self.date = Date(day, month, year)
|
||||
|
||||
def makePlaylistCompilation(self, playlist):
|
||||
self.variousArtists = playlist.variousArtists
|
||||
@ -136,8 +140,9 @@ class Album:
|
||||
self.pic = playlist.pic
|
||||
|
||||
def removeDuplicateArtists(self):
|
||||
"""Removes duplicate artists for both artist array and artists dict"""
|
||||
(self.artist, self.artists) = removeDuplicateArtists(self.artist, self.artists)
|
||||
|
||||
# Removes featuring from the album name
|
||||
def getCleanTitle(self):
|
||||
"""Removes featuring from the album name"""
|
||||
return removeFeatures(self.title)
|
||||
|
@ -2,8 +2,8 @@ from deemix.types.Picture import Picture
|
||||
from deemix.types import VARIOUS_ARTISTS
|
||||
|
||||
class Artist:
|
||||
def __init__(self, id="0", name="", role="", pic_md5=""):
|
||||
self.id = str(id)
|
||||
def __init__(self, art_id="0", name="", role="", pic_md5=""):
|
||||
self.id = str(art_id)
|
||||
self.name = name
|
||||
self.pic = Picture(md5=pic_md5, type="artist")
|
||||
self.role = role
|
||||
|
@ -1,4 +1,4 @@
|
||||
class Date(object):
|
||||
class Date:
|
||||
def __init__(self, day="00", month="00", year="XXXX"):
|
||||
self.year = year
|
||||
self.month = month
|
||||
|
@ -1,4 +1,5 @@
|
||||
class IDownloadObject:
|
||||
"""DownloadObject interface"""
|
||||
def __init__(self, obj):
|
||||
self.type = obj['type']
|
||||
self.id = obj['id']
|
||||
@ -50,9 +51,9 @@ class IDownloadObject:
|
||||
def getSlimmedDict(self):
|
||||
light = self.toDict()
|
||||
propertiesToDelete = ['single', 'collection', 'convertable']
|
||||
for property in propertiesToDelete:
|
||||
if property in light:
|
||||
del light[property]
|
||||
for prop in propertiesToDelete:
|
||||
if prop in light:
|
||||
del light[prop]
|
||||
return light
|
||||
|
||||
def updateProgress(self, interface=None):
|
||||
|
@ -1,6 +1,6 @@
|
||||
class Lyrics:
|
||||
def __init__(self, id="0"):
|
||||
self.id = id
|
||||
def __init__(self, lyr_id="0"):
|
||||
self.id = lyr_id
|
||||
self.sync = ""
|
||||
self.unsync = ""
|
||||
self.syncID3 = []
|
||||
@ -11,7 +11,7 @@ class Lyrics:
|
||||
syncLyricsJson = lyricsAPI["LYRICS_SYNC_JSON"]
|
||||
timestamp = ""
|
||||
milliseconds = 0
|
||||
for line in range(len(syncLyricsJson)):
|
||||
for line in enumerate(syncLyricsJson):
|
||||
if syncLyricsJson[line]["line"] != "":
|
||||
timestamp = syncLyricsJson[line]["lrc_timestamp"]
|
||||
milliseconds = int(syncLyricsJson[line]["milliseconds"])
|
||||
|
@ -1,25 +1,25 @@
|
||||
class Picture:
|
||||
def __init__(self, md5="", type="", url=None):
|
||||
def __init__(self, md5="", pic_type="", url=None):
|
||||
self.md5 = md5
|
||||
self.type = type
|
||||
self.type = pic_type
|
||||
self.staticUrl = url
|
||||
|
||||
def generatePictureURL(self, size, format):
|
||||
def generatePictureURL(self, size, pic_format):
|
||||
if self.staticUrl: return self.staticUrl
|
||||
|
||||
url = "https://e-cdns-images.dzcdn.net/images/{}/{}/{}x{}".format(
|
||||
url = "https://e-cdns-images.dzcdn.net/images/{}/{}/{size}x{size}".format(
|
||||
self.type,
|
||||
self.md5,
|
||||
size, size
|
||||
size=size
|
||||
)
|
||||
|
||||
if format.startswith("jpg"):
|
||||
if pic_format.startswith("jpg"):
|
||||
quality = 80
|
||||
if '-' in format:
|
||||
quality = format[4:]
|
||||
format = 'jpg'
|
||||
if '-' in pic_format:
|
||||
quality = pic_format[4:]
|
||||
pic_format = 'jpg'
|
||||
return url + f'-000000-{quality}-0-0.jpg'
|
||||
if format == 'png':
|
||||
if pic_format == 'png':
|
||||
return url + '-none-100-0-0.png'
|
||||
|
||||
return url+'.jpg'
|
||||
|
@ -32,7 +32,7 @@ class Playlist:
|
||||
md5 = url[url.find(picType+'/') + len(picType)+1:-24]
|
||||
self.pic = Picture(
|
||||
md5 = md5,
|
||||
type = picType
|
||||
pic_type = picType
|
||||
)
|
||||
else:
|
||||
self.pic = Picture(url = playlistAPI['picture_xl'])
|
||||
@ -41,7 +41,7 @@ class Playlist:
|
||||
pic_md5 = playlistAPI['various_artist']['picture_small']
|
||||
pic_md5 = pic_md5[pic_md5.find('artist/') + 7:-24]
|
||||
self.variousArtists = Artist(
|
||||
id = playlistAPI['various_artist']['id'],
|
||||
art_id = playlistAPI['various_artist']['id'],
|
||||
name = playlistAPI['various_artist']['name'],
|
||||
role = "Main",
|
||||
pic_md5 = pic_md5
|
||||
|
@ -1,5 +1,6 @@
|
||||
import requests
|
||||
from time import sleep
|
||||
import re
|
||||
import requests
|
||||
|
||||
from deezer.gw import GWAPIError
|
||||
from deezer.api import APIError
|
||||
@ -14,9 +15,11 @@ from deemix.types.Playlist import Playlist
|
||||
from deemix.types.Lyrics import Lyrics
|
||||
from deemix.types import VARIOUS_ARTISTS
|
||||
|
||||
from deemix.settings import FeaturesOption
|
||||
|
||||
class Track:
|
||||
def __init__(self, id="0", name=""):
|
||||
self.id = id
|
||||
def __init__(self, sng_id="0", name=""):
|
||||
self.id = sng_id
|
||||
self.title = name
|
||||
self.MD5 = ""
|
||||
self.mediaVersion = ""
|
||||
@ -82,9 +85,9 @@ class Track:
|
||||
result_json = site.json()
|
||||
except:
|
||||
sleep(2)
|
||||
return self.retriveFilesizes(dz)
|
||||
self.retriveFilesizes(dz)
|
||||
if len(result_json['error']):
|
||||
raise APIError(json.dumps(result_json['error']))
|
||||
raise APIError(result_json.dumps(result_json['error']))
|
||||
response = result_json.get("results")
|
||||
filesizes = {}
|
||||
for key, value in response.items():
|
||||
@ -116,7 +119,7 @@ class Track:
|
||||
|
||||
# Parse Album Data
|
||||
self.album = Album(
|
||||
id = trackAPI_gw['ALB_ID'],
|
||||
alb_id = trackAPI_gw['ALB_ID'],
|
||||
title = trackAPI_gw['ALB_TITLE'],
|
||||
pic_md5 = trackAPI_gw.get('ALB_PICTURE')
|
||||
)
|
||||
@ -157,7 +160,7 @@ class Track:
|
||||
if not len(self.artist['Main']):
|
||||
self.artist['Main'] = [self.mainArtist['name']]
|
||||
|
||||
self.singleDownload = trackAPI_gw.get('SINGLE_TRACK', False) # TODO: To change
|
||||
self.singleDownload = trackAPI_gw.get('SINGLE_TRACK', False) # TODO: Change
|
||||
self.position = trackAPI_gw.get('POSITION')
|
||||
|
||||
# Add playlist data if track is in a playlist
|
||||
@ -173,7 +176,7 @@ class Track:
|
||||
self.album = Album(title=trackAPI_gw['ALB_TITLE'])
|
||||
self.album.pic = Picture(
|
||||
md5 = trackAPI_gw.get('ALB_PICTURE', ""),
|
||||
type = "cover"
|
||||
pic_type = "cover"
|
||||
)
|
||||
self.mainArtist = Artist(name=trackAPI_gw['ART_NAME'])
|
||||
self.artists = [trackAPI_gw['ART_NAME']]
|
||||
@ -188,7 +191,7 @@ class Track:
|
||||
|
||||
def parseTrackGW(self, trackAPI_gw):
|
||||
self.title = trackAPI_gw['SNG_TITLE'].strip()
|
||||
if trackAPI_gw.get('VERSION') and not trackAPI_gw['VERSION'].strip() in this.title:
|
||||
if trackAPI_gw.get('VERSION') and not trackAPI_gw['VERSION'].strip() in self.title:
|
||||
self.title += f" {trackAPI_gw['VERSION'].strip()}"
|
||||
|
||||
self.discNumber = trackAPI_gw.get('DISK_NUMBER')
|
||||
@ -202,7 +205,7 @@ class Track:
|
||||
self.lyrics = Lyrics(trackAPI_gw.get('LYRICS_ID', "0"))
|
||||
|
||||
self.mainArtist = Artist(
|
||||
id = trackAPI_gw['ART_ID'],
|
||||
art_id = trackAPI_gw['ART_ID'],
|
||||
name = trackAPI_gw['ART_NAME'],
|
||||
pic_md5 = trackAPI_gw.get('ART_PICTURE')
|
||||
)
|
||||
@ -257,7 +260,6 @@ class Track:
|
||||
self.featArtistsString = "feat. "+andCommaConcat(self.artist['Featured'])
|
||||
|
||||
def applySettings(self, settings, TEMPDIR, embeddedImageFormat):
|
||||
from deemix.settings import FeaturesOption
|
||||
|
||||
# Check if should save the playlist as a compilation
|
||||
if self.playlist and settings['tags']['savePlaylistAsCompilation']:
|
||||
@ -269,7 +271,8 @@ class Track:
|
||||
ext = self.album.embeddedCoverURL[-4:]
|
||||
if ext[0] != ".": ext = ".jpg" # Check for Spotify images
|
||||
|
||||
self.album.embeddedCoverPath = TEMPDIR / f"pl{trackAPI_gw['_EXTRA_PLAYLIST']['id']}_{settings['embeddedArtworkSize']}{ext}"
|
||||
# TODO: FIX
|
||||
# self.album.embeddedCoverPath = TEMPDIR / f"pl{trackAPI_gw['_EXTRA_PLAYLIST']['id']}_{settings['embeddedArtworkSize']}{ext}"
|
||||
else:
|
||||
if self.album.date: self.date = self.album.date
|
||||
self.album.embeddedCoverURL = self.album.pic.generatePictureURL(settings['embeddedArtworkSize'], embeddedImageFormat)
|
||||
@ -290,7 +293,7 @@ class Track:
|
||||
self.album.artists.insert(0, artist.name)
|
||||
|
||||
if isMainArtist or artist.name not in self.album.artist['Main'] and not isMainArtist:
|
||||
if not artist.role in self.album.artist:
|
||||
if artist.role not in self.album.artist:
|
||||
self.album.artist[artist.role] = []
|
||||
self.album.artist[artist.role].insert(0, artist.name)
|
||||
self.album.mainArtist.save = not self.album.mainArtist.isVariousArtists() or settings['albumVariousArtists'] and self.album.mainArtist.isVariousArtists()
|
||||
@ -319,9 +322,9 @@ class Track:
|
||||
self.mainArtist.name = changeCase(self.mainArtist.name, settings['artistCasing'])
|
||||
for i, artist in enumerate(self.artists):
|
||||
self.artists[i] = changeCase(artist, settings['artistCasing'])
|
||||
for type in self.artist:
|
||||
for i, artist in enumerate(self.artist[type]):
|
||||
self.artist[type][i] = changeCase(artist, settings['artistCasing'])
|
||||
for art_type in self.artist:
|
||||
for i, artist in enumerate(self.artist[art_type]):
|
||||
self.artist[art_type][i] = changeCase(artist, settings['artistCasing'])
|
||||
self.generateMainFeatStrings()
|
||||
|
||||
# Generate artist tag
|
||||
@ -343,7 +346,6 @@ class Track:
|
||||
|
||||
class TrackError(Exception):
|
||||
"""Base class for exceptions in this module."""
|
||||
pass
|
||||
|
||||
class AlbumDoesntExists(TrackError):
|
||||
pass
|
||||
|
Reference in New Issue
Block a user