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
Commits
89943266
Verified
Commit
89943266
authored
May 15, 2018
by
Eliot Berriot
Browse files
See
#195
: expose bitrate, duration and size in AP audio representations
parent
4b21128e
Changes
4
Hide whitespace changes
Inline
Side-by-side
api/funkwhale_api/federation/factories.py
View file @
89943266
...
...
@@ -233,6 +233,9 @@ class AudioMetadataFactory(factory.Factory):
release
=
factory
.
LazyAttribute
(
lambda
o
:
'https://musicbrainz.org/release/{}'
.
format
(
uuid
.
uuid4
())
)
bitrate
=
42
length
=
43
size
=
44
class
Meta
:
model
=
dict
...
...
api/funkwhale_api/federation/models.py
View file @
89943266
...
...
@@ -216,3 +216,6 @@ class LibraryTrack(models.Model):
for
chunk
in
r
.
iter_content
(
chunk_size
=
512
):
tmp_file
.
write
(
chunk
)
self
.
audio_file
.
save
(
filename
,
tmp_file
)
def
get_metadata
(
self
,
key
):
return
self
.
metadata
.
get
(
key
)
api/funkwhale_api/federation/serializers.py
View file @
89943266
...
...
@@ -688,6 +688,12 @@ class AudioMetadataSerializer(serializers.Serializer):
artist
=
ArtistMetadataSerializer
()
release
=
ReleaseMetadataSerializer
()
recording
=
RecordingMetadataSerializer
()
bitrate
=
serializers
.
IntegerField
(
required
=
False
,
allow_null
=
True
,
min_value
=
0
)
size
=
serializers
.
IntegerField
(
required
=
False
,
allow_null
=
True
,
min_value
=
0
)
length
=
serializers
.
IntegerField
(
required
=
False
,
allow_null
=
True
,
min_value
=
0
)
class
AudioSerializer
(
serializers
.
Serializer
):
...
...
@@ -760,6 +766,9 @@ class AudioSerializer(serializers.Serializer):
'musicbrainz_id'
:
str
(
track
.
mbid
)
if
track
.
mbid
else
None
,
'title'
:
track
.
title
,
},
'bitrate'
:
instance
.
bitrate
,
'size'
:
instance
.
size
,
'length'
:
instance
.
duration
,
},
'url'
:
{
'href'
:
utils
.
full_url
(
instance
.
path
),
...
...
api/tests/federation/test_serializers.py
View file @
89943266
...
...
@@ -533,7 +533,12 @@ def test_activity_pub_audio_serializer_to_library_track_no_duplicate(
def
test_activity_pub_audio_serializer_to_ap
(
factories
):
tf
=
factories
[
'music.TrackFile'
](
mimetype
=
'audio/mp3'
)
tf
=
factories
[
'music.TrackFile'
](
mimetype
=
'audio/mp3'
,
bitrate
=
42
,
duration
=
43
,
size
=
44
,
)
library
=
actors
.
SYSTEM_ACTORS
[
'library'
].
get_actor_instance
()
expected
=
{
'@context'
:
serializers
.
AP_CONTEXT
,
...
...
@@ -555,6 +560,9 @@ def test_activity_pub_audio_serializer_to_ap(factories):
'musicbrainz_id'
:
tf
.
track
.
mbid
,
'title'
:
tf
.
track
.
title
,
},
'size'
:
tf
.
size
,
'length'
:
tf
.
duration
,
'bitrate'
:
tf
.
bitrate
,
},
'url'
:
{
'href'
:
utils
.
full_url
(
tf
.
path
),
...
...
@@ -599,6 +607,9 @@ def test_activity_pub_audio_serializer_to_ap_no_mbid(factories):
'title'
:
tf
.
track
.
title
,
'musicbrainz_id'
:
None
,
},
'size'
:
None
,
'length'
:
None
,
'bitrate'
:
None
,
},
'url'
:
{
'href'
:
utils
.
full_url
(
tf
.
path
),
...
...
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