-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
427 additions
and
4 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
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,80 @@ | ||
import codecs | ||
import json | ||
|
||
import PixivHelper | ||
from PixivException import PixivException | ||
|
||
MAX_LIMIT = 10 | ||
|
||
|
||
class PixivNovel: | ||
novel_id = 0 | ||
novel_json_str = "" | ||
content = "" | ||
title = "" | ||
|
||
def __init__(self, novel_id, novel_json) -> None: | ||
self.novel_id = novel_id | ||
self.novel_json_str = novel_json | ||
self.parse() | ||
|
||
def parse(self): | ||
js = json.loads(self.novel_json_str) | ||
if js["error"]: | ||
raise PixivException("Cannot get novel details", | ||
errorCode=PixivException.UNKNOWN_IMAGE_ERROR, | ||
htmlPage=self.novel_json_str) | ||
|
||
self.title = js["body"]["title"] | ||
self.content = js["body"]["content"] | ||
|
||
def write_content(self, filename): | ||
ft = open("novel_template.html") | ||
template_str = ft.read() | ||
ft.close() | ||
|
||
fh = None | ||
try: | ||
PixivHelper.makeSubdirs(filename) | ||
fh = codecs.open(filename, 'wb', encoding='utf-8') | ||
except IOError: | ||
fh = codecs.open(str(self.novel_id) + ".html", 'wb', encoding='utf-8') | ||
PixivHelper.get_logger().exception("Error when saving novel: %s, file is saved to: %s.html", filename, str(self.novel_id)) | ||
|
||
if fh is not None: | ||
content_str = template_str.replace("%title%", self.title) | ||
content_str = content_str.replace("%novel_json_str%", self.novel_json_str) | ||
fh.write(content_str) | ||
fh.close() | ||
|
||
|
||
class NovelSeries: | ||
series_id = 0 | ||
series_str = "" | ||
series_list = list() | ||
series_list_str = dict() | ||
total = 0 | ||
|
||
def __init__(self, series_id, series_json) -> None: | ||
self.series_id = series_id | ||
self.series_str = series_json | ||
|
||
self.parse() | ||
|
||
def parse(self): | ||
js = json.loads(self.series_str) | ||
if js["error"]: | ||
raise PixivException("Cannot get novel series content details", | ||
errorCode=PixivException.UNKNOWN_IMAGE_ERROR, | ||
htmlPage=self.series_str) | ||
self.total = js["body"]["total"] | ||
|
||
def parse_series_content(self, page_info, current_page): | ||
js = json.loads(page_info) | ||
if js["error"]: | ||
raise PixivException("Cannot get novel series content details", | ||
errorCode=PixivException.UNKNOWN_IMAGE_ERROR, | ||
htmlPage=page_info) | ||
|
||
self.series_list.extend(js["body"]["seriesContents"]) | ||
self.series_list_str[current_page] = page_info |
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,49 @@ | ||
import PixivHelper | ||
import PixivNovel | ||
|
||
|
||
def process_novel(caller, | ||
config, | ||
novel_id, | ||
notifier=None): | ||
if notifier is None: | ||
notifier = PixivHelper.dummy_notifier | ||
|
||
PixivHelper.print_and_log(None, f"Processing Novel details = {novel_id}") | ||
novel = caller.__br__.getNovelPage(novel_id) | ||
PixivHelper.print_and_log(None, f"Title = {novel.title}") | ||
filename = f"novel-{novel_id}.html" | ||
PixivHelper.print_and_log(None, f"Saving Novel details to = {filename}") | ||
novel.write_content(filename) | ||
|
||
|
||
def process_novel_series(caller, | ||
config, | ||
series_id, | ||
start_page=1, | ||
end_page=0, | ||
notifier=None): | ||
if notifier is None: | ||
notifier = PixivHelper.dummy_notifier | ||
PixivHelper.print_and_log(None, f"Processing Novel Series = {series_id}") | ||
|
||
novel_series = caller.__br__.getNovelSeries(series_id) | ||
page = start_page | ||
flag = True | ||
while(flag): | ||
PixivHelper.print_and_log(None, f"Getting page = {page}") | ||
novel_series = caller.__br__.getNovelSeriesContent(novel_series, current_page=page) | ||
page = page + 1 | ||
if end_page > 0 and page > end_page: | ||
PixivHelper.print_and_log(None, f"Page limit reached = {end_page}.") | ||
flag = False | ||
if (page * PixivNovel.MAX_LIMIT) >= novel_series.total: | ||
PixivHelper.print_and_log(None, "No more novel.") | ||
flag = False | ||
|
||
for novel in novel_series.series_list: | ||
print(novel["id"]) | ||
# process_novel(caller, | ||
# config, | ||
# novel_id=novel["id"], | ||
# notifier=notifier) |
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
Oops, something went wrong.