1 Star 3 Fork 1

senbinge / comic_downloader_cli

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
book.py 2.23 KB
一键复制 编辑 原始数据 按行查看 历史
senbinge 提交于 2021-09-27 16:02 . init
from chapter import Chapter
from os import path
import pickle
class Book:
def __init__(self,url,save_path=None) -> None:
super().__init__()
self.title=None
self.chapter_count=None
self.url=url
self.save_path=save_path
self.chapters=dict()
# self.completed=False
def is_completed(self):
# if len(self.chapters) < self.chapter_count:
# return False
if self.is_missing_chapter():
return False
for chapter in self.chapters.values():
if chapter.is_completed()==False:
return False
return True
def is_missing_chapter(self):
return not self.chapter_count or len(self.chapters) < self.chapter_count
def add_chapter(self,chapter:Chapter):
chapter.chapter_folder=path.join(self.get_book_folder(),chapter.title)
self.chapters[chapter.title]=chapter
def get_chapter(self,chapter_title):
return self.chapters.get(chapter_title,None)
def has_chapter(self,chater_title):
return chater_title in self.chapters
def get_book_folder(self):
if not self.title:
raise Exception('漫画名称未设置!')
if not self.save_path:
return self.title
else:
return path.join(self.save_path,self.title)
# def scan_chapter_progress(self):
def __getstate__(self):
state=self.__dict__.copy()
chapters=self.chapters.values()
state['chapters']=[chapter.to_dict() for chapter in chapters]
return state
def __setstate__(self,state):
chapters=state['chapters']
state['chapters']={}
self.__dict__.update(state)
for chapter in chapters:
ch=Chapter.from_dict(chapter)
self.add_chapter(ch)
return state
def save(self):
book_path=path.join(self.get_book_folder(),'book.dat')
with open(book_path,'wb') as f:
pickle.dump(self,f)
@staticmethod
def load(book_path:str):
if book_path.endswith('book.dat') ==False:
book_path=path.join(book_path,'book.dat')
with open(book_path,'rb') as f:
return pickle.load(f)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/senbinge/comic_downloader_cli.git
git@gitee.com:senbinge/comic_downloader_cli.git
senbinge
comic_downloader_cli
comic_downloader_cli
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891