Skip to content

Commit

Permalink
Fix audio alt files missing bit rate (#3931)
Browse files Browse the repository at this point in the history
* Make some audio alt file fields not required

Signed-off-by: Olga Bulat <[email protected]>

* Add ccmixter to sample data

Signed-off-by: Olga Bulat <[email protected]>

* Add serializer test

Signed-off-by: Olga Bulat <[email protected]>

* Update api/api/serializers/audio_serializers.py

Co-authored-by: Dhruv Bhanushali <[email protected]>
Signed-off-by: Olga Bulat <[email protected]>

---------

Signed-off-by: Olga Bulat <[email protected]>
Co-authored-by: Dhruv Bhanushali <[email protected]>
  • Loading branch information
obulat and dhruvkb authored Mar 18, 2024
1 parent 4938423 commit a9d1b36
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion api/api/examples/audio_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"display_name": "Freesound",
"source_url": "https://freesound.org/",
"logo_url": None,
"media_count": 828,
"media_count": 827,
},
{
"source_name": "jamendo",
Expand Down
3 changes: 3 additions & 0 deletions api/api/serializers/audio_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,19 @@ class Meta:
bit_rate = serializers.IntegerField(
help_text="Bit rate of the alternative file.",
min_value=0,
required=False,
)
filesize = serializers.IntegerField(
help_text="Size of the alternative file in bytes.",
min_value=0,
required=False,
)
filetype = serializers.CharField(
help_text="File type of the alternative file.",
)
sample_rate = serializers.IntegerField(
help_text="Sample rate of the alternative file.",
required=False,
min_value=0,
)

Expand Down
2 changes: 1 addition & 1 deletion api/test/integration/test_media_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def media_type(request):
"audio": MediaType(
name="audio",
path="audio",
providers=["freesound", "jamendo", "wikimedia_audio"],
providers=["freesound", "jamendo", "wikimedia_audio", "ccmixter"],
categories=["music", "pronunciation"],
tags=["cat"],
q="love",
Expand Down
22 changes: 22 additions & 0 deletions api/test/unit/serializers/test_audio_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,25 @@ def test_audio_serializer_with_peaks_param(audio_fixture, include_peaks):

audio_serializer = AudioSerializer(instance=audio_fixture, context=mock_ctx)
assert ("peaks" in audio_serializer.data) is include_peaks


# https://github.com/WordPress/openverse/issues/3930
@pytest.mark.django_db
def test_audio_serializer_with_non_required_alt_audio_fields_missing():
alt_files = [
{"bit_rate": 128, "filetype": "mp3", "url": "https://example.com/audio.mp3"}
]
audio = Audio(
identifier=uuid.uuid4(),
alt_files=alt_files,
)
audio.save()
factory = APIRequestFactory()
request = factory.get(f"audio/{audio.identifier}/?peaks=false")
request = Request(request)
mock_ctx = {"request": request}

audio_serializer = AudioSerializer(instance=audio, context=mock_ctx)

assert len(audio_serializer.data.get("alt_files")) == 1
assert audio_serializer.data.get("alt_files")[0] == alt_files[0]
1 change: 1 addition & 0 deletions load_sample_data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ VALUES
(now(), 'freesound', 'Freesound', 'https://freesound.org/', false, 'audio'),
(now(), 'jamendo', 'Jamendo', 'https://www.jamendo.com', false, 'audio'),
(now(), 'wikimedia_audio', 'Wikimedia', 'https://commons.wikimedia.org', false, 'audio');
(now(), 'ccmixter', 'CCMixter', 'https://ccmixter.org', false, 'audio');
"

#############
Expand Down
2 changes: 1 addition & 1 deletion sample_data/sample_audio.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4987,7 +4987,7 @@ eaf02071-03f5-4b53-ba65-08893ac6b2a3,2022-05-01 13:29:45.000000+00,2022-05-01 13
f560f982-61cb-41a5-a306-d5c020a7a987,2022-07-14 00:14:10.000000+00,2022-07-14 00:14:10.000000+00,provider_api,freesound,freesound,540761,https://freesound.org/people/schampa/sounds/540761,https://cdn.freesound.org/previews/540/540761_12061410-hq.mp3,,mp3,8490,128000,,,,,,"[{""url"": ""https://freesound.org/apiv2/sounds/540761/download/"", ""bit_rate"": ""64000"", ""filesize"": ""69745"", ""filetype"": ""m4a"", ""sample_rate"": ""48000""}]",163344,cc0,1.0,schampa,https://freesound.org/people/schampa,Dog Squeaking Toy,"{""download"": ""https://freesound.org/apiv2/sounds/540761/download/"", ""description"": ""AME 111: Lecture Response 9 - My dog squeaking its toy"", ""license_url"": ""https://creativecommons.org/publicdomain/zero/1.0/"", ""num_downloads"": ""6"", ""raw_license_url"": ""http://creativecommons.org/publicdomain/zero/1.0/""}","[{""name"": ""Dog-Toy"", ""provider"": ""freesound""}, {""name"": ""Squeaking"", ""provider"": ""freesound""}, {""name"": ""Dog"", ""provider"": ""freesound""}]",false,2022-06-23 16:48:28.620481+00,false,,
ad31d6a4-da5e-4f9a-accd-488cc6f26f85,2022-11-18 19:16:34.000000+00,2022-11-18 19:16:34.000000+00,provider_api,freesound,freesound,540769,https://freesound.org/people/aes2322/sounds/540769,https://cdn.freesound.org/previews/540/540769_12002388-hq.mp3,,mp3,26538,128000,,,,,,"[{""url"": ""https://freesound.org/apiv2/sounds/540769/download/"", ""bit_rate"": ""67000"", ""filesize"": ""223413"", ""filetype"": ""m4a"", ""sample_rate"": ""48000""}]",520992,cc0,1.0,aes2322,https://freesound.org/people/aes2322,rainy backyard.m4a,"{""geotag"": ""42.4415094256 -76.5142383879"", ""download"": ""https://freesound.org/apiv2/sounds/540769/download/"", ""description"": ""recording of backyard in upstate new york at night during a light rainstorm, crickets in the background"", ""license_url"": ""https://creativecommons.org/publicdomain/zero/1.0/"", ""num_downloads"": ""13"", ""raw_license_url"": ""http://creativecommons.org/publicdomain/zero/1.0/""}","[{""name"": ""field-recording"", ""provider"": ""freesound""}, {""name"": ""nature"", ""provider"": ""freesound""}, {""name"": ""insects"", ""provider"": ""freesound""}, {""name"": ""dripping"", ""provider"": ""freesound""}, {""name"": ""rain"", ""provider"": ""freesound""}, {""name"": ""crickets"", ""provider"": ""freesound""}, {""name"": ""night"", ""provider"": ""freesound""}]",false,2022-06-23 16:48:28.620481+00,false,,
1ed40a60-878e-4de9-9c92-f999aa985938,2022-07-09 08:21:00.000000+00,2022-07-09 08:21:00.000000+00,provider_api,freesound,freesound,540979,https://freesound.org/people/izzytherobloxgamer09/sounds/540979,https://cdn.freesound.org/previews/540/540979_11676858-hq.mp3,,mp3,57794,128000,,,,,,"[{""url"": ""https://freesound.org/apiv2/sounds/540979/download/"", ""bit_rate"": ""196000"", ""filesize"": ""1421403"", ""filetype"": ""m4a"", ""sample_rate"": ""44100""}]",1375925,by-nc,3.0,izzytherobloxgamer09,https://freesound.org/people/izzytherobloxgamer09,The caged child song.mp3,"{""download"": ""https://freesound.org/apiv2/sounds/540979/download/"", ""description"": ""Here is me singing the Caged Child song from danganronpa V3"", ""license_url"": ""https://creativecommons.org/licenses/by-nc/3.0/"", ""num_downloads"": ""14"", ""raw_license_url"": ""http://creativecommons.org/licenses/by-nc/3.0/""}","[{""name"": ""danganronpa"", ""provider"": ""freesound""}, {""name"": ""videogame"", ""provider"": ""freesound""}, {""name"": ""seance"", ""provider"": ""freesound""}, {""name"": ""music"", ""provider"": ""freesound""}, {""name"": ""song"", ""provider"": ""freesound""}]",false,2022-06-23 16:48:28.620481+00,false,,
39c3ee4e-0734-4515-b7a3-a8e9bef482a6,2022-11-10 16:38:14.000000+00,2022-11-10 16:38:14.000000+00,provider_api,freesound,freesound,541215,https://freesound.org/people/bogenseeberg/sounds/541215,https://cdn.freesound.org/previews/541/541215_7495013-hq.mp3,,mp3,17809,128000,,,,"{""title"": ""Lithuanian"", ""creator"": ""bogenseeberg"", ""thumbnail"": null, ""creator_url"": ""https://freesound.org/people/bogenseeberg/"", ""foreign_identifier"": ""27957"", ""foreign_landing_url"": ""https://freesound.org/apiv2/packs/27957/""}",,"[{""url"": ""https://freesound.org/apiv2/sounds/541215/download/"", ""bit_rate"": ""99000"", ""filesize"": ""221102"", ""filetype"": ""m4a"", ""sample_rate"": ""44100""}]",334767,by,3.0,bogenseeberg,https://freesound.org/people/bogenseeberg,Lithuanian alphabet. Letter T.,"{""download"": ""https://freesound.org/apiv2/sounds/541215/download/"", ""description"": ""Triušis tigras ir teptukas Televizorius trintukas Tulpe, tortas, trupinys Zodziu pilnas traukinys ar tikrai ar tik man rodos pirmas raidas ju vienodos"", ""license_url"": ""https://creativecommons.org/licenses/by/3.0/"", ""num_downloads"": ""13"", ""raw_license_url"": ""http://creativecommons.org/licenses/by/3.0/""}","[{""name"": ""kids"", ""provider"": ""freesound""}, {""name"": ""alphabet"", ""provider"": ""freesound""}, {""name"": ""lithuanian"", ""provider"": ""freesound""}, {""name"": ""rhymes"", ""provider"": ""freesound""}, {""name"": ""lietuvu"", ""provider"": ""freesound""}, {""name"": ""t"", ""provider"": ""freesound""}, {""name"": ""kalba"", ""provider"": ""freesound""}]",false,2022-06-23 16:48:28.620481+00,false,,27957
c82f7c3d-7330-4bfe-9e1c-3f2a26347744,2024-03-12 18:47:50.634854 +00:00,2024-03-12 18:47:50.634854 +00:00,provider_api,ccmixter,ccmixter,45311,https://ccmixter.org/files/NiGiD/45311,https://ccmixter.org/content/NiGiD/NiGiD_-_Six_of_One.mp3,,mp3,233000,,44000,,,,,,3728657,by-nc,3.0,Martijn de Boer (NiGiD),https://ccmixter.org/people/NiGiD,Six of One,"{""description"": ""Bass improvisation on billraydrums' Six of One. Also added some 'guitar', played high on the bass fretboard. It's in G7, the B-part is in Gmin7 and a normal blues scheme. Bill Ray - Drums Instruments in ZIP (FLAC files)"", ""license_url"": ""https://creativecommons.org/licenses/by-nc/3.0/"", ""raw_license_url"": ""http://creativecommons.org/licenses/by-nc/3.0/"", ""description_html"": ""Bass improvisation on billraydrums&#8217; Six of One. Also added some &#8216;guitar&#8217;, played high on the bass fretboard.<br /> <br /> It&#8217;s in G7, the B-part is in Gmin7 and a normal blues scheme.<br /> <br /> Bill Ray - Drums<br /> <br /> Instruments in ZIP (FLAC files)"", ""upload_num_scores"": ""5""}","[{""name"": ""media"", ""provider"": ""ccmixter""}, {""name"": ""remix"", ""provider"": ""ccmixter""}, {""name"": ""bpm_110_115"", ""provider"": ""ccmixter""}, {""name"": ""sample"", ""provider"": ""ccmixter""}, {""name"": ""non_commercial"", ""provider"": ""ccmixter""}, {""name"": ""audio"", ""provider"": ""ccmixter""}, {""name"": ""mp3"", ""provider"": ""ccmixter""}, {""name"": ""44k"", ""provider"": ""ccmixter""}, {""name"": ""stereo"", ""provider"": ""ccmixter""}, {""name"": ""CBR"", ""provider"": ""ccmixter""}, {""name"": ""archive"", ""provider"": ""ccmixter""}, {""name"": ""zip"", ""provider"": ""ccmixter""}, {""name"": ""billraydrums"", ""provider"": ""ccmixter""}, {""name"": ""drums"", ""provider"": ""ccmixter""}, {""name"": ""guitar"", ""provider"": ""ccmixter""}, {""name"": ""bass"", ""provider"": ""ccmixter""}, {""name"": ""instrumental"", ""provider"": ""ccmixter""}, {""name"": ""jazz"", ""provider"": ""ccmixter""}, {""name"": ""free_jazz"", ""provider"": ""ccmixter""}]",false,2024-03-12 18:47:50.634854 +00:00,false,,
68b11ad9-c406-46d2-a303-155f9b0a975a,2022-03-05 08:45:00.000000+00,2022-03-05 08:45:00.000000+00,provider_api,freesound,freesound,541228,https://freesound.org/people/karinalarasart/sounds/541228,https://cdn.freesound.org/previews/541/541228_6383813-hq.mp3,,mp3,14826,128000,,,,,,"[{""url"": ""https://freesound.org/apiv2/sounds/541228/download/"", ""bit_rate"": ""67000"", ""filesize"": ""125854"", ""filetype"": ""m4a"", ""sample_rate"": ""48000""}]",284592,cc0,1.0,karinalarasart,https://freesound.org/people/karinalarasart,Hummingbird Siren 2,"{""download"": ""https://freesound.org/apiv2/sounds/541228/download/"", ""description"": ""Hummingbird warning sound/song. Sounds like a little whistle/siren. Recorded with iPhone 8"", ""license_url"": ""https://creativecommons.org/publicdomain/zero/1.0/"", ""num_downloads"": ""10"", ""raw_license_url"": ""http://creativecommons.org/publicdomain/zero/1.0/""}","[{""name"": ""nature"", ""provider"": ""freesound""}, {""name"": ""tweet"", ""provider"": ""freesound""}, {""name"": ""birds"", ""provider"": ""freesound""}, {""name"": ""bird-song"", ""provider"": ""freesound""}, {""name"": ""bird"", ""provider"": ""freesound""}, {""name"": ""birdsong"", ""provider"": ""freesound""}]",false,2022-06-23 16:48:28.620481+00,false,,
96acc4c0-78c1-4ba6-be77-d0afd0ace672,2022-12-29 18:38:34.000000+00,2022-12-29 18:38:34.000000+00,provider_api,freesound,freesound,541232,https://freesound.org/people/karinalarasart/sounds/541232,https://cdn.freesound.org/previews/541/541232_6383813-hq.mp3,,mp3,60842,128000,,,,,,"[{""url"": ""https://freesound.org/apiv2/sounds/541232/download/"", ""bit_rate"": ""64000"", ""filesize"": ""506993"", ""filetype"": ""m4a"", ""sample_rate"": ""48000""}]",1174896,cc0,1.0,karinalarasart,https://freesound.org/people/karinalarasart,Rain Hitting Metal,"{""download"": ""https://freesound.org/apiv2/sounds/541232/download/"", ""avg_rating"": ""4.0"", ""description"": ""Rain hitting he metal storage thing in the backyard. Recorded with iPhone 8"", ""license_url"": ""https://creativecommons.org/publicdomain/zero/1.0/"", ""num_ratings"": ""1"", ""num_downloads"": ""14"", ""raw_license_url"": ""http://creativecommons.org/publicdomain/zero/1.0/""}","[{""name"": ""rainfall"", ""provider"": ""freesound""}, {""name"": ""weather"", ""provider"": ""freesound""}, {""name"": ""rain"", ""provider"": ""freesound""}, {""name"": ""raining"", ""provider"": ""freesound""}]",false,2022-06-23 16:48:28.620481+00,false,,
80da10a3-51ec-4f4f-8b3a-4e0ddc4515b5,2022-07-11 07:59:12.000000+00,2022-07-11 07:59:12.000000+00,provider_api,freesound,freesound,541271,https://freesound.org/people/melakoma/sounds/541271,https://cdn.freesound.org/previews/541/541271_10945366-hq.mp3,,mp3,1555,128000,,,,,,"[{""url"": ""https://freesound.org/apiv2/sounds/541271/download/"", ""bit_rate"": ""292000"", ""filesize"": ""56935"", ""filetype"": ""m4a"", ""sample_rate"": ""44100""}]",32714,cc0,1.0,melakoma,https://freesound.org/people/melakoma,two door knock.m4a,"{""download"": ""https://freesound.org/apiv2/sounds/541271/download/"", ""description"": ""needed a two door knock for a project, so I knocked twice on a wooden desk."", ""license_url"": ""https://creativecommons.org/publicdomain/zero/1.0/"", ""num_downloads"": ""15"", ""raw_license_url"": ""http://creativecommons.org/publicdomain/zero/1.0/""}","[{""name"": ""wooden"", ""provider"": ""freesound""}, {""name"": ""knock"", ""provider"": ""freesound""}, {""name"": ""door"", ""provider"": ""freesound""}, {""name"": ""two"", ""provider"": ""freesound""}, {""name"": ""desk"", ""provider"": ""freesound""}]",false,2022-06-23 16:48:28.620481+00,false,,
Expand Down

0 comments on commit a9d1b36

Please sign in to comment.