diff --git a/main.py b/main.py index f2e0118..3fd220c 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,6 @@ -from plugin.engine.bing import Bing +from plugin.engine.minebbs import Minebbs +from plugin.engine.klpbbs import Klpbbs +from plugin.engine.spigotmc import Spigot from plugin.utils.translate import translate, EN @@ -16,7 +18,20 @@ def print_result(result): if keyword == "exit": break - engine = Bing() + engine = Spigot() for result in engine.search(keyword): print_result(result) + + engine = Minebbs() + + for result in engine.search(keyword): + print_result(result) + + engine = Klpbbs() + + for result in engine.search(keyword): + print_result(result) + + + diff --git a/plugin/engine/bing.py b/plugin/engine/bing.py index 69cda56..9a9a3aa 100644 --- a/plugin/engine/bing.py +++ b/plugin/engine/bing.py @@ -9,18 +9,18 @@ class Bing(SearchEngine): + def search(self, keywords) -> typing.List[SearchResult]: + pass + def get_bing_url(self, keywords): keywords = keywords.strip('\n') bing_url = re.sub(r'^', 'https://cn.bing.com/search?q=', keywords) bing_url = re.sub(r'\s', '+', bing_url) return bing_url - def search(self, keywords) -> typing.List[SearchResult]: - return list(set(self._search(f"我的世界 {translate(keywords)} 插件")) | set( - self._search(f"minecraft {translate(keywords, to_lang=EN)} plugin"))) - - def _search(self, keywords) -> typing.List[SearchResult]: - bing_url = self.get_bing_url(keywords) + def _search(self, keywords, site="minebbs.com") -> typing.List[SearchResult]: + keywords = f'"{translate(keywords)}" ”插件“ site:{site}' + url = self.get_bing_url(keywords) result: typing.List[SearchResult] = [] headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', @@ -29,24 +29,21 @@ def _search(self, keywords) -> typing.List[SearchResult]: 'cookie': 'DUP=Q=sBQdXP4Rfrv4P4CTmxe4lQ2&T=415111783&A=2&IG=31B594EB8C9D4B1DB9BDA58C6CFD6F39; ' 'MUID=196418ED32D66077102115A736D66479; SRCHD=AF=NOFORM; ' 'SRCHUID=V=2&GUID=DDFFA87D3A894019942913899F5EC316&dmnchg=1; ENSEARCH=BENVER=1; ' - '_HPVN=CS=eyJQbiI6eyJDbiI6MiwiU3QiOjAsIlFzIjowLCJQcm9kIjoiUCJ9LCJTYyI6eyJDbiI6MiwiU3QiOjAsIlFzIjowLCJQcm9kIjoiSCJ9LCJReiI6eyJDbiI6MiwiU3QiOjAsIlFzIjowLCJQcm9kIjoiVCJ9LCJBcCI6dHJ1ZSwiTXV0ZSI6dHJ1ZSwiTGFkIjoiMjAyMC0wMy0xNlQwMDowMDowMFoiLCJJb3RkIjowLCJEZnQiOm51bGwsIk12cyI6MCwiRmx0IjowLCJJbXAiOjd9; ABDEF=V=13&ABDV=11&MRNB=1614238717214&MRB=0; _RwBf=mtu=0&g=0&cid=&o=2&p=&c=&t=0&s=0001-01-01T00:00:00.0000000+00:00&ts=2021-02-25T07:47:40.5285039+00:00&e=; MUIDB=196418ED32D66077102115A736D66479; SerpPWA=reg=1; SRCHUSR=DOB=20190509&T=1614253842000&TPC=1614238646000; _SS=SID=375CD2D8DA85697D0DA0DD31DBAB689D; _EDGE_S=SID=375CD2D8DA85697D0DA0DD31DBAB689D&mkt=zh-cn; _FP=hta=on; SL_GWPT_Show_Hide_tmp=1; SL_wptGlobTipTmp=1; dsc=order=ShopOrderDefault; ipv6=hit=1614260171835&t=4; SRCHHPGUSR=CW=993&CH=919&DPR=1&UTC=480&WTS=63749850642&HV=1614256571&BRW=HTP&BRH=M&DM=0' + '_HPVN=CS' + '=eyJQbiI6eyJDbiI6MiwiU3QiOjAsIlFzIjowLCJQcm9kIjoiUCJ9LCJTYyI6eyJDbiI6MiwiU3QiOjAsIlFzIjowLCJQcm9kIjoiSCJ9LCJReiI6eyJDbiI6MiwiU3QiOjAsIlFzIjowLCJQcm9kIjoiVCJ9LCJBcCI6dHJ1ZSwiTXV0ZSI6dHJ1ZSwiTGFkIjoiMjAyMC0wMy0xNlQwMDowMDowMFoiLCJJb3RkIjowLCJEZnQiOm51bGwsIk12cyI6MCwiRmx0IjowLCJJbXAiOjd9; ABDEF=V=13&ABDV=11&MRNB=1614238717214&MRB=0; _RwBf=mtu=0&g=0&cid=&o=2&p=&c=&t=0&s=0001-01-01T00:00:00.0000000+00:00&ts=2021-02-25T07:47:40.5285039+00:00&e=; MUIDB=196418ED32D66077102115A736D66479; SerpPWA=reg=1; SRCHUSR=DOB=20190509&T=1614253842000&TPC=1614238646000; _SS=SID=375CD2D8DA85697D0DA0DD31DBAB689D; _EDGE_S=SID=375CD2D8DA85697D0DA0DD31DBAB689D&mkt=zh-cn; _FP=hta=on; SL_GWPT_Show_Hide_tmp=1; SL_wptGlobTipTmp=1; dsc=order=ShopOrderDefault; ipv6=hit=1614260171835&t=4; SRCHHPGUSR=CW=993&CH=919&DPR=1&UTC=480&WTS=63749850642&HV=1614256571&BRW=HTP&BRH=M&DM=0' } - - for i in range(1, 3): - if i == 1: - url = bing_url - else: - url = bing_url + '&qs=ds&first=' + str((i * 10) - 1) + '&FORM=PERE' - content = requests.get(url=url, timeout=5, headers=headers) - tree = etree.HTML(content.text) - li_list = tree.xpath('//ol[@id="b_results"]//li[@class="b_algo"]') - for li in li_list: - try: - h3 = li.xpath('./h2/a')[0] - p = li.xpath('.//p')[0].xpath('string(.)') - url = h3.get('href') - result.append(SearchResult(url=url, title=translate(h3.xpath('string(.)')), summary=translate(p))) - except Exception as pri: - print(pri) + content = requests.get(url=url, timeout=5, headers=headers) + tree = etree.HTML(content.text) + li_list = tree.xpath('//ol[@id="b_results"]//li[@class="b_algo"]') + for li in li_list: + try: + h3: str = li.xpath('./h2/a')[0].xpath('string(.)') + p = li.xpath('.//p')[0].xpath('string(.)') + url = li.xpath('./div[1]/a/div[2]/div[2]/div/cite')[0].xpath('string(.)') + if h3.find("模组") != -1 or h3.find("地图") != -1 or h3.find("插件") == -1: + continue + result.append(SearchResult(url=url, title=h3, summary=p)) + except Exception as pri: + print(pri) return result diff --git a/plugin/engine/klpbbs.py b/plugin/engine/klpbbs.py new file mode 100644 index 0000000..9300dde --- /dev/null +++ b/plugin/engine/klpbbs.py @@ -0,0 +1,10 @@ +import typing + +from plugin.engine.base import SearchResult +from plugin.engine.bing import Bing + + +class Klpbbs(Bing): + + def search(self, keywords) -> typing.List[SearchResult]: + return super()._search(keywords, site="klpbbs.com")[:3] # 一般来将,前五个才有价值 # 更加fw,3个 \ No newline at end of file diff --git a/plugin/engine/minebbs.py b/plugin/engine/minebbs.py new file mode 100644 index 0000000..5b59821 --- /dev/null +++ b/plugin/engine/minebbs.py @@ -0,0 +1,10 @@ +import typing + +from plugin.engine.base import SearchResult +from plugin.engine.bing import Bing + + +class Minebbs(Bing): + + def search(self, keywords) -> typing.List[SearchResult]: + return super()._search(keywords, site="minebbs.com")[:4] # 一般来将,前五个才有价值 # 四个吧 diff --git a/plugin/engine/spigotmc.py b/plugin/engine/spigotmc.py index e69de29..490005d 100644 --- a/plugin/engine/spigotmc.py +++ b/plugin/engine/spigotmc.py @@ -0,0 +1,28 @@ +import typing + +from plugin.engine.base import SearchEngine, SearchResult +from plugin.utils.translate import translate, EN +import requests +import json + + +class SpigotResult(SearchResult): + def __init__(self, url, title, summary, count): + super().__init__(url, title, summary) + self.count = count + + +class Spigot(SearchEngine): + def search(self, keywords) -> typing.List[SearchResult]: + key = translate(keywords, EN) + data = json.loads(requests.get( + f"https://fof1092.de/Plugins/SSE/resourceSearchV2.php?SearchText={key}").content) + result = [] + for plug in data: + result.append( + SpigotResult(url=plug["url"], title=plug["name"], summary=plug["tag"], count=plug["download"]["count"])) + result.sort(key=lambda obj: obj.count,reverse=True) + result = result[:16] + for plug in result: + plug.summary = translate(plug.summary) + return result