Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
jovuit
funkwhale_OLD
Commits
0efdb6d9
Commit
0efdb6d9
authored
Jan 29, 2019
by
Vierkantor
Committed by
Eliot Berriot
Jan 29, 2019
Browse files
Resolve "In-place imports cannot be transcoded"
parent
db8427f3
Changes
4
Hide whitespace changes
Inline
Side-by-side
api/funkwhale_api/music/models.py
View file @
0efdb6d9
...
...
@@ -7,6 +7,7 @@ import uuid
import
markdown
import
pendulum
import
pydub
from
django.conf
import
settings
from
django.contrib.postgres.fields
import
JSONField
from
django.core.files.base
import
ContentFile
...
...
@@ -780,6 +781,15 @@ class Upload(models.Model):
"size"
:
self
.
get_file_size
(),
}
def
get_audio_segment
(
self
):
input
=
self
.
get_audio_file
()
if
not
input
:
return
input_format
=
utils
.
MIMETYPE_TO_EXTENSION
[
self
.
mimetype
]
audio
=
pydub
.
AudioSegment
.
from_file
(
input
,
format
=
input_format
)
return
audio
def
save
(
self
,
**
kwargs
):
if
not
self
.
mimetype
:
if
self
.
audio_file
:
...
...
@@ -824,10 +834,9 @@ class Upload(models.Model):
0
]
+
".{}"
.
format
(
format
)
version
.
audio_file
.
save
(
new_name
,
f
)
utils
.
transcode_
file
(
input
=
self
.
audio_
file
,
utils
.
transcode_
audio
(
audio
=
self
.
get_
audio_
segment
()
,
output
=
version
.
audio_file
,
input_format
=
utils
.
MIMETYPE_TO_EXTENSION
[
self
.
mimetype
],
output_format
=
utils
.
MIMETYPE_TO_EXTENSION
[
mimetype
],
)
version
.
size
=
version
.
audio_file
.
size
...
...
api/funkwhale_api/music/utils.py
View file @
0efdb6d9
...
...
@@ -75,5 +75,9 @@ def get_actor_from_request(request):
def
transcode_file
(
input
,
output
,
input_format
,
output_format
,
**
kwargs
):
with
input
.
open
(
"rb"
):
audio
=
pydub
.
AudioSegment
.
from_file
(
input
,
format
=
input_format
)
return
transcode_audio
(
audio
,
output
,
output_format
,
**
kwargs
)
def
transcode_audio
(
audio
,
output
,
output_format
,
**
kwargs
):
with
output
.
open
(
"wb"
):
return
audio
.
export
(
output
,
format
=
output_format
,
**
kwargs
)
api/tests/music/test_views.py
View file @
0efdb6d9
...
...
@@ -374,6 +374,32 @@ def test_listen_transcode(factories, now, logged_in_api_client, mocker):
)
@
pytest
.
mark
.
parametrize
(
"serve_path"
,
[(
"/host/music"
,),
(
"/app/music"
,)])
def
test_listen_transcode_in_place
(
serve_path
,
factories
,
now
,
logged_in_api_client
,
mocker
,
settings
):
settings
.
MUSIC_DIRECTORY_PATH
=
"/app/music"
settings
.
MUSIC_DIRECTORY_SERVE_PATH
=
serve_path
upload
=
factories
[
"music.Upload"
](
import_status
=
"finished"
,
library__actor__user
=
logged_in_api_client
.
user
,
audio_file
=
None
,
source
=
"file://"
+
os
.
path
.
join
(
DATA_DIR
,
"test.ogg"
),
)
assert
upload
.
get_audio_segment
()
url
=
reverse
(
"api:v1:listen-detail"
,
kwargs
=
{
"uuid"
:
upload
.
track
.
uuid
})
handle_serve
=
mocker
.
spy
(
views
,
"handle_serve"
)
response
=
logged_in_api_client
.
get
(
url
,
{
"to"
:
"mp3"
})
assert
response
.
status_code
==
200
handle_serve
.
assert_called_once_with
(
upload
,
user
=
logged_in_api_client
.
user
,
format
=
"mp3"
)
def
test_user_can_create_library
(
factories
,
logged_in_api_client
):
actor
=
logged_in_api_client
.
user
.
create_actor
()
url
=
reverse
(
"api:v1:libraries-list"
)
...
...
changes/changelog.d/688.bugfix
0 → 100644
View file @
0efdb6d9
Fix transcoding of in-place imported tracks (#688)
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