Skip to content

Commit

Permalink
Fix wikimedia_commons.py
Browse files Browse the repository at this point in the history
  • Loading branch information
obulat committed Apr 28, 2023
1 parent e9e5760 commit 0c7416f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,7 @@ def get_record_data(self, record):
if license_info.url is None:
return None

media_url = media_info.get("url")
if media_url is None:
if not (url := media_info.get("url")):
return None

creator, creator_url = self.extract_creator_info(media_info)
Expand All @@ -322,7 +321,7 @@ def get_record_data(self, record):
meta_data = self.create_meta_data_dict(record)

record_data = {
"media_url": media_url,
"url": url,
"foreign_landing_url": media_info.get("descriptionshorturl"),
"foreign_identifier": foreign_id,
"license_info": license_info,
Expand All @@ -345,7 +344,6 @@ def get_record_data(self, record):
@staticmethod
def get_image_record_data(record_data, media_info):
"""Extend record_data with image-specific fields."""
record_data["url"] = record_data.pop("media_url")
if record_data["filetype"] == "svg":
record_data["category"] = "illustration"

Expand All @@ -357,8 +355,6 @@ def get_image_record_data(record_data, media_info):

def get_audio_record_data(self, record_data, media_info):
"""Extend record_data with audio-specific fields."""
record_data["url"] = record_data.pop("media_url")

duration = int(float(media_info.get("duration", 0)) * 1000)
record_data["duration"] = duration
record_data["category"] = self.extract_audio_category(record_data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def test_create_meta_data_tallies_zero_global_usage_count(wmc):

def test_get_audio_record_data_parses_ogg_streams(wmc):
file_metadata = _get_resource_json("audio_filedata_ogg.json")
original_data = {"media_url": "myurl.com", "meta_data": {}}
original_data = {"url": "myurl.com", "meta_data": {}}
actual_parsed_data = wmc.get_audio_record_data(original_data, file_metadata)

expected_parsed_data = {
Expand All @@ -435,7 +435,7 @@ def test_get_audio_record_data_parses_ogg_streams(wmc):

def test_get_audio_record_data_parses_wav_audio_data(wmc):
file_metadata = _get_resource_json("audio_filedata_wav.json")
original_data = {"media_url": "myurl.com", "meta_data": {}}
original_data = {"url": "myurl.com", "meta_data": {}}
actual_parsed_data = wmc.get_audio_record_data(original_data, file_metadata)

expected_parsed_data = {
Expand All @@ -449,7 +449,7 @@ def test_get_audio_record_data_parses_wav_audio_data(wmc):

def test_get_audio_record_data_parses_wav_audio_data_missing_streams(wmc):
file_metadata = _get_resource_json("audio_filedata_wav.json")
original_data = {"media_url": "myurl.com", "meta_data": {}}
original_data = {"url": "myurl.com", "meta_data": {}}
# Remove any actual audio metadata
file_metadata["metadata"] = (
file_metadata["metadata"][:5] + file_metadata["metadata"][6:]
Expand All @@ -465,7 +465,7 @@ def test_get_audio_record_data_parses_wav_audio_data_missing_streams(wmc):

def test_get_audio_record_data_parses_wav_invalid_bit_rate(wmc):
file_metadata = _get_resource_json("audio_filedata_wav.json")
original_data = {"media_url": "myurl.com", "meta_data": {}}
original_data = {"url": "myurl.com", "meta_data": {}}
# Set the bit rate higher than the int max
file_metadata["metadata"][5]["value"][3]["value"][0]["value"][3][
"value"
Expand Down

0 comments on commit 0c7416f

Please sign in to comment.