4
4
5
5
from aiohttp import ClientSession
6
6
from PicImageSearch import SauceNAO
7
+ from yarl import URL
7
8
8
9
from .ascii2d import ascii2d_search
9
10
from .config import config
@@ -40,7 +41,6 @@ async def saucenao_search(
40
41
final_res = []
41
42
if res and res .raw :
42
43
selected_res = res .raw [0 ]
43
- ext_urls = selected_res .origin ["data" ].get ("ext_urls" )
44
44
# 如果结果为 pixiv ,尝试找到原始投稿,避免返回盗图者的投稿
45
45
if selected_res .index_id == saucenao_db ["pixiv" ]:
46
46
pixiv_res_list = list (
@@ -57,29 +57,25 @@ async def saucenao_search(
57
57
key = lambda x : int (re .search (r"\d+" , x .url ).group ()), # type: ignore
58
58
)
59
59
# 如果地址有多个,优先取 danbooru
60
- elif ext_urls and len (ext_urls ) > 1 :
61
- for i in ext_urls :
60
+ elif len (selected_res . ext_urls ) > 1 :
61
+ for i in selected_res . ext_urls :
62
62
if "danbooru" in i :
63
63
selected_res .url = i
64
64
_hide_img = hide_img or selected_res .hidden
65
65
if selected_res .similarity < config .saucenao_low_acc :
66
66
_hide_img = _hide_img or config .hide_img_when_low_acc
67
67
thumbnail = await handle_img (selected_res .thumbnail , _hide_img )
68
- if _source := selected_res .origin ["data" ].get ("source" , "" ):
69
- source = await shorten_url (_source )
70
- else :
71
- source = await shorten_url (await get_source (selected_res .url ))
72
- # 如果结果为 doujin ,尝试返回日文标题而不是英文标题
73
- if selected_res .index_id in saucenao_db ["doujin" ]: # type: ignore
74
- if title := (
75
- selected_res .origin ["data" ].get ("jp_name" )
76
- or selected_res .origin ["data" ].get ("eng_name" )
77
- ):
78
- selected_res .title = title
68
+ source = selected_res .source
69
+ if source and source == selected_res .title :
70
+ source = ""
71
+ if not source and selected_res .url :
72
+ source = await get_source (selected_res .url )
73
+ if source and URL (source ).host :
74
+ source = await shorten_url (source )
79
75
_url = await shorten_url (selected_res .url )
80
76
author = selected_res .author
81
- if author and selected_res .index_id == saucenao_db [ "pixiv" ] :
82
- author = f' [{ author } ](https://pixiv.net/u/ { selected_res .origin [ "data" ][ "member_id" ] } )'
77
+ if author and selected_res .author_url :
78
+ author = f" [{ author } ]({ await shorten_url ( selected_res .author_url ) } )"
83
79
res_list = [
84
80
f"SauceNAO ({ selected_res .similarity } %)" ,
85
81
thumbnail ,
0 commit comments