mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-29 16:44:13 +08:00
amb
This commit is contained in:
parent
bef522ec0c
commit
fe71aab2b3
@ -2340,24 +2340,17 @@ class mdict(cishubase):
|
|||||||
print_exc()
|
print_exc()
|
||||||
|
|
||||||
def querycomplex(self, word, index):
|
def querycomplex(self, word, index):
|
||||||
# 0 严格,1 前缀,2 后缀,3 中缀
|
|
||||||
results = []
|
results = []
|
||||||
results += index(word)
|
diss = {}
|
||||||
if self.config["ambiguity"] == 0:
|
import winsharedutils
|
||||||
_ = []
|
|
||||||
for __ in results:
|
for k in index("*" + word + "*"):
|
||||||
if __.lower() == word:
|
dis = winsharedutils.distance(k, word)
|
||||||
_.append(__)
|
if dis <= self.config["ambiguity"]:
|
||||||
results = _
|
results.append(k)
|
||||||
if self.config["ambiguity"] >= 2:
|
diss[k] = dis
|
||||||
for k in index("*" + word):
|
|
||||||
if k not in results:
|
return sorted(results, key=lambda x: diss[x])
|
||||||
results.append(k)
|
|
||||||
if self.config["ambiguity"] >= 3:
|
|
||||||
for k in index("*" + word + "*"):
|
|
||||||
if k not in results:
|
|
||||||
results.append(k)
|
|
||||||
return results
|
|
||||||
|
|
||||||
def parse_strings(self, input_string):
|
def parse_strings(self, input_string):
|
||||||
parsed_strings = []
|
parsed_strings = []
|
||||||
@ -2462,77 +2455,95 @@ class mdict(cishubase):
|
|||||||
html += htmlitem
|
html += htmlitem
|
||||||
# print(html)
|
# print(html)
|
||||||
return html
|
return html
|
||||||
def get_mime_type_from_magic(self,magic_bytes):
|
|
||||||
if magic_bytes.startswith(b'OggS'):
|
def get_mime_type_from_magic(self, magic_bytes):
|
||||||
return 'audio/ogg'
|
if magic_bytes.startswith(b"OggS"):
|
||||||
elif magic_bytes.startswith(b'\x1A\x45\xDF\xA3'): # EBML header (Matroska)
|
return "audio/ogg"
|
||||||
return 'video/webm'
|
elif magic_bytes.startswith(b"\x1A\x45\xDF\xA3"): # EBML header (Matroska)
|
||||||
elif magic_bytes.startswith(b'\x52\x49\x46\x46') and magic_bytes[8:12] == b'WEBP':
|
return "video/webm"
|
||||||
return 'image/webp'
|
elif (
|
||||||
elif magic_bytes.startswith(b'\xFF\xD8\xFF'):
|
magic_bytes.startswith(b"\x52\x49\x46\x46") and magic_bytes[8:12] == b"WEBP"
|
||||||
return 'image/jpeg'
|
):
|
||||||
elif magic_bytes.startswith(b'\x89\x50\x4E\x47\x0D\x0A\x1A\x0A'):
|
return "image/webp"
|
||||||
return 'image/png'
|
elif magic_bytes.startswith(b"\xFF\xD8\xFF"):
|
||||||
elif magic_bytes.startswith(b'GIF87a') or magic_bytes.startswith(b'GIF89a'):
|
return "image/jpeg"
|
||||||
return 'image/gif'
|
elif magic_bytes.startswith(b"\x89\x50\x4E\x47\x0D\x0A\x1A\x0A"):
|
||||||
elif magic_bytes.startswith(b'\x00\x00\x01\xBA') or magic_bytes.startswith(b'\x00\x00\x01\xB3'):
|
return "image/png"
|
||||||
return 'video/mpeg'
|
elif magic_bytes.startswith(b"GIF87a") or magic_bytes.startswith(b"GIF89a"):
|
||||||
elif magic_bytes.startswith(b'\x49\x44\x33') or magic_bytes.startswith(b'\xFF\xFB'):
|
return "image/gif"
|
||||||
return 'audio/mpeg'
|
elif magic_bytes.startswith(b"\x00\x00\x01\xBA") or magic_bytes.startswith(
|
||||||
|
b"\x00\x00\x01\xB3"
|
||||||
|
):
|
||||||
|
return "video/mpeg"
|
||||||
|
elif magic_bytes.startswith(b"\x49\x44\x33") or magic_bytes.startswith(
|
||||||
|
b"\xFF\xFB"
|
||||||
|
):
|
||||||
|
return "audio/mpeg"
|
||||||
else:
|
else:
|
||||||
return 'application/octet-stream'
|
return "application/octet-stream"
|
||||||
def repairtarget(self,index,base,html_content):
|
|
||||||
|
def repairtarget(self, index, base, html_content):
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
src_pattern = r'src="([^"]+)"'
|
src_pattern = r'src="([^"]+)"'
|
||||||
href_pattern = r'href="([^"]+)"'
|
href_pattern = r'href="([^"]+)"'
|
||||||
|
|
||||||
src_matches = re.findall(src_pattern, html_content)
|
src_matches = re.findall(src_pattern, html_content)
|
||||||
href_matches = re.findall(href_pattern, html_content)
|
href_matches = re.findall(href_pattern, html_content)
|
||||||
|
|
||||||
for url in src_matches + href_matches:
|
for url in src_matches + href_matches:
|
||||||
oked=False
|
oked = False
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
with open(os.path.join(base, url), 'rb') as f:
|
with open(os.path.join(base, url), "rb") as f:
|
||||||
file_content = f.read()
|
file_content = f.read()
|
||||||
|
|
||||||
except:
|
except:
|
||||||
url1=url.replace('/','\\')
|
url1 = url.replace("/", "\\")
|
||||||
if not url1.startswith('\\'):
|
if not url1.startswith("\\"):
|
||||||
url1='\\'+url1
|
url1 = "\\" + url1
|
||||||
try:
|
try:
|
||||||
file_content=index.mdd_lookup(url1)[0]
|
file_content = index.mdd_lookup(url1)[0]
|
||||||
except:
|
except:
|
||||||
func=url.split(r'://')[0]
|
func = url.split(r"://")[0]
|
||||||
|
|
||||||
url1=url.split(r'://')[1]
|
url1 = url.split(r"://")[1]
|
||||||
url1=url1.replace('/','\\')
|
url1 = url1.replace("/", "\\")
|
||||||
|
|
||||||
if not url1.startswith('\\'):
|
if not url1.startswith("\\"):
|
||||||
url1='\\'+url1
|
url1 = "\\" + url1
|
||||||
file_content=index.mdd_lookup(url1)[0]
|
file_content = index.mdd_lookup(url1)[0]
|
||||||
if func=='sound':
|
if func == "sound":
|
||||||
|
|
||||||
base64_content = base64.b64encode(file_content).decode('utf-8')
|
base64_content = base64.b64encode(file_content).decode(
|
||||||
|
"utf-8"
|
||||||
|
)
|
||||||
import uuid
|
import uuid
|
||||||
uid=str(uuid.uuid4())
|
|
||||||
|
uid = str(uuid.uuid4())
|
||||||
# with open(uid+'.mp3','wb') as ff:
|
# with open(uid+'.mp3','wb') as ff:
|
||||||
# ff.write(file_content)
|
# ff.write(file_content)
|
||||||
audio=f'<audio controls id="{uid}" style="display: none"><source src="data:{self.get_mime_type_from_magic(file_content)};base64,{base64_content}"></audio>'
|
audio = f'<audio controls id="{uid}" style="display: none"><source src="data:{self.get_mime_type_from_magic(file_content)};base64,{base64_content}"></audio>'
|
||||||
html_content = audio+html_content.replace(url, f"javascript:document.getElementById('{uid}').play()")
|
html_content = audio + html_content.replace(
|
||||||
file_content=None
|
url,
|
||||||
oked=True
|
f"javascript:document.getElementById('{uid}').play()",
|
||||||
|
)
|
||||||
|
file_content = None
|
||||||
|
oked = True
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print(url)
|
print(url)
|
||||||
except:
|
except:
|
||||||
file_content=None
|
file_content = None
|
||||||
if file_content:
|
if file_content:
|
||||||
base64_content = base64.b64encode(file_content).decode('utf-8')
|
base64_content = base64.b64encode(file_content).decode("utf-8")
|
||||||
html_content = html_content.replace(url, f'data:application/octet-stream;base64,{base64_content}')
|
html_content = html_content.replace(
|
||||||
|
url, f"data:application/octet-stream;base64,{base64_content}"
|
||||||
|
)
|
||||||
elif not oked:
|
elif not oked:
|
||||||
print(url)
|
print(url)
|
||||||
return html_content
|
return html_content
|
||||||
|
|
||||||
def search(self, word):
|
def search(self, word):
|
||||||
allres = []
|
allres = []
|
||||||
for index, f in self.builders:
|
for index, f in self.builders:
|
||||||
@ -2555,9 +2566,9 @@ class mdict(cishubase):
|
|||||||
print_exc()
|
print_exc()
|
||||||
if len(results) == 0:
|
if len(results) == 0:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for i in range(len(results)):
|
for i in range(len(results)):
|
||||||
results[i]=self.repairtarget(index,os.path.dirname(f),results[i])
|
results[i] = self.repairtarget(index, os.path.dirname(f), results[i])
|
||||||
# <img src="/rjx0849.png" width="1080px"><br><center> <a href="entry://rjx0848">
|
# <img src="/rjx0849.png" width="1080px"><br><center> <a href="entry://rjx0848">
|
||||||
# /rjx0849.png->mddkey \\rjx0849.png entry://rjx0848->跳转到mdxkey rjx0849
|
# /rjx0849.png->mddkey \\rjx0849.png entry://rjx0848->跳转到mdxkey rjx0849
|
||||||
# 太麻烦,不搞了。
|
# 太麻烦,不搞了。
|
||||||
|
@ -979,7 +979,7 @@
|
|||||||
"type": "intspin",
|
"type": "intspin",
|
||||||
"name": "ambiguity",
|
"name": "ambiguity",
|
||||||
"min": 0,
|
"min": 0,
|
||||||
"max": 3,
|
"max": 100,
|
||||||
"step": 1
|
"step": 1
|
||||||
},
|
},
|
||||||
"priority": {
|
"priority": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user