Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
petitminion
funkwhale
Commits
18ad6cfa
Verified
Commit
18ad6cfa
authored
Jun 03, 2018
by
Eliot Berriot
Browse files
Fix #273: fix_track_files will now update files with bad mimetype
parent
390dcfd0
Changes
3
Hide whitespace changes
Inline
Side-by-side
api/funkwhale_api/music/management/commands/fix_track_files.py
View file @
18ad6cfa
...
...
@@ -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
))
...
...
api/tests/music/test_commands.py
View file @
18ad6cfa
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'
changes/changelog.d/273.enhancement
0 → 100644
View file @
18ad6cfa
fix_track_files will now update files with bad mimetype (and not only
the one with no mimetype) (#273)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment