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