mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-29 00:24:13 +08:00
better
This commit is contained in:
parent
8deddf6f9a
commit
c8b262eb0f
@ -1,6 +1,6 @@
|
||||
import requests
|
||||
from urllib.parse import quote
|
||||
import re
|
||||
import re, os
|
||||
from myutils.proxy import getproxy
|
||||
from cishu.cishubase import cishubase
|
||||
|
||||
@ -12,15 +12,19 @@ class goo(cishubase):
|
||||
x = requests.get(url, proxies=getproxy()).text
|
||||
xx = re.findall("<section>([\\s\\S]*?)</section>", x)
|
||||
|
||||
xx = "".join(xx)
|
||||
xx = re.sub("<h1>([\\s\\S]*?)</h1>", "", xx)
|
||||
xx = re.sub("<a([\\s\\S]*?)>", "", xx)
|
||||
xx = "".join(xx).replace('href="/', 'href="https://dictionary.goo.ne.jp/')
|
||||
if os.path.exists("cache/temp/goo.css") == False:
|
||||
stl = requests.get(
|
||||
"https://dictionary.goo.ne.jp/mix/css/app.css", proxies=getproxy()
|
||||
).text
|
||||
os.makedirs("cache/temp", exist_ok=True)
|
||||
with open("cache/temp/goo.css", "w", encoding="utf8") as ff:
|
||||
ff.write(stl)
|
||||
else:
|
||||
with open("cache/temp/goo.css", "r", encoding="utf8") as ff:
|
||||
stl = ff.read()
|
||||
|
||||
xx = re.sub("</a>", "", xx)
|
||||
if len(xx):
|
||||
return (
|
||||
'<div style="text-align: center;"><a href="{}">link</a></div>'.format(
|
||||
url
|
||||
)
|
||||
+ xx
|
||||
return '<div style="text-align: center;"><a href="{}">link</a><style>{}</style></div><div id="NR-main-in">{}</div>'.format(
|
||||
url, stl, xx
|
||||
)
|
||||
|
@ -1,7 +1,7 @@
|
||||
from myutils.config import getlangsrc
|
||||
import requests
|
||||
from urllib.parse import quote
|
||||
import re
|
||||
import re, os
|
||||
from myutils.proxy import getproxy
|
||||
from cishu.cishubase import cishubase
|
||||
|
||||
@ -24,14 +24,14 @@ class youdao(cishubase):
|
||||
),
|
||||
proxies=getproxy(),
|
||||
).text
|
||||
fnd = re.findall('<section class="modules"(.*?)>([\\s\\S]*?)</section>', text)
|
||||
|
||||
if len(fnd[0][1]):
|
||||
return (
|
||||
'<div style="text-align: center;"><a href="{}">link</a></div><br>'.format(
|
||||
"https://dict.youdao.com/result?word={}&lang={}".format(
|
||||
quote(word), self.srclang
|
||||
)
|
||||
)
|
||||
+ fnd[0][1]
|
||||
)
|
||||
fnd = re.search('<section class="modules"(.*?)>([\\s\\S]*?)</section>', text)
|
||||
fnd = fnd.group()
|
||||
style = re.search("<style(.*?)>([\\s\\S]*?)</style>", text)
|
||||
style = style.group()
|
||||
return '<div style="text-align: center;"><a href="{}">link</a></div><br>{}{}'.format(
|
||||
"https://dict.youdao.com/result?word={}&lang={}".format(
|
||||
quote(word), self.srclang
|
||||
),
|
||||
style,
|
||||
fnd,
|
||||
)
|
||||
|
@ -103,8 +103,8 @@ class QButtonGroup_switch_widegt(QWidget):
|
||||
|
||||
|
||||
def listprocessm():
|
||||
os.makedirs("./cache", exist_ok=True)
|
||||
cachefname = os.path.abspath("./cache/{}.txt".format(time.time()))
|
||||
os.makedirs("cache/temp", exist_ok=True)
|
||||
cachefname = os.path.abspath("cache/temp/{}.txt".format(time.time()))
|
||||
arch = "64" if gobject.baseobject.textsource.is64bit else "32"
|
||||
exe = os.path.abspath("./files/plugins/shareddllproxy{}.exe".format(arch))
|
||||
pid = " ".join([str(_) for _ in gobject.baseobject.textsource.pids])
|
||||
|
@ -43,9 +43,9 @@ from gui.rangeselect import rangeselct_function
|
||||
|
||||
class loopbackrecorder:
|
||||
def __init__(self):
|
||||
os.makedirs("./cache/tts", exist_ok=True)
|
||||
os.makedirs("cache/temp", exist_ok=True)
|
||||
self.file = os.path.abspath(
|
||||
os.path.join("./cache/tts", str(time.time()) + ".wav")
|
||||
os.path.join("cache/temp", str(time.time()) + ".wav")
|
||||
)
|
||||
try:
|
||||
self.waitsignal = str(time.time())
|
||||
@ -133,8 +133,8 @@ class AnkiWindow(QWidget):
|
||||
refreshhtml = pyqtSignal()
|
||||
|
||||
def callbacktts(self, edit, data):
|
||||
fname = "./cache/tts/" + str(uuid.uuid4()) + ".mp3"
|
||||
os.makedirs("./cache/tts", exist_ok=True)
|
||||
fname = "cache/temp/" + str(uuid.uuid4()) + ".mp3"
|
||||
os.makedirs("cache/temp", exist_ok=True)
|
||||
with open(fname, "wb") as ff:
|
||||
ff.write(data)
|
||||
edit.setText(os.path.abspath(fname))
|
||||
@ -161,8 +161,8 @@ class AnkiWindow(QWidget):
|
||||
img = imageCut(
|
||||
0, rect[0][0], rect[0][1], rect[1][0], rect[1][1], False, True
|
||||
)
|
||||
fname = "./cache/ocr/cropforanki.png"
|
||||
os.makedirs("./cache/ocr", exist_ok=True)
|
||||
fname = "cache/temp/" + str(uuid.uuid4()) + ".png"
|
||||
os.makedirs("cache/temp", exist_ok=True)
|
||||
img.save(fname)
|
||||
self.editpath.setText(os.path.abspath(fname))
|
||||
if globalconfig["ankiconnect"]["ocrcroped"]:
|
||||
|
@ -10,8 +10,10 @@ from myutils.wrapper import threader
|
||||
|
||||
@threader
|
||||
def grabwindow(callback=None):
|
||||
|
||||
fnamebase = "./cache/screenshot/{}".format(0)
|
||||
if callback:
|
||||
fnamebase = "cache/temp"
|
||||
else:
|
||||
fnamebase = "./cache/screenshot/{}".format(0)
|
||||
try:
|
||||
if gobject.baseobject.textsource.md5 != "0":
|
||||
fnamebase = "./cache/screenshot/{}".format(
|
||||
|
@ -203,14 +203,14 @@ def safedownload():
|
||||
"https://dl.vndb.org/dump/vndb-tags-latest.json.gz",
|
||||
proxies=getproxy(),
|
||||
)
|
||||
os.makedirs("./cache/vndb", exist_ok=True)
|
||||
with open("./cache/vndb/vndb-tags-latest.json.gz", "wb") as ff:
|
||||
os.makedirs("cache/temp", exist_ok=True)
|
||||
with open("cache/temp/vndb-tags-latest.json.gz", "wb") as ff:
|
||||
ff.write(resp.content)
|
||||
decompress_gzip_file(
|
||||
"./cache/vndb/vndb-tags-latest.json.gz",
|
||||
"./cache/vndb/vndb-tags-latest.json",
|
||||
"cache/temp/vndb-tags-latest.json.gz",
|
||||
"cache/temp/vndb-tags-latest.json",
|
||||
)
|
||||
with open("./cache/vndb/vndb-tags-latest.json", "r", encoding="utf8") as ff:
|
||||
with open("cache/temp/vndb-tags-latest.json", "r", encoding="utf8") as ff:
|
||||
js = json.load(ff)
|
||||
newjs = {}
|
||||
for item in js:
|
||||
|
@ -8,8 +8,8 @@ class OCR(baseocr):
|
||||
|
||||
def ocr(self, imagebinary):
|
||||
|
||||
os.makedirs("./cache/ocr", exist_ok=True)
|
||||
fname = "./cache/ocr/" + str(uuid.uuid4()) + ".png"
|
||||
os.makedirs("cache/temp", exist_ok=True)
|
||||
fname = "cache/temp/" + str(uuid.uuid4()) + ".png"
|
||||
with open(fname, "wb") as ff:
|
||||
ff.write(imagebinary)
|
||||
self.checkempty(["Port"])
|
||||
|
@ -24,9 +24,9 @@ class OCR(baseocr):
|
||||
path = self.config["路径"]
|
||||
if os.path.exists(path) == False:
|
||||
raise Exception(_TR("路径不存在"))
|
||||
|
||||
os.makedirs("./cache/ocr", exist_ok=True)
|
||||
fname = "./cache/ocr/" + str(uuid.uuid4()) + ".png"
|
||||
|
||||
os.makedirs("cache/temp", exist_ok=True)
|
||||
fname = "cache/temp/" + str(uuid.uuid4()) + ".png"
|
||||
with open(fname, "wb") as ff:
|
||||
ff.write(imagebinary)
|
||||
imgfile = os.path.abspath(fname)
|
||||
|
@ -25,8 +25,8 @@ class Method(scalebase):
|
||||
|
||||
def init(self):
|
||||
self.statuslistener()
|
||||
os.makedirs("./cache", exist_ok=True)
|
||||
self.jspath = os.path.abspath("./cache/magpie.config.json")
|
||||
os.makedirs("cache/temp", exist_ok=True)
|
||||
self.jspath = os.path.abspath("cache/temp/magpie.config.json")
|
||||
self.engine = subproc_w(
|
||||
'./files/plugins/Magpie/Magpie.Core.exe "{}"'.format(self.jspath),
|
||||
cwd="./files/plugins/Magpie/",
|
||||
|
@ -69,7 +69,8 @@ class TTS(TTSbase):
|
||||
return self.mapx[(hk, idx)]
|
||||
|
||||
def getvoicelist(self):
|
||||
cachefname = os.path.abspath("./cache/{}.txt".format(time.time()))
|
||||
os.makedirs("cache/temp", exist_ok=True)
|
||||
cachefname = os.path.abspath("cache/temp/{}.txt".format(time.time()))
|
||||
exe = os.path.abspath("./files/plugins/shareddllproxy32.exe")
|
||||
subprocess.run('"{}" neospeechlist "{}"'.format(exe, cachefname))
|
||||
|
||||
@ -93,5 +94,5 @@ class TTS(TTSbase):
|
||||
buf = ctypes.create_unicode_buffer(content, 10000)
|
||||
windows.WriteFile(self.hPipe, bytes(buf))
|
||||
size = c_int32.from_buffer_copy(windows.ReadFile(self.hPipe, 4)).value
|
||||
|
||||
return cast(self.mem, POINTER(c_char))[:size]
|
||||
|
||||
return cast(self.mem, POINTER(c_char))[:size]
|
||||
|
Loading…
x
Reference in New Issue
Block a user