Merge branch '273-fix-mimetypes' into 'develop'
Resolve "Update file_track_files command to handle bad mimetypes" Closes #273 See merge request funkwhale/funkwhale!226
This commit is contained in:
commit
a16bd2a409
|
@ -33,9 +33,9 @@ class Command(BaseCommand):
|
|||
def fix_mimetypes(self, dry_run, **kwargs):
|
||||
self.stdout.write('Fixing missing mimetypes...')
|
||||
matching = models.TrackFile.objects.filter(
|
||||
source__startswith='file://', mimetype=None)
|
||||
source__startswith='file://').exclude(mimetype__startswith='audio/')
|
||||
self.stdout.write(
|
||||
'[mimetypes] {} entries found with no mimetype'.format(
|
||||
'[mimetypes] {} entries found with bad or no mimetype'.format(
|
||||
matching.count()))
|
||||
for extension, mimetype in utils.EXTENSION_TO_MIMETYPE.items():
|
||||
qs = matching.filter(source__endswith='.{}'.format(extension))
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
import os
|
||||
|
||||
from funkwhale_api.music.management.commands import fix_track_files
|
||||
|
||||
DATA_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
||||
def test_fix_track_files_bitrate_length(factories, mocker):
|
||||
tf1 = factories['music.TrackFile'](bitrate=1, duration=2)
|
||||
|
@ -43,3 +47,27 @@ def test_fix_track_files_size(factories, mocker):
|
|||
|
||||
# updated
|
||||
assert tf2.size == 2
|
||||
|
||||
|
||||
def test_fix_track_files_mimetype(factories, mocker):
|
||||
name = 'test.mp3'
|
||||
mp3_path = os.path.join(DATA_DIR, 'test.mp3')
|
||||
ogg_path = os.path.join(DATA_DIR, 'test.ogg')
|
||||
tf1 = factories['music.TrackFile'](
|
||||
audio_file__from_path=mp3_path,
|
||||
source='file://{}'.format(mp3_path),
|
||||
mimetype='application/x-empty')
|
||||
|
||||
# this one already has a mimetype set, to it should not be updated
|
||||
tf2 = factories['music.TrackFile'](
|
||||
audio_file__from_path=ogg_path,
|
||||
source='file://{}'.format(ogg_path),
|
||||
mimetype='audio/something')
|
||||
c = fix_track_files.Command()
|
||||
c.fix_mimetypes(dry_run=False)
|
||||
|
||||
tf1.refresh_from_db()
|
||||
tf2.refresh_from_db()
|
||||
|
||||
assert tf1.mimetype == 'audio/mpeg'
|
||||
assert tf2.mimetype == 'audio/something'
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
fix_track_files will now update files with bad mimetype (and not only
|
||||
the one with no mimetype) (#273)
|
Loading…
Reference in New Issue