From 2fc6de3af001dc6efa92421d34223664f13f2b64 Mon Sep 17 00:00:00 2001 From: "St.Huang" Date: Tue, 31 Jul 2018 11:53:18 +0800 Subject: [PATCH] bug fixes. --- addons/fastwq/service/dict/baicizhan.py | 3 +-- addons/fastwq/service/dict/baidu_chinese.py | 3 +-- addons/fastwq/service/dict/frdic.py | 3 +-- addons/fastwq/service/dict/iciba.py | 4 ++-- addons/fastwq/service/dict/oxford_learning.py | 4 ++-- addons21/fastwq/service/dict/baicizhan.py | 3 +-- addons21/fastwq/service/dict/baidu_chinese.py | 3 +-- addons21/fastwq/service/dict/frdic.py | 3 +-- addons21/fastwq/service/dict/iciba.py | 4 ++-- addons21/fastwq/service/dict/oxford_learning.py | 6 +++--- 10 files changed, 15 insertions(+), 21 deletions(-) diff --git a/addons/fastwq/service/dict/baicizhan.py b/addons/fastwq/service/dict/baicizhan.py index 82f05c9..9d0d13a 100644 --- a/addons/fastwq/service/dict/baicizhan.py +++ b/addons/fastwq/service/dict/baicizhan.py @@ -36,8 +36,7 @@ class Baicizhan(WebService): @export('PRON') def fld_phonetic(self): url = u'http://baicizhan.qiniucdn.com/word_audios/{}.mp3'.format(self.quote_word) - audio_name = 'bcz_%s.mp3' % self.word - audio_name = get_hex_name(self.unique.lower(), audio_name, 'mp3') + audio_name = get_hex_name(self.unique.lower(), url, 'mp3') if self.bcz_download_mp3: if os.path.exists(audio_name) or self.download(url, audio_name, 5): with open(audio_name, 'rb') as f: diff --git a/addons/fastwq/service/dict/baidu_chinese.py b/addons/fastwq/service/dict/baidu_chinese.py index 1bc4960..0426fa0 100644 --- a/addons/fastwq/service/dict/baidu_chinese.py +++ b/addons/fastwq/service/dict/baidu_chinese.py @@ -71,8 +71,7 @@ class Baidu_Chinese(WebService): def fld_pron(self): audio_url = self._get_field('audio_url') if baidu_download_mp3 and audio_url: - filename = u'_baidu_chinese_{}_.mp3'.format(self.word) - filename = get_hex_name(self.unique.lower(), filename, 'mp3') + filename = get_hex_name(self.unique.lower(), audio_url, 'mp3') try: if os.path.exists(filename) or self.net_download( filename, diff --git a/addons/fastwq/service/dict/frdic.py b/addons/fastwq/service/dict/frdic.py index 0621904..4f410a6 100644 --- a/addons/fastwq/service/dict/frdic.py +++ b/addons/fastwq/service/dict/frdic.py @@ -60,8 +60,7 @@ class Frdic(WebService): url = 'https://api.frdic.com/api/v2/speech/speakweb?langid=fr&txt=QYN{word}'.format( word=urllib2.quote(base64.b64encode(self.word.encode('utf-8'))) ) - filename = u'frdic_{word}.mp3'.format(word=self.word) - filename = get_hex_name(self.unique.lower(), filename, 'mp3') + filename = get_hex_name(self.unique.lower(), url, 'mp3') if os.path.exists(filename) or self.net_download(filename, url): return self.get_anki_label(filename, 'audio') return '' diff --git a/addons/fastwq/service/dict/iciba.py b/addons/fastwq/service/dict/iciba.py index 80ea1d9..794a555 100644 --- a/addons/fastwq/service/dict/iciba.py +++ b/addons/fastwq/service/dict/iciba.py @@ -58,7 +58,7 @@ class ICIBA(WebService): if not audio_url: audio_url, t = seg['symbols'][0]['ph_tts_mp3'], 'tts' if iciba_download_mp3 and audio_url: - filename = u'iciba_{0}_{1}.mp3'.format(self.word, t) + filename = get_hex_name(self.unique.lower(), audio_url, 'mp3') if os.path.exists(filename) or self.download(audio_url, filename): return self.get_anki_label(filename, 'audio') return audio_url @@ -71,7 +71,7 @@ class ICIBA(WebService): if not audio_url: audio_url, t = seg['symbols'][0]['ph_tts_mp3'], 'tts' if iciba_download_mp3 and audio_url: - filename = u'iciba_{0}_{1}.mp3'.format(self.word, t) + filename = get_hex_name(self.unique.lower(), audio_url, 'mp3') if os.path.exists(filename) or self.download(audio_url, filename): return self.get_anki_label(filename, 'audio') return audio_url diff --git a/addons/fastwq/service/dict/oxford_learning.py b/addons/fastwq/service/dict/oxford_learning.py index 561a721..4840be6 100644 --- a/addons/fastwq/service/dict/oxford_learning.py +++ b/addons/fastwq/service/dict/oxford_learning.py @@ -71,14 +71,14 @@ class OxfordLearning(WebService): def get_sound_bre(self): url = self._get_single_dict('s_bre') - filename = u'oxford_{}_uk.mp3'.format(self.word) + filename = get_hex_name(self.unique.lower(), url, 'mp3') if url and self.download(url, filename): return self.get_anki_label(filename, 'audio') return '' def get_sound_ame(self): url = self._get_single_dict('s_ame') - filename = u'oxford_{}_us.mp3'.format(self.word) + filename = get_hex_name(self.unique.lower(), url, 'mp3') if url and self.download(url, filename): return self.get_anki_label(filename, 'audio') return '' diff --git a/addons21/fastwq/service/dict/baicizhan.py b/addons21/fastwq/service/dict/baicizhan.py index 82f05c9..9d0d13a 100644 --- a/addons21/fastwq/service/dict/baicizhan.py +++ b/addons21/fastwq/service/dict/baicizhan.py @@ -36,8 +36,7 @@ class Baicizhan(WebService): @export('PRON') def fld_phonetic(self): url = u'http://baicizhan.qiniucdn.com/word_audios/{}.mp3'.format(self.quote_word) - audio_name = 'bcz_%s.mp3' % self.word - audio_name = get_hex_name(self.unique.lower(), audio_name, 'mp3') + audio_name = get_hex_name(self.unique.lower(), url, 'mp3') if self.bcz_download_mp3: if os.path.exists(audio_name) or self.download(url, audio_name, 5): with open(audio_name, 'rb') as f: diff --git a/addons21/fastwq/service/dict/baidu_chinese.py b/addons21/fastwq/service/dict/baidu_chinese.py index 7074147..d8deb6d 100644 --- a/addons21/fastwq/service/dict/baidu_chinese.py +++ b/addons21/fastwq/service/dict/baidu_chinese.py @@ -71,8 +71,7 @@ class Baidu_Chinese(WebService): def fld_pron(self): audio_url = self._get_field('audio_url') if baidu_download_mp3 and audio_url: - filename = u'_baidu_chinese_{}_.mp3'.format(self.word) - filename = get_hex_name(self.unique.lower(), filename, 'mp3') + filename = get_hex_name(self.unique.lower(), audio_url, 'mp3') try: if os.path.exists(filename) or self.net_download( filename, diff --git a/addons21/fastwq/service/dict/frdic.py b/addons21/fastwq/service/dict/frdic.py index 99fcce3..bc4c47c 100644 --- a/addons21/fastwq/service/dict/frdic.py +++ b/addons21/fastwq/service/dict/frdic.py @@ -60,8 +60,7 @@ class Frdic(WebService): url = 'https://api.frdic.com/api/v2/speech/speakweb?langid=fr&txt=QYN{word}'.format( word=urllib2.quote(base64.b64encode(self.word.encode('utf-8'))) ) - filename = u'frdic_{word}.mp3'.format(word=self.word) - filename = get_hex_name(self.unique.lower(), filename, 'mp3') + filename = get_hex_name(self.unique.lower(), url, 'mp3') if os.path.exists(filename) or self.net_download(filename, url): return self.get_anki_label(filename, 'audio') return '' diff --git a/addons21/fastwq/service/dict/iciba.py b/addons21/fastwq/service/dict/iciba.py index 80ea1d9..794a555 100644 --- a/addons21/fastwq/service/dict/iciba.py +++ b/addons21/fastwq/service/dict/iciba.py @@ -58,7 +58,7 @@ class ICIBA(WebService): if not audio_url: audio_url, t = seg['symbols'][0]['ph_tts_mp3'], 'tts' if iciba_download_mp3 and audio_url: - filename = u'iciba_{0}_{1}.mp3'.format(self.word, t) + filename = get_hex_name(self.unique.lower(), audio_url, 'mp3') if os.path.exists(filename) or self.download(audio_url, filename): return self.get_anki_label(filename, 'audio') return audio_url @@ -71,7 +71,7 @@ class ICIBA(WebService): if not audio_url: audio_url, t = seg['symbols'][0]['ph_tts_mp3'], 'tts' if iciba_download_mp3 and audio_url: - filename = u'iciba_{0}_{1}.mp3'.format(self.word, t) + filename = get_hex_name(self.unique.lower(), audio_url, 'mp3') if os.path.exists(filename) or self.download(audio_url, filename): return self.get_anki_label(filename, 'audio') return audio_url diff --git a/addons21/fastwq/service/dict/oxford_learning.py b/addons21/fastwq/service/dict/oxford_learning.py index 004db26..4b53124 100644 --- a/addons21/fastwq/service/dict/oxford_learning.py +++ b/addons21/fastwq/service/dict/oxford_learning.py @@ -2,7 +2,7 @@ #from warnings import filterwarnings from bs4 import Tag -from ..base import WebService, export, register, with_styles, parse_html +from ..base import * #filterwarnings('ignore') @@ -77,14 +77,14 @@ class OxfordLearning(WebService): def get_sound_bre(self): url = self._get_single_dict('s_bre') - filename = u'oxford_{}_uk.mp3'.format(self.word) + filename = get_hex_name(self.unique.lower(), url, 'mp3') if url and self.download(url, filename): return self.get_anki_label(filename, 'audio') return '' def get_sound_ame(self): url = self._get_single_dict('s_ame') - filename = u'oxford_{}_us.mp3'.format(self.word) + filename = get_hex_name(self.unique.lower(), url, 'mp3') if url and self.download(url, filename): return self.get_anki_label(filename, 'audio') return ''