Verified Commit 89943266 authored by Eliot Berriot's avatar Eliot Berriot
Browse files

See #195: expose bitrate, duration and size in AP audio representations

parent 4b21128e
......@@ -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
......
......@@ -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)
......@@ -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),
......
......@@ -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),
......
Supports Markdown
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