Skip to content

Commit

Permalink
Add alt_files serializer
Browse files Browse the repository at this point in the history
Signed-off-by: Olga Bulat <obulat@gmail.com>
  • Loading branch information
obulat committed Feb 28, 2024
1 parent 00fecbd commit cdbab2a
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions api/api/serializers/audio_serializers.py
Expand Up @@ -114,6 +114,41 @@ class Meta:
AudioHyperlinksSerializer = get_hyperlinks_serializer("audio")


class AudioAltFileSerializer(serializers.Serializer):
"""
A set of alternative files for a single audio object,
rendered as a part of the ``AudioSerializer`` output.
"""

class Meta:
fields = [
"url",
"bit_rate",
"filesize",
"filetype",
"sample_rate",
]

url = serializers.URLField(
help_text="URL of the alternative file.",
)
bit_rate = serializers.IntegerField(
help_text="Bit rate of the alternative file.",
min_value=0,
)
filesize = serializers.IntegerField(
help_text="Size of the alternative file in bytes.",
min_value=0,
)
filetype = serializers.CharField(
help_text="File type of the alternative file.",
)
sample_rate = serializers.IntegerField(
help_text="Sample rate of the alternative file.",
min_value=0,
)


class AudioSerializer(AudioHyperlinksSerializer, MediaSerializer):
"""A single audio file. Used in search results."""

Expand Down Expand Up @@ -145,6 +180,13 @@ class Meta:
read_only=True,
)

alt_files = AudioAltFileSerializer(
allow_null=True,
help_text="JSON describing alternative files for this audio.",
read_only=True,
many=True,
)

waveform = SchemableHyperlinkedIdentityField(
read_only=True,
view_name="audio-waveform",
Expand Down

0 comments on commit cdbab2a

Please sign in to comment.