Total rework of the library (WIP)
This commit is contained in:
@ -4,7 +4,7 @@ from deemix.utils import removeDuplicateArtists, removeFeatures
|
||||
from deemix.types.Artist import Artist
|
||||
from deemix.types.Date import Date
|
||||
from deemix.types.Picture import Picture
|
||||
from deemix import VARIOUS_ARTISTS
|
||||
from deemix.types import VARIOUS_ARTISTS
|
||||
|
||||
class Album:
|
||||
def __init__(self, id="0", title="", pic_md5=""):
|
||||
|
@ -1,5 +1,5 @@
|
||||
from deemix.types.Picture import Picture
|
||||
from deemix import VARIOUS_ARTISTS
|
||||
from deemix.types import VARIOUS_ARTISTS
|
||||
|
||||
class Artist:
|
||||
def __init__(self, id="0", name="", role="", pic_md5=""):
|
||||
|
126
deemix/types/DownloadObjects.py
Normal file
126
deemix/types/DownloadObjects.py
Normal file
@ -0,0 +1,126 @@
|
||||
class IDownloadObject:
|
||||
def __init__(self, type=None, id=None, bitrate=None, title=None, artist=None, cover=None, explicit=False, size=None, dictItem=None):
|
||||
if dictItem:
|
||||
self.type = dictItem['type']
|
||||
self.id = dictItem['id']
|
||||
self.bitrate = dictItem['bitrate']
|
||||
self.title = dictItem['title']
|
||||
self.artist = dictItem['artist']
|
||||
self.cover = dictItem['cover']
|
||||
self.explicit = dictItem.get('explicit', False)
|
||||
self.size = dictItem['size']
|
||||
self.downloaded = dictItem['downloaded']
|
||||
self.failed = dictItem['failed']
|
||||
self.progress = dictItem['progress']
|
||||
self.errors = dictItem['errors']
|
||||
self.files = dictItem['files']
|
||||
else:
|
||||
self.type = type
|
||||
self.id = id
|
||||
self.bitrate = bitrate
|
||||
self.title = title
|
||||
self.artist = artist
|
||||
self.cover = cover
|
||||
self.explicit = explicit
|
||||
self.size = size
|
||||
self.downloaded = 0
|
||||
self.failed = 0
|
||||
self.progress = 0
|
||||
self.errors = []
|
||||
self.files = []
|
||||
self.uuid = f"{self.type}_{self.id}_{self.bitrate}"
|
||||
self.ack = None
|
||||
self.__type__ = None
|
||||
|
||||
def toDict(self):
|
||||
return {
|
||||
'type': self.type,
|
||||
'id': self.id,
|
||||
'bitrate': self.bitrate,
|
||||
'uuid': self.uuid,
|
||||
'title': self.title,
|
||||
'artist': self.artist,
|
||||
'cover': self.cover,
|
||||
'explicit': self.explicit,
|
||||
'size': self.size,
|
||||
'downloaded': self.downloaded,
|
||||
'failed': self.failed,
|
||||
'progress': self.progress,
|
||||
'errors': self.errors,
|
||||
'files': self.files,
|
||||
'ack': self.ack,
|
||||
'__type__': self.__type__
|
||||
}
|
||||
|
||||
def getResettedDict(self):
|
||||
item = self.toDict()
|
||||
item['downloaded'] = 0
|
||||
item['failed'] = 0
|
||||
item['progress'] = 0
|
||||
item['errors'] = []
|
||||
item['files'] = []
|
||||
return item
|
||||
|
||||
def getSlimmedDict(self):
|
||||
light = self.toDict()
|
||||
propertiesToDelete = ['single', 'collection', 'convertable']
|
||||
for property in propertiesToDelete:
|
||||
if property in light:
|
||||
del light[property]
|
||||
return light
|
||||
|
||||
class Single(IDownloadObject):
|
||||
def __init__(self, type=None, id=None, bitrate=None, title=None, artist=None, cover=None, explicit=False, trackAPI_gw=None, trackAPI=None, albumAPI=None, dictItem=None):
|
||||
if dictItem:
|
||||
super().__init__(dictItem=dictItem)
|
||||
self.single = dictItem['single']
|
||||
else:
|
||||
super().__init__(type, id, bitrate, title, artist, cover, explicit, 1)
|
||||
self.single = {
|
||||
'trackAPI_gw': trackAPI_gw,
|
||||
'trackAPI': trackAPI,
|
||||
'albumAPI': albumAPI
|
||||
}
|
||||
self.__type__ = "Single"
|
||||
|
||||
def toDict(self):
|
||||
item = super().toDict()
|
||||
item['single'] = self.single
|
||||
return item
|
||||
|
||||
class Collection(IDownloadObject):
|
||||
def __init__(self, type=None, id=None, bitrate=None, title=None, artist=None, cover=None, explicit=False, size=None, tracks_gw=None, albumAPI=None, playlistAPI=None, dictItem=None):
|
||||
if dictItem:
|
||||
super().__init__(dictItem=dictItem)
|
||||
self.collection = dictItem['collection']
|
||||
else:
|
||||
super().__init__(type, id, bitrate, title, artist, cover, explicit, size)
|
||||
self.collection = {
|
||||
'tracks_gw': tracks_gw,
|
||||
'albumAPI': albumAPI,
|
||||
'playlistAPI': playlistAPI
|
||||
}
|
||||
self.__type__ = "Collection"
|
||||
|
||||
def toDict(self):
|
||||
item = super().toDict()
|
||||
item['collection'] = self.collection
|
||||
return item
|
||||
|
||||
class Convertable(Collection):
|
||||
def __init__(self, type=None, id=None, bitrate=None, title=None, artist=None, cover=None, explicit=False, size=None, plugin=None, conversion_data=None, dictItem=None):
|
||||
if dictItem:
|
||||
super().__init__(dictItem=dictItem)
|
||||
self.plugin = dictItem['plugin']
|
||||
self.conversion_data = dictItem['conversion_data']
|
||||
else:
|
||||
super().__init__(type, id, bitrate, title, artist, cover, explicit, size)
|
||||
self.plugin = plugin
|
||||
self.conversion_data = conversion_data
|
||||
self.__type__ = "Convertable"
|
||||
|
||||
def toDict(self):
|
||||
item = super().toDict()
|
||||
item['plugin'] = self.plugin
|
||||
item['conversion_data'] = self.conversion_data
|
||||
return item
|
@ -14,7 +14,7 @@ from deemix.types.Date import Date
|
||||
from deemix.types.Picture import Picture
|
||||
from deemix.types.Playlist import Playlist
|
||||
from deemix.types.Lyrics import Lyrics
|
||||
from deemix import VARIOUS_ARTISTS
|
||||
from deemix.types import VARIOUS_ARTISTS
|
||||
|
||||
class Track:
|
||||
def __init__(self, id="0", name=""):
|
||||
@ -259,6 +259,91 @@ class Track:
|
||||
if 'Featured' in self.artist:
|
||||
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']:
|
||||
self.trackNumber = self.position
|
||||
self.discNumber = "1"
|
||||
self.album.makePlaylistCompilation(self.playlist)
|
||||
self.album.embeddedCoverURL = self.playlist.pic.generatePictureURL(settings['embeddedArtworkSize'], embeddedImageFormat)
|
||||
|
||||
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}"
|
||||
else:
|
||||
if self.album.date: self.date = self.album.date
|
||||
self.album.embeddedCoverURL = self.album.pic.generatePictureURL(settings['embeddedArtworkSize'], embeddedImageFormat)
|
||||
|
||||
ext = self.album.embeddedCoverURL[-4:]
|
||||
self.album.embeddedCoverPath = TEMPDIR / f"alb{self.album.id}_{settings['embeddedArtworkSize']}{ext}"
|
||||
|
||||
self.dateString = self.date.format(settings['dateFormat'])
|
||||
self.album.dateString = self.album.date.format(settings['dateFormat'])
|
||||
if self.playlist: self.playlist.dateString = self.playlist.date.format(settings['dateFormat'])
|
||||
|
||||
# Check various artist option
|
||||
if settings['albumVariousArtists'] and self.album.variousArtists:
|
||||
artist = self.album.variousArtists
|
||||
isMainArtist = artist.role == "Main"
|
||||
|
||||
if artist.name not in self.album.artists:
|
||||
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:
|
||||
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()
|
||||
|
||||
# Check removeDuplicateArtists
|
||||
if settings['removeDuplicateArtists']: self.removeDuplicateArtists()
|
||||
|
||||
# Check if user wants the feat in the title
|
||||
if str(settings['featuredToTitle']) == FeaturesOption.REMOVE_TITLE:
|
||||
self.title = self.getCleanTitle()
|
||||
elif str(settings['featuredToTitle']) == FeaturesOption.MOVE_TITLE:
|
||||
self.title = self.getFeatTitle()
|
||||
elif str(settings['featuredToTitle']) == FeaturesOption.REMOVE_TITLE_ALBUM:
|
||||
self.title = self.getCleanTitle()
|
||||
self.album.title = self.album.getCleanTitle()
|
||||
|
||||
# Remove (Album Version) from tracks that have that
|
||||
if settings['removeAlbumVersion']:
|
||||
if "Album Version" in self.title:
|
||||
self.title = re.sub(r' ?\(Album Version\)', "", self.title).strip()
|
||||
|
||||
# Change Title and Artists casing if needed
|
||||
if settings['titleCasing'] != "nothing":
|
||||
self.title = changeCase(self.title, settings['titleCasing'])
|
||||
if settings['artistCasing'] != "nothing":
|
||||
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'])
|
||||
self.generateMainFeatStrings()
|
||||
|
||||
# Generate artist tag
|
||||
if settings['tags']['multiArtistSeparator'] == "default":
|
||||
if str(settings['featuredToTitle']) == FeaturesOption.MOVE_TITLE:
|
||||
self.artistsString = ", ".join(self.artist['Main'])
|
||||
else:
|
||||
self.artistsString = ", ".join(self.artists)
|
||||
elif settings['tags']['multiArtistSeparator'] == "andFeat":
|
||||
self.artistsString = self.mainArtistsString
|
||||
if self.featArtistsString and str(settings['featuredToTitle']) != FeaturesOption.MOVE_TITLE:
|
||||
self.artistsString += " " + self.featArtistsString
|
||||
else:
|
||||
separator = settings['tags']['multiArtistSeparator']
|
||||
if str(settings['featuredToTitle']) == FeaturesOption.MOVE_TITLE:
|
||||
self.artistsString = separator.join(self.artist['Main'])
|
||||
else:
|
||||
self.artistsString = separator.join(self.artists)
|
||||
|
||||
class TrackError(Exception):
|
||||
"""Base class for exceptions in this module."""
|
||||
pass
|
||||
|
@ -1,7 +1 @@
|
||||
from deemix.types.Date import Date
|
||||
from deemix.types.Picture import Picture
|
||||
from deemix.types.Lyrics import Lyrics
|
||||
from deemix.types.Album import Album
|
||||
from deemix.types.Artist import Artist
|
||||
from deemix.types.Playlist import Playlist
|
||||
from deemix.types.Track import Track
|
||||
VARIOUS_ARTISTS = "5080"
|
||||
|
Reference in New Issue
Block a user