Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Commit

Permalink
Fix Yahoo Dictionary to get the url of mp3 file.
Browse files Browse the repository at this point in the history
  • Loading branch information
shunyi authored and shunyi committed Aug 31, 2016
1 parent 05e5c81 commit 978b67f
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions zdict/dictionaries/yahoo.py
Expand Up @@ -80,18 +80,34 @@ def query(self, word: str):
content['pronounce'].append(match.group(1, 2))

# handle sound
pronu_sound = data.find(class_='proun_sound')
if pronu_sound:
content['sound'] = [
('mp3', pronu_sound.find(
class_='source',
attrs={'data-type': 'audio/mpeg'}
).attrs['data-src']),
('ogg', pronu_sound.find(
class_='source',
attrs={'data-type': 'audio/ogg'}
).attrs['data-src']),
]
proun_sound = data.find(
'span',
style="display: none;",
id="iconStyle",
class_="tri",
title="http://product.dreye.com.tw/",
)
if proun_sound:
content['sound'] = {}
d = json.loads(proun_sound.text)

sound_types_and_urls = (
d.get('sound_url_1', []) + d.get('sound_url_2', [])
)
sound_accents = (
d.get('sound_type_1', []) + d.get('sound_type_2', [])
)

for sound_type_and_url, sound_accent in zip(
sound_types_and_urls, sound_accents
):
if sound_type_and_url:
sound_type, sound_url = list(sound_type_and_url.items())[0]
content['sound'].setdefault(
sound_type, {}
).setdefault(
sound_accent, []
).append(sound_url)

# Handle explain
main_explanations = data.find(
Expand Down

0 comments on commit 978b67f

Please sign in to comment.