From 4603f662a5c13269fb56b1de9016a2c29261b900 Mon Sep 17 00:00:00 2001 From: yu7777 Date: Mon, 7 Oct 2019 15:37:49 +1100 Subject: [PATCH] rename audio files for mdx default field rename audio files for mdx default field --- addons21/fastwq/service/base.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/addons21/fastwq/service/base.py b/addons21/fastwq/service/base.py index 1f84b2b..21d59fe 100644 --- a/addons21/fastwq/service/base.py +++ b/addons21/fastwq/service/base.py @@ -63,7 +63,7 @@ except ImportError: __all__ = [ - 'register', 'export', 'copy_static_file', 'with_styles', 'parse_html', 'service_wrap', 'get_hex_name', + 'register', 'export', 'copy_static_file', 'with_styles', 'parse_html', 'service_wrap', 'get_hex_name', 'Service', 'WebService', 'LocalService', 'MdxService', 'StardictService', 'QueryResult' ] @@ -88,7 +88,7 @@ def register(labels): """ def _deco(cls): cls.__register_label__ = _cl(labels) - + methods = inspect.getmembers(cls, predicate=_is_method_or_func) exports = [] for method in methods: @@ -250,7 +250,7 @@ class Service(object): @property def word(self): return self._word - + @word.setter def word(self, value): value = re.sub(r']*>', '', value) @@ -259,11 +259,11 @@ class Service(object): @property def quote_word(self): return urllib2.quote(self.word) - + @property def support(self): return True - + @property def fields(self): return self._fields @@ -415,7 +415,7 @@ class WebService(Service): headers = {'User-Agent': _default_ua} if custom_headers: headers.update(custom_headers) - + response = urllib2.urlopen( urllib2.Request( url=('?'.join([url, params]) if params and method == 'GET' @@ -672,8 +672,8 @@ class MdxService(LocalService): html = html.replace(each, u'_' + each.split('/')[-1]) # find sounds p = re.compile( - r']+?href=\"(sound:_.*?\.(?:mp3|wav))\"[^>]*?>(.*?)') - html = p.sub(u"[\\1]\\2", html) + r']+?href=\"sound:_(.*?\.(?:mp3|wav))\"[^>]*?>(.*?)') + html = p.sub("[sound:mdx-"+self.title+"-"+u"\\1]\\2", html) self.save_media_files(media_files_set) for f in mcss: cssfile = u'_{}'.format(os.path.basename(f.replace('\\', os.path.sep))) @@ -684,7 +684,7 @@ class MdxService(LocalService): css_src = self.dict_path.replace(self._filename + u'.mdx', f) if os.path.exists(css_src): shutil.copy(css_src, cssfile) - else: + else: self.missed_css.add(cssfile[1:]) new_css_file, wrap_class_name = wrap_css(cssfile) html = html.replace(cssfile, new_css_file) @@ -701,6 +701,8 @@ class MdxService(LocalService): basename = os.path.basename(filepath_in_mdx.replace('\\', os.path.sep)) if savepath is None: savepath = '_' + basename + if basename.lower().endswith(("mp3","wav")): + savepath = "mdx-" + self.title + "-" + basename if os.path.exists(savepath): return savepath try: @@ -739,6 +741,7 @@ class MdxService(LocalService): lst.extend(keys) for each in lst: self.save_default_file(each) + except AttributeError: pass