mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-06 04:19:56 +02:00
Can now import covers from track metadata and track directory as well
This commit is contained in:
parent
14c8073e26
commit
290cae9a8f
13 changed files with 353 additions and 53 deletions
|
@ -23,6 +23,7 @@ from funkwhale_api import downloader
|
|||
from funkwhale_api import musicbrainz
|
||||
from funkwhale_api.federation import utils as federation_utils
|
||||
from . import importers
|
||||
from . import metadata
|
||||
from . import utils
|
||||
|
||||
|
||||
|
@ -192,10 +193,20 @@ class Album(APIModelMixin):
|
|||
}
|
||||
objects = AlbumQuerySet.as_manager()
|
||||
|
||||
def get_image(self):
|
||||
image_data = musicbrainz.api.images.get_front(str(self.mbid))
|
||||
f = ContentFile(image_data)
|
||||
self.cover.save('{0}.jpg'.format(self.mbid), f)
|
||||
def get_image(self, data=None):
|
||||
if data:
|
||||
f = ContentFile(data['content'])
|
||||
extensions = {
|
||||
'image/jpeg': 'jpg',
|
||||
'image/png': 'png',
|
||||
'image/gif': 'gif',
|
||||
}
|
||||
extension = extensions.get(data['mimetype'], 'jpg')
|
||||
self.cover.save('{}.{}'.format(self.uuid, extension), f)
|
||||
else:
|
||||
image_data = musicbrainz.api.images.get_front(str(self.mbid))
|
||||
f = ContentFile(image_data)
|
||||
self.cover.save('{0}.jpg'.format(self.mbid), f)
|
||||
return self.cover.file
|
||||
|
||||
def __str__(self):
|
||||
|
@ -522,6 +533,12 @@ class TrackFile(models.Model):
|
|||
self.mimetype = utils.guess_mimetype(self.audio_file)
|
||||
return super().save(**kwargs)
|
||||
|
||||
def get_metadata(self):
|
||||
audio_file = self.get_audio_file()
|
||||
if not audio_file:
|
||||
return
|
||||
return metadata.Metadata(audio_file)
|
||||
|
||||
|
||||
IMPORT_STATUS_CHOICES = (
|
||||
('pending', 'Pending'),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue