Skip to content

Commit

Permalink
fix some glitches
Browse files Browse the repository at this point in the history
  • Loading branch information
asadahimeka committed Mar 9, 2024
1 parent d20f99a commit 9408dea
Showing 1 changed file with 17 additions and 26 deletions.
43 changes: 17 additions & 26 deletions hibiapi/api/pixiv/api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json
import re
from datetime import date, timedelta
from enum import Enum
from typing import Any, Dict, Optional, cast
Expand All @@ -7,10 +9,7 @@
from hibiapi.utils.cache import cache_config
from hibiapi.utils.decorators import enum_auto_doc
from hibiapi.utils.net import catch_network_error
from hibiapi.utils.routing import BaseEndpoint, dont_route, request_headers

import json
import re
from hibiapi.utils.routing import BaseEndpoint, dont_route, request_headers, response_headers


@enum_auto_doc
Expand Down Expand Up @@ -270,7 +269,7 @@ async def search(
page: int = 1,
size: int = 30,
include_translated_tag_results: bool = True,
search_ai_type: int = None, # 0: 过滤 AI 生成作品, 1: 反之
search_ai_type: bool = True, # 搜索结果是否包含AI作品
):
return await self.request(
"v1/search/illust",
Expand All @@ -281,7 +280,7 @@ async def search(
"duration": duration,
"offset": (page - 1) * size,
"include_translated_tag_results": include_translated_tag_results,
"search_ai_type": search_ai_type,
"search_ai_type": 1 if search_ai_type else 0,
},
)

Expand Down Expand Up @@ -488,18 +487,20 @@ async def webview_novel(self, *, id: int, raw: bool = False):
response = await self.request(
"webview/v2/novel",
params={
"id": id,
"viewer_version": "20221031_ai",
"id": id,
"viewer_version": "20221031_ai",
},
return_text=True,
)
if raw:
# 直接返回 HTML,但是返回头 content-type 还是 application/json
# 可能需要修改为 text/html
# 直接返回 HTML
response_headers.get().setdefault("content-type", "text/html; charset=UTF-8")
return response

Check warning on line 498 in hibiapi/api/pixiv/api.py

View check run for this annotation

Codecov / codecov/patch

hibiapi/api/pixiv/api.py#L497-L498

Added lines #L497 - L498 were not covered by tests

try:
novel_json = re.search(r"novel:\s({.+}),\s+isOwnWork", response).groups()[0].encode()
novel_json = (
re.search(r"novel:\s({.+}),\s+isOwnWork", response).groups()[0].encode()
)
return json.loads(novel_json)
except Exception as e:
return {"error": "Parsing novel error: %s" % e}

Check warning on line 506 in hibiapi/api/pixiv/api.py

View check run for this annotation

Codecov / codecov/patch

hibiapi/api/pixiv/api.py#L505-L506

Added lines #L505 - L506 were not covered by tests
Expand All @@ -519,7 +520,7 @@ async def search_novel(
duration: Optional[SearchDurationType] = None,
page: int = 1,
size: int = 30,
search_ai_type: int = None, # 0: 过滤 AI 生成作品, 1: 反之
search_ai_type: bool = True, # 搜索结果是否包含AI作品
):
return await self.request(
"/v1/search/novel",
Expand All @@ -531,7 +532,7 @@ async def search_novel(
"include_translated_tag_results": include_translated_tag_results,
"duration": duration,
"offset": (page - 1) * size,
"search_ai_type": search_ai_type,
"search_ai_type": 1 if search_ai_type else 0,
},
)

Expand Down Expand Up @@ -586,28 +587,18 @@ async def related_member(self, *, id: int):
async def illust_series(self, *, id: int, page: int = 1, size: int = 30):
return await self.request(
"v1/illust/series",
params={
"illust_series_id": id,
"offset": (page - 1) * size
},
params={"illust_series_id": id, "offset": (page - 1) * size},
)

# 用户的漫画系列
async def member_illust_series(self, *, id: int, page: int = 1, size: int = 30):
return await self.request(
"v1/user/illust-series",
params={
"user_id": id,
"offset": (page - 1) * size
},
params={"user_id": id, "offset": (page - 1) * size},
)

# 用户的小说系列
async def member_novel_series(self, *, id: int, page: int = 1, size: int = 30):
return await self.request(
"v1/user/novel-series",
params={
"user_id": id,
"offset": (page - 1) * size
}
"v1/user/novel-series", params={"user_id": id, "offset": (page - 1) * size}
)

0 comments on commit 9408dea

Please sign in to comment.