Now store track file mimetype in database

This commit is contained in:
Eliot Berriot 2018-02-18 23:46:15 +01:00
parent 937c55fdd5
commit ddea5f1825
No known key found for this signature in database
GPG key ID: DD6965E2476E5C27
6 changed files with 99 additions and 1 deletions

View file

@ -18,6 +18,7 @@ from versatileimagefield.fields import VersatileImageField
from funkwhale_api import downloader
from funkwhale_api import musicbrainz
from . import importers
from . import utils
class APIModelMixin(models.Model):
@ -364,6 +365,7 @@ class TrackFile(models.Model):
source = models.URLField(null=True, blank=True)
duration = models.IntegerField(null=True, blank=True)
acoustid_track_id = models.UUIDField(null=True, blank=True)
mimetype = models.CharField(null=True, blank=True, max_length=200)
def download_file(self):
# import the track file, since there is not any
@ -393,6 +395,10 @@ class TrackFile(models.Model):
self.track.full_name,
os.path.splitext(self.audio_file.name)[-1])
def save(self, **kwargs):
if not self.mimetype and self.audio_file:
self.mimetype = utils.guess_mimetype(self.audio_file)
return super().save(**kwargs)
class ImportBatch(models.Model):
IMPORT_BATCH_SOURCES = [