This commit is contained in:
恍兮惚兮 2025-01-05 19:12:07 +08:00
parent 54feff89ef
commit abfc9f123a
6 changed files with 73 additions and 44 deletions

View File

@ -1,7 +1,7 @@
set(VERSION_MAJOR 6) set(VERSION_MAJOR 6)
set(VERSION_MINOR 17) set(VERSION_MINOR 17)
set(VERSION_PATCH 1) set(VERSION_PATCH 2)
set(VERSION_REVISION 0) set(VERSION_REVISION 0)
set(LUNA_VERSION "{${VERSION_MAJOR},${VERSION_MINOR},${VERSION_PATCH},${VERSION_REVISION}}") set(LUNA_VERSION "{${VERSION_MAJOR},${VERSION_MINOR},${VERSION_PATCH},${VERSION_REVISION}}")
add_library(VERSION_DEF ${CMAKE_CURRENT_LIST_DIR}/version_def.cpp) add_library(VERSION_DEF ${CMAKE_CURRENT_LIST_DIR}/version_def.cpp)

View File

@ -1,35 +1,34 @@
import requests import requests
from urllib.parse import quote from urllib.parse import quote
import re import re
from myutils.utils import localcachehelper
from cishu.cishubase import cishubase from cishu.cishubase import cishubase
class goo(cishubase): class goo(cishubase):
def init(self): def init(self):
self.style = None self.cache = localcachehelper("cishucss/goo")
self.klass = None self.klass = "lunagoocsswrapper"
def search(self, word): def search(self, word):
url = "https://dictionary.goo.ne.jp/srch/all/{}/m1u/".format(quote(word)) url = "https://dictionary.goo.ne.jp/srch/all/{}/m1u/".format(quote(word))
x = requests.get(url, proxies=self.proxy).text x = requests.get(url, proxies=self.proxy).text
xx = re.findall("<section>([\\s\\S]*?)</section>", x) xx = re.findall("<section>([\\s\\S]*?)</section>", x)
if not xx:
return
xx = "".join(xx).replace('href="/', 'href="https://dictionary.goo.ne.jp/') xx = "".join(xx).replace('href="/', 'href="https://dictionary.goo.ne.jp/')
if not self.style: cssurl = "https://dictionary.goo.ne.jp/mix/css/app.css"
self.style, self.klass = self.parse_stylesheet( if not self.cache[cssurl]:
( origin = requests.get(cssurl, proxies=self.proxy).text
requests.get( origin = (
"https://dictionary.goo.ne.jp/mix/css/app.css", origin.replace("width:1004px", "")
proxies=self.proxy, .replace("width:1024px", "")
) .replace("width:644px", "")
.text.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(
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
self.style, self.klass, xx )
)

View File

@ -1,15 +1,15 @@
import requests import requests
from urllib.parse import quote from urllib.parse import quote
from cishu.cishubase import cishubase from cishu.cishubase import cishubase
from myutils.utils import get_element_by from myutils.utils import get_element_by, localcachehelper
import re import re
class japandict(cishubase): class japandict(cishubase):
def init(self): def init(self):
self.style = None self.style = localcachehelper("cishucss/japandict")
self.klass = None self.klass = "lunajapandictcsswrapper"
def search(self, word): def search(self, word):
url = "https://www.japandict.com/?s={}&lang=eng&list=1".format(quote(word)) url = "https://www.japandict.com/?s={}&lang=eng&list=1".format(quote(word))
@ -25,13 +25,12 @@ class japandict(cishubase):
if not res: if not res:
return return
res = re.sub('href="(.*?)"', 'href="https://www.japandict.com\\1"', res) res = re.sub('href="(.*?)"', 'href="https://www.japandict.com\\1"', res)
if not self.style: csslink = "https://www.japandict.com/static/css/japandict.ac087f3ecbc8.css"
self.style, self.klass = self.parse_stylesheet( if not self.style[csslink]:
requests.get( css = requests.get(csslink, proxies=self.proxy).text
"https://www.japandict.com/static/css/japandict.ac087f3ecbc8.css", css = css.replace("padding-top:60px !important", "")
proxies=self.proxy, css = self.parse_stylesheet(css, self.klass)
).text.replace("padding-top:60px !important", "") self.style[csslink] = css
)
return '<style>{}</style><div class="{}">{}</div>'.format( return '<style>{}</style><div class="{}">{}</div>'.format(
self.style, self.klass, res self.style[csslink], self.klass, res
) )

View File

@ -2,13 +2,14 @@ import requests
from urllib.parse import quote from urllib.parse import quote
import re, threading import re, threading
from cishu.cishubase import cishubase 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): class jisho(cishubase):
def init(self): def init(self):
self.style = {} self.style = localcachehelper("cishucss/jisho")
self.klass = "lunajishocsswrapper"
def generatehtml_tabswitch(self, allres): def generatehtml_tabswitch(self, allres):
btns = [] btns = []
@ -132,7 +133,9 @@ function onclickbtn_xxxxxx_internal(_id) {
) )
link = ss.group()[6:-1] link = ss.group()[6:-1]
if not self.style.get(link): 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["style"] = self.style[link]
saver["primary"] = get_element_by("id", "result_area", res) + res.replace( saver["primary"] = get_element_by("id", "result_area", res) + res.replace(
get_element_by("id", "main_results", res), get_element_by("id", "main_results", res),
@ -163,7 +166,6 @@ function onclickbtn_xxxxxx_internal(_id) {
res.append(("Others", saver["secondary"])) res.append(("Others", saver["secondary"]))
if not res: if not res:
return return
style, klass = self.parse_stylesheet(saver.get("style", ""))
return '<style>{}</style><div class="{}">{}</div>'.format( return '<style>{}</style><div class="{}">{}</div>'.format(
style, klass, self.generatehtml_tabswitch(res) saver.get("style", ""), self.klass, self.generatehtml_tabswitch(res)
) )

View File

@ -1,14 +1,15 @@
import requests import requests
from urllib.parse import quote, unquote from urllib.parse import quote, unquote
from cishu.cishubase import cishubase from cishu.cishubase import cishubase
from myutils.utils import simplehtmlparser_all, simplehtmlparser from myutils.utils import simplehtmlparser_all, simplehtmlparser, localcachehelper
import re, threading import re, threading
class weblio(cishubase): class weblio(cishubase):
def init(self): def init(self):
self.style = {} self.cache = localcachehelper("cishucss/weblio")
self.klass = "lunawebliocsswrapper"
def search(self, word): def search(self, word):
url = "https://www.weblio.jp/content/" + quote(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) return '''href="javascript:safe_weblio_search_word('{}')"'''.format(word)
join = re.sub('href="https://www.weblio.jp/content/(.*?)"', __, join) join = re.sub('href="https://www.weblio.jp/content/(.*?)"', __, join)
join+=r''' join += r"""
<script> <script>
function safe_weblio_search_word(word){ function safe_weblio_search_word(word){
if(window.luna_search_word) if(window.luna_search_word)
@ -59,7 +60,7 @@ function safe_weblio_search_word(word){
else if(window.LUNAJSObject) else if(window.LUNAJSObject)
window.LUNAJSObject.luna_search_word(word) window.LUNAJSObject.luna_search_word(word)
}</script> }</script>
''' """
links = [] links = []
style = simplehtmlparser(html, "style", "<style>")[7:-8] style = simplehtmlparser(html, "style", "<style>")[7:-8]
for link in simplehtmlparser_all(html, "link", '<link rel="stylesheet"'): for link in simplehtmlparser_all(html, "link", '<link rel="stylesheet"'):
@ -71,15 +72,14 @@ function safe_weblio_search_word(word){
ts[-1].start() ts[-1].start()
for t in ts: for t in ts:
t.join() t.join()
style += "".join(self.style.get(link, "") for link in links) style += "".join(self.cache.get(link) for link in links)
style, klass = self.parse_stylesheet(style) return '<style>{}</style><div class="{}">{}</div>'.format(style, self.klass, join)
return '<style>{}</style><div class="{}">{}</div>'.format(style, klass, join)
def makelink(self, link): def makelink(self, link):
if not self.style.get(link): if not self.cache.get(link):
req = requests.get( req = requests.get(
link, link,
proxies=self.proxy, proxies=self.proxy,
) )
html = req.text if req.status_code == 200 else "" html = req.text if req.status_code == 200 else ""
self.style[link] = html self.cache[link] = self.parse_stylesheet(html, self.klass)

View File

@ -26,6 +26,35 @@ from html.parser import HTMLParser
from myutils.audioplayer import bass_code_cast 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"): def qimage2binary(qimage: QImage, fmt="BMP"):
byte_array = QByteArray() byte_array = QByteArray()
buffer = QBuffer(byte_array) buffer = QBuffer(byte_array)