-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[API] Add document unpacking for story content
- Loading branch information
Showing
6 changed files
with
92 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import asyncio | ||
from pathlib import Path | ||
|
||
from example.boilerplate import API, dumps | ||
from novelai_api.utils import decrypt_user_data | ||
|
||
dump_file = Path(__file__).parent.parent / "results" / "story.json" | ||
|
||
|
||
async def main(): | ||
async with API() as api_handler: | ||
api = api_handler.api | ||
key = api_handler.encryption_key | ||
|
||
keystore = await api.high_level.get_keystore(key) | ||
|
||
story = (await api.high_level.download_user_stories())[0] | ||
decrypt_user_data(story, keystore) | ||
|
||
storycontent_id = story["data"]["remoteStoryId"] | ||
|
||
story_contents = await api.low_level.download_object("storycontent", storycontent_id) | ||
decrypt_user_data(story_contents, keystore, True) | ||
|
||
dump_file.parent.mkdir(exist_ok=True) | ||
dump_file.write_text(dumps(story_contents), "utf-8") | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -712,14 +712,6 @@ class GlobalSettings: | |
".", | ||
":", | ||
"\n", | ||
"ve", | ||
"s", | ||
"t", | ||
"n", | ||
"d", | ||
"ll", | ||
"re", | ||
"m", | ||
"-", | ||
"*", | ||
")", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from typing import Any | ||
|
||
from msgpackr.constants import SKIP | ||
from msgpackr.unpack import MsgpackExtension | ||
|
||
|
||
class NAIExtension(MsgpackExtension): | ||
@classmethod | ||
def unpack(cls, _unpacker, _data: bytes, _pos: int, _length: int) -> Any: | ||
return SKIP | ||
|
||
# TODO: the data should be bundled in post_unpack | ||
|
||
@classmethod | ||
def pack(cls, _unpacker, data: Any) -> bytes: | ||
return data | ||
|
||
|
||
class Ext20(NAIExtension): | ||
EXT_TYPE = 20 | ||
|
||
|
||
class Ext30(NAIExtension): | ||
EXT_TYPE = 30 | ||
|
||
|
||
class Ext31(NAIExtension): | ||
EXT_TYPE = 31 | ||
|
||
|
||
class Ext40(NAIExtension): | ||
EXT_TYPE = 40 | ||
|
||
|
||
class Ext41(NAIExtension): | ||
EXT_TYPE = 41 | ||
|
||
|
||
class Ext42(NAIExtension): | ||
EXT_TYPE = 42 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters