Skip to content

Commit

Permalink
Merge pull request #585 from xxyzz/zh
Browse files Browse the repository at this point in the history
Fix 'OGG_url' not defined error in some zh edition pages
  • Loading branch information
xxyzz authored Apr 15, 2024
2 parents ce4c458 + 2cb9d36 commit 35d8612
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/wiktextract/extractor/share.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def split_chinese_variants(text: str) -> Iterable[tuple[Optional[str], str]]:
def create_audio_url_dict(filename: str) -> dict[str, str]:
# remove white space and left-to-right mark
filename = filename.strip(" \u200e")
file_extension = filename[filename.rfind(".") + 1 :]
if file_extension.lower() == "ogv":
file_extension = filename[filename.rfind(".") + 1 :].lower()
if file_extension == "ogv":
# ".ogv" pages are redirected to ".oga" pages in Wikipedia Commons
filename = filename[:filename.rfind(".")] + ".oga"
file_extension = "oga"
Expand Down
12 changes: 12 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def test_audio_transcode_url(self):
"ogg_url": "https://upload.wikimedia.org/wikipedia/commons/transcoded/e/e1/LL-Q150_(fra)-DenisdeShawi-bonjour.wav/LL-Q150_(fra)-DenisdeShawi-bonjour.wav.ogg",
},
)

sound_data = create_audio_url_dict("File:Fr-BonjourF.oga")
self.assertEqual(
sound_data,
Expand All @@ -84,5 +85,16 @@ def test_audio_transcode_url(self):
"mp3_url": "https://upload.wikimedia.org/wikipedia/commons/transcoded/b/b9/Fr-BonjourF.oga/Fr-BonjourF.oga.mp3",
},
)

sound_data = create_audio_url_dict("Qc-Vancouver.ogv")
self.assertEqual(sound_data["audio"], "Qc-Vancouver.oga")

sound_data = create_audio_url_dict("De-Fisch.OGG")
self.assertEqual(
sound_data,
{
"audio": "De-Fisch.OGG",
"ogg_url": "https://commons.wikimedia.org/wiki/Special:FilePath/De-Fisch.OGG",
"mp3_url": "https://upload.wikimedia.org/wikipedia/commons/transcoded/0/0f/De-Fisch.OGG/De-Fisch.OGG.mp3",
},
)

0 comments on commit 35d8612

Please sign in to comment.