Commit a16bd2a4 authored by Eliot Berriot's avatar Eliot Berriot
Browse files

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
parents 1098f1b9 18ad6cfa
...@@ -33,9 +33,9 @@ class Command(BaseCommand): ...@@ -33,9 +33,9 @@ class Command(BaseCommand):
def fix_mimetypes(self, dry_run, **kwargs): def fix_mimetypes(self, dry_run, **kwargs):
self.stdout.write('Fixing missing mimetypes...') self.stdout.write('Fixing missing mimetypes...')
matching = models.TrackFile.objects.filter( matching = models.TrackFile.objects.filter(
source__startswith='file://', mimetype=None) source__startswith='file://').exclude(mimetype__startswith='audio/')
self.stdout.write( self.stdout.write(
'[mimetypes] {} entries found with no mimetype'.format( '[mimetypes] {} entries found with bad or no mimetype'.format(
matching.count())) matching.count()))
for extension, mimetype in utils.EXTENSION_TO_MIMETYPE.items(): for extension, mimetype in utils.EXTENSION_TO_MIMETYPE.items():
qs = matching.filter(source__endswith='.{}'.format(extension)) qs = matching.filter(source__endswith='.{}'.format(extension))
import os
from import fix_track_files from import fix_track_files
DATA_DIR = os.path.dirname(os.path.abspath(__file__))
def test_fix_track_files_bitrate_length(factories, mocker): def test_fix_track_files_bitrate_length(factories, mocker):
tf1 = factories['music.TrackFile'](bitrate=1, duration=2) tf1 = factories['music.TrackFile'](bitrate=1, duration=2)
...@@ -43,3 +47,27 @@ def test_fix_track_files_size(factories, mocker): ...@@ -43,3 +47,27 @@ def test_fix_track_files_size(factories, mocker):
# updated # updated
assert tf2.size == 2 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'](
# this one already has a mimetype set, to it should not be updated
tf2 = factories['music.TrackFile'](
c = fix_track_files.Command()
assert tf1.mimetype == 'audio/mpeg'
assert tf2.mimetype == 'audio/something'
fix_track_files will now update files with bad mimetype (and not only
the one with no mimetype) (#273)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment