mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2025-01-13 07:33:53 +08:00
.
This commit is contained in:
parent
54feff89ef
commit
abfc9f123a
@ -1,7 +1,7 @@
|
||||
|
||||
set(VERSION_MAJOR 6)
|
||||
set(VERSION_MINOR 17)
|
||||
set(VERSION_PATCH 1)
|
||||
set(VERSION_PATCH 2)
|
||||
set(VERSION_REVISION 0)
|
||||
set(LUNA_VERSION "{${VERSION_MAJOR},${VERSION_MINOR},${VERSION_PATCH},${VERSION_REVISION}}")
|
||||
add_library(VERSION_DEF ${CMAKE_CURRENT_LIST_DIR}/version_def.cpp)
|
||||
|
@ -1,35 +1,34 @@
|
||||
import requests
|
||||
from urllib.parse import quote
|
||||
import re
|
||||
from myutils.utils import localcachehelper
|
||||
from cishu.cishubase import cishubase
|
||||
|
||||
|
||||
class goo(cishubase):
|
||||
|
||||
def init(self):
|
||||
self.style = None
|
||||
self.klass = None
|
||||
self.cache = localcachehelper("cishucss/goo")
|
||||
self.klass = "lunagoocsswrapper"
|
||||
|
||||
def search(self, word):
|
||||
url = "https://dictionary.goo.ne.jp/srch/all/{}/m1u/".format(quote(word))
|
||||
x = requests.get(url, proxies=self.proxy).text
|
||||
xx = re.findall("<section>([\\s\\S]*?)</section>", x)
|
||||
|
||||
if not xx:
|
||||
return
|
||||
xx = "".join(xx).replace('href="/', 'href="https://dictionary.goo.ne.jp/')
|
||||
if not self.style:
|
||||
self.style, self.klass = self.parse_stylesheet(
|
||||
(
|
||||
requests.get(
|
||||
"https://dictionary.goo.ne.jp/mix/css/app.css",
|
||||
proxies=self.proxy,
|
||||
)
|
||||
.text.replace("width:1004px", "")
|
||||
.replace("width:1024px", "")
|
||||
.replace("width:644px", "")
|
||||
)
|
||||
cssurl = "https://dictionary.goo.ne.jp/mix/css/app.css"
|
||||
if not self.cache[cssurl]:
|
||||
origin = requests.get(cssurl, proxies=self.proxy).text
|
||||
origin = (
|
||||
origin.replace("width:1004px", "")
|
||||
.replace("width:1024px", "")
|
||||
.replace("width:644px", "")
|
||||
)
|
||||
origin = self.parse_stylesheet(origin, self.klass)
|
||||
self.cache[cssurl] = origin
|
||||
|
||||
if len(xx):
|
||||
return '<style>{}</style><div class="{}"><div id="NR-wrapper"><div id="NR-wrapper-in" class="cx">{}</div></div></div>'.format(
|
||||
self.style, self.klass, xx
|
||||
)
|
||||
return '<style>{}</style><div class="{}"><div id="NR-wrapper"><div id="NR-wrapper-in" class="cx">{}</div></div></div>'.format(
|
||||
self.cache[cssurl], self.klass, xx
|
||||
)
|
||||
|
@ -1,15 +1,15 @@
|
||||
import requests
|
||||
from urllib.parse import quote
|
||||
from cishu.cishubase import cishubase
|
||||
from myutils.utils import get_element_by
|
||||
from myutils.utils import get_element_by, localcachehelper
|
||||
import re
|
||||
|
||||
|
||||
class japandict(cishubase):
|
||||
|
||||
def init(self):
|
||||
self.style = None
|
||||
self.klass = None
|
||||
self.style = localcachehelper("cishucss/japandict")
|
||||
self.klass = "lunajapandictcsswrapper"
|
||||
|
||||
def search(self, word):
|
||||
url = "https://www.japandict.com/?s={}&lang=eng&list=1".format(quote(word))
|
||||
@ -25,13 +25,12 @@ class japandict(cishubase):
|
||||
if not res:
|
||||
return
|
||||
res = re.sub('href="(.*?)"', 'href="https://www.japandict.com\\1"', res)
|
||||
if not self.style:
|
||||
self.style, self.klass = self.parse_stylesheet(
|
||||
requests.get(
|
||||
"https://www.japandict.com/static/css/japandict.ac087f3ecbc8.css",
|
||||
proxies=self.proxy,
|
||||
).text.replace("padding-top:60px !important", "")
|
||||
)
|
||||
csslink = "https://www.japandict.com/static/css/japandict.ac087f3ecbc8.css"
|
||||
if not self.style[csslink]:
|
||||
css = requests.get(csslink, proxies=self.proxy).text
|
||||
css = css.replace("padding-top:60px !important", "")
|
||||
css = self.parse_stylesheet(css, self.klass)
|
||||
self.style[csslink] = css
|
||||
return '<style>{}</style><div class="{}">{}</div>'.format(
|
||||
self.style, self.klass, res
|
||||
self.style[csslink], self.klass, res
|
||||
)
|
||||
|
@ -2,13 +2,14 @@ import requests
|
||||
from urllib.parse import quote
|
||||
import re, threading
|
||||
from cishu.cishubase import cishubase
|
||||
from myutils.utils import get_element_by, simplehtmlparser_all
|
||||
from myutils.utils import get_element_by, simplehtmlparser_all, localcachehelper
|
||||
|
||||
|
||||
class jisho(cishubase):
|
||||
|
||||
def init(self):
|
||||
self.style = {}
|
||||
self.style = localcachehelper("cishucss/jisho")
|
||||
self.klass = "lunajishocsswrapper"
|
||||
|
||||
def generatehtml_tabswitch(self, allres):
|
||||
btns = []
|
||||
@ -132,7 +133,9 @@ function onclickbtn_xxxxxx_internal(_id) {
|
||||
)
|
||||
link = ss.group()[6:-1]
|
||||
if not self.style.get(link):
|
||||
self.style[link] = requests.get(link, proxies=self.proxy).text
|
||||
self.style[link] = self.parse_stylesheet(
|
||||
requests.get(link, proxies=self.proxy).text, self.klass
|
||||
)
|
||||
saver["style"] = self.style[link]
|
||||
saver["primary"] = get_element_by("id", "result_area", res) + res.replace(
|
||||
get_element_by("id", "main_results", res),
|
||||
@ -163,7 +166,6 @@ function onclickbtn_xxxxxx_internal(_id) {
|
||||
res.append(("Others", saver["secondary"]))
|
||||
if not res:
|
||||
return
|
||||
style, klass = self.parse_stylesheet(saver.get("style", ""))
|
||||
return '<style>{}</style><div class="{}">{}</div>'.format(
|
||||
style, klass, self.generatehtml_tabswitch(res)
|
||||
saver.get("style", ""), self.klass, self.generatehtml_tabswitch(res)
|
||||
)
|
||||
|
@ -1,14 +1,15 @@
|
||||
import requests
|
||||
from urllib.parse import quote, unquote
|
||||
from cishu.cishubase import cishubase
|
||||
from myutils.utils import simplehtmlparser_all, simplehtmlparser
|
||||
from myutils.utils import simplehtmlparser_all, simplehtmlparser, localcachehelper
|
||||
import re, threading
|
||||
|
||||
|
||||
class weblio(cishubase):
|
||||
|
||||
def init(self):
|
||||
self.style = {}
|
||||
self.cache = localcachehelper("cishucss/weblio")
|
||||
self.klass = "lunawebliocsswrapper"
|
||||
|
||||
def search(self, word):
|
||||
url = "https://www.weblio.jp/content/" + quote(word)
|
||||
@ -51,7 +52,7 @@ class weblio(cishubase):
|
||||
return '''href="javascript:safe_weblio_search_word('{}')"'''.format(word)
|
||||
|
||||
join = re.sub('href="https://www.weblio.jp/content/(.*?)"', __, join)
|
||||
join+=r'''
|
||||
join += r"""
|
||||
<script>
|
||||
function safe_weblio_search_word(word){
|
||||
if(window.luna_search_word)
|
||||
@ -59,7 +60,7 @@ function safe_weblio_search_word(word){
|
||||
else if(window.LUNAJSObject)
|
||||
window.LUNAJSObject.luna_search_word(word)
|
||||
}</script>
|
||||
'''
|
||||
"""
|
||||
links = []
|
||||
style = simplehtmlparser(html, "style", "<style>")[7:-8]
|
||||
for link in simplehtmlparser_all(html, "link", '<link rel="stylesheet"'):
|
||||
@ -71,15 +72,14 @@ function safe_weblio_search_word(word){
|
||||
ts[-1].start()
|
||||
for t in ts:
|
||||
t.join()
|
||||
style += "".join(self.style.get(link, "") for link in links)
|
||||
style, klass = self.parse_stylesheet(style)
|
||||
return '<style>{}</style><div class="{}">{}</div>'.format(style, klass, join)
|
||||
style += "".join(self.cache.get(link) for link in links)
|
||||
return '<style>{}</style><div class="{}">{}</div>'.format(style, self.klass, join)
|
||||
|
||||
def makelink(self, link):
|
||||
if not self.style.get(link):
|
||||
if not self.cache.get(link):
|
||||
req = requests.get(
|
||||
link,
|
||||
proxies=self.proxy,
|
||||
)
|
||||
html = req.text if req.status_code == 200 else ""
|
||||
self.style[link] = html
|
||||
self.cache[link] = self.parse_stylesheet(html, self.klass)
|
||||
|
@ -26,6 +26,35 @@ from html.parser import HTMLParser
|
||||
from myutils.audioplayer import bass_code_cast
|
||||
|
||||
|
||||
class localcachehelper:
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
self.cache = {}
|
||||
|
||||
def __getitem__(self, url: str):
|
||||
_ = self.cache.get(url)
|
||||
if _:
|
||||
return _
|
||||
b64 = hashlib.md5(url.encode("utf8")).hexdigest()
|
||||
fn = gobject.getcachedir(os.path.join(self.name, b64))
|
||||
if not os.path.isfile(fn):
|
||||
return None
|
||||
with open(fn, "r", encoding="utf8") as ff:
|
||||
data = ff.read()
|
||||
self.cache[url] = data
|
||||
return data
|
||||
|
||||
def __setitem__(self, url: str, data):
|
||||
self.cache[url] = data
|
||||
b64 = hashlib.md5(url.encode("utf8")).hexdigest()
|
||||
fn = gobject.getcachedir(os.path.join(self.name, b64))
|
||||
with open(fn, "w", encoding="utf8") as ff:
|
||||
ff.write(data)
|
||||
|
||||
get = __getitem__
|
||||
set = __setitem__
|
||||
|
||||
|
||||
def qimage2binary(qimage: QImage, fmt="BMP"):
|
||||
byte_array = QByteArray()
|
||||
buffer = QBuffer(byte_array)
|
||||
|
Loading…
x
Reference in New Issue
Block a user