Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Problem) Now AppPixivAPI.novel_text method is not available #337

Closed
xiyihan0 opened this issue Feb 29, 2024 · 4 comments
Closed

(Problem) Now AppPixivAPI.novel_text method is not available #337

xiyihan0 opened this issue Feb 29, 2024 · 4 comments
Labels

Comments

@xiyihan0
Copy link
Contributor

Tested on PixivPy 3.7.0:

_ACCESS_TOKEN = ""
_REFRESH_TOKEN = ""
from pixivpy3 import *
api = AppPixivAPI()
api.set_auth(access_token = _ACCESS_TOKEN,refresh_token=_REFRESH_TOKEN)
res = api.novel_text(21269184)
print(res) #{'error': {'user_message': "Specified end-point doesn't exist", 'message': '', 'reason': '', 'user_message_details': {}}}

This method has been affected since the latest update of Pixiv APP.

@xiyihan0
Copy link
Contributor Author

A possible patch:

import json
class AppPixivAPI(BasePixivAPI):
    ...
    def novel_text(self, novel_id: int | str, req_auth: bool = True) -> ParsedJson:
        url = "%s/webview/v2/novel" % self.hosts
        params = {
            "id": novel_id
        }
        r = self.no_auth_requests_call("GET", url, params=params, req_auth=req_auth)
        return {"novel_text": json.loads(re.search("novel:\s({.+}),\s+isOwnWork", r.text).groups()[0].encode())["text"]}

@upbit upbit added the bug label Mar 1, 2024
@upbit
Copy link
Owner

upbit commented Mar 1, 2024

Thank you for the reminder. I will verify the v2 API and update a version later.

@upbit
Copy link
Owner

upbit commented Mar 3, 2024

We currently have two methods to obtain the text of the novel. One is the https://www.pixiv.net/ajax/novel/{novel_id} mentioned in #264 (no authentication required?). However, the data returned by this interface is quite extensive and not very compatible with the novel_text.

Another option is /webview/v2/novel, the interface currently used by the iOS app behaves as follows:

GET /webview/v2/novel?id=21630272&font=mincho&font_size=1.0em&line_height=1.8&color=%231F1F1F&background_color=%23FFFFFF&mode=horizontal&theme=light&margin_top=60px&margin_bottom=50px&viewer_version=20221031_ai HTTP/1.1
Host: app-api.pixiv.net
-------------------------------
HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8

<!DOCTYPE html><html lang="zh"><head><title>pixiv</title><link rel="canonical" href="/novel/show.php?id=21630272"><meta name="robots" content="noindex"><meta http-equiv="content-type" content="text/html; charset=utf-8"><script>
            Object.defineProperty(window, 'pixiv', {
                value: {
                    viewerVersion: "20221031_ai",
                    isV2: true,
                    userLang: "zh",
                    novel: 
{"id":"21630272","title":"\u4ffa\u306e\u4e8b\u304c\u5927\u597d\u304d\u306a\u5148\u8f29\u5f8c\u8f29\u3061\u3083\u3093\u304c\u3072\u305f\u3059\u3089\u80b2\u4e73\u3057\u3066\u8d85\u7206\u4e73\u306b\u306a\u308b\u8a71","seriesId":null,"seriesTitle":null,"seriesIsWatched":null,"userId":"32020681","coverUrl":"https:\/\/i.pximg.net\/c\/240x480_80\/novel-cover-master\/img\/2024\/02\/25\/15\/07\/26\/ci21630272_2f4d16677b64694b8fe208a141b34d91_master1200.jpg","tags":["R-18"],...}

It appears that this interface returns an HTML, which includes the novel text and formatting. Therefore, in addition to parsing the text section, I will make novel_text API provide a raw={False|True} parameter that returns the complete HTML formatted content.

upbit added a commit that referenced this issue Mar 3, 2024
Bump version to 3.7.5, and closed issue #337
@upbit
Copy link
Owner

upbit commented Mar 3, 2024

fixed in v3.7.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants