Skip to content

Commit

Permalink
aapi中search_illust/novel添加search_ai_type参数 (#318)
Browse files Browse the repository at this point in the history
* aapi中search_illust/novel添加search_ai_type参数

* Update demo.py

* Update aapi.py

在aapi中增加user_edit_ai_show_settings方法

* Update aapi.py
  • Loading branch information
xiyihan0 authored Dec 29, 2023
1 parent 5daed39 commit e6e1e91
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ def appapi_search(aapi):
novel = json_result.novels[0]
print(">>> {}, origin url: {}".format(novel.title, novel.image_urls["large"]))

json_result = aapi.search_illust("AI生成", search_target="exact_match_for_tags", search_ai_type=0)
# 关闭AI搜索选项后,将过滤掉所有illust_ai_type=2的插画,而illust_ai_type=1 or 0 的插画将被保留
# 但是,加入了"AI生成"的tag却没有在作品提交时打开“AI生成”的开关的作品不会被筛选出结果列表
print(json_result["illusts"][0])


def appapi_user_search(aapi):
json_result = aapi.illust_ranking("day_male")
Expand Down
15 changes: 15 additions & 0 deletions pixivpy3/aapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ def trending_tags_illust(self, filter: _FILTER = "for_ios", req_auth: bool = Tru
# title_and_caption - 标题说明文
# sort: [date_desc, date_asc, popular_desc] - popular_desc为会员的热门排序
# duration: [within_last_day, within_last_week, within_last_month]
# search_ai_type: 0|1 (0: 过滤AI生成作品, 1: 显示AI生成作品)
# start_date, end_date: '2020-07-01'
def search_illust(
self,
Expand All @@ -468,6 +469,7 @@ def search_illust(
start_date: str | None = None,
end_date: str | None = None,
filter: _FILTER = "for_ios",
search_ai_type: Literal[0, 1] | None = None,
offset: int | str | None = None,
req_auth: bool = True,
) -> ParsedJson:
Expand All @@ -484,6 +486,8 @@ def search_illust(
params["end_date"] = end_date
if duration:
params["duration"] = duration
if search_ai_type:
params["search_ai_type"] = search_ai_type
if offset:
params["offset"] = offset
r = self.no_auth_requests_call("GET", url, params=params, req_auth=req_auth)
Expand All @@ -496,6 +500,7 @@ def search_illust(
# text - 正文
# keyword - 关键词
# sort: [date_desc, date_asc]
# search_ai_type: 0|1 (0: 过滤AI生成作品, 1: 显示AI生成作品)
# start_date/end_date: 2020-06-01
def search_novel(
self,
Expand All @@ -507,6 +512,7 @@ def search_novel(
start_date: str | None = None,
end_date: str | None = None,
filter: str | None = None,
search_ai_type: Literal[0, 1] | None = None,
offset: int | str | None = None,
req_auth: bool = True,
) -> ParsedJson:
Expand All @@ -523,6 +529,8 @@ def search_novel(
params["start_date"] = start_date
if end_date:
params["end_date"] = end_date
if search_ai_type:
params["search_ai_type"] = search_ai_type
if offset:
params["offset"] = offset
r = self.no_auth_requests_call("GET", url, params=params, req_auth=req_auth)
Expand Down Expand Up @@ -608,6 +616,13 @@ def user_follow_delete(self, user_id: int | str, req_auth: bool = True) -> Parse
r = self.no_auth_requests_call("POST", url, data=data, req_auth=req_auth)
return self.parse_result(r)

# 设置用户选项中是否展现AI生成作品
def user_edit_ai_show_settings(self, setting: _BOOL, req_auth: bool = True) -> ParsedJson:
url = "%s/v1/user/ai-show-settings/edit" % self.hosts
data = {"show_ai": setting}
r = self.no_auth_requests_call("POST", url, data=data, req_auth=req_auth)
return self.parse_result(r)

# 用户收藏标签列表
def user_bookmark_tags_illust(
self,
Expand Down

0 comments on commit e6e1e91

Please sign in to comment.