fix
This commit is contained in:
parent
6bcaa91a2c
commit
67e38759d7
4
run.py
4
run.py
@ -8,11 +8,11 @@ logger = setup_logging(__name__)
|
||||
async def main():
|
||||
# 配置下载参数
|
||||
#manga_url = "https://rouman5.com/books/cm693tf2z0170dr07ve0hpa7s"
|
||||
manga_list_url = "https://rouman5.com/books?continued=true"
|
||||
manga_list_url = "https://rouman5.com/books?continued=undefined"
|
||||
|
||||
# 开始下载
|
||||
#await MangaManager().download_manga(manga_url)
|
||||
for i in range(0,70):
|
||||
for i in range(0,77):
|
||||
await MangaManager().download_list_manga(f"{manga_list_url}&page={i}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
class MangaException(Exception):
|
||||
"""漫画下载相关异常的基类"""
|
||||
pass
|
||||
exit
|
||||
|
||||
class NetworkError(MangaException):
|
||||
"""网络相关错误"""
|
||||
|
||||
@ -84,6 +84,8 @@ class ListManga(BaseModel):
|
||||
list_url.append(HttpUrl("https://rouman5.com" + url))
|
||||
return list_url
|
||||
|
||||
created_at: List[str] = []
|
||||
|
||||
class MangaInfo(BaseModel):
|
||||
project: str
|
||||
"""漫画项目名称"""
|
||||
|
||||
@ -7,6 +7,7 @@ selectors:
|
||||
manga_list:
|
||||
title: '//div[@class="truncate text-foreground"]/text()'
|
||||
url: '//main//div[@class="grid grid-cols-1 sm:grid-cols-4 md:grid-cols-6 gap-2 sm:gap-4"]//a/@href'
|
||||
created_at: '//div[@class="grid grid-cols-1 sm:grid-cols-4 md:grid-cols-6 gap-2 sm:gap-4"]//a//div[@class="flex items-center space-x-1 justify-end"]/div[2]/text()'
|
||||
manga_info:
|
||||
title: '//div[@class="basis-3/5 text-sm sm:text-base"]//div[@class="text-xl text-foreground"]/text()'
|
||||
author:
|
||||
|
||||
@ -73,9 +73,6 @@ class MangaManager:
|
||||
if not chapter.status == "downloaded":
|
||||
total += 1
|
||||
total_chapters = total
|
||||
# 找到0个章节则证明已全部下载跳过
|
||||
if total == 0: MangaUtils().add_manga(manga_name)
|
||||
else: MangaUtils().delete_manga(manga_name)
|
||||
logger.info(f"找到 {total_chapters} 个章节")
|
||||
manga_item.chapters.extend(chapters) # 添加章节到 MangaItem
|
||||
yield {
|
||||
@ -155,18 +152,19 @@ class MangaManager:
|
||||
raise MangaException(f"不支持的网站: {manga_url}")
|
||||
async with list_site_handler() as site:
|
||||
manga_list = await site.get_manga_list(manga_url)
|
||||
for title,url in zip(manga_list.title, manga_list.url):
|
||||
for title,url,created_at in zip(manga_list.title, manga_list.url, manga_list.created_at):
|
||||
title = FileNaming.chinese_file_name(title)
|
||||
save_manga = MangaUtils().search_manga(title)
|
||||
if save_manga != None:
|
||||
created = save_manga.get('created_at', None)
|
||||
if created != None and created_at == created:
|
||||
logger.info(f"{save_manga} 已存在")
|
||||
else:
|
||||
logger.info(f"开始下载 漫画: {title}")
|
||||
logger.info(f"{url}")
|
||||
await self.download_manga(str(url))
|
||||
await self.download_manga(str(url), title = title, created_at = created_at)
|
||||
|
||||
@classmethod
|
||||
async def download_manga(cls, url: str, save_dir: Path = BASE_IMAGES_DIR):
|
||||
async def download_manga(cls, url: str, title: str, created_at: str, save_dir: Path = BASE_IMAGES_DIR):
|
||||
"""下载漫画"""
|
||||
manager = MangaManager(save_dir)
|
||||
|
||||
@ -200,6 +198,10 @@ class MangaManager:
|
||||
elif result['type'] == 'error':
|
||||
logger.error(f"下载出错: {result['error']}")
|
||||
|
||||
# 全部下载完成
|
||||
if int(total_chapters) == int(completed_chapters):
|
||||
MangaUtils().add_manga(title, created_at=created_at)
|
||||
logger.info(f"全部完成 {title}, {created_at}")
|
||||
except MangaException as e:
|
||||
logger.error(f"下载失败: {str(e)}")
|
||||
except Exception as e:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user