This commit is contained in:
caiwx86 2025-02-04 21:16:17 +08:00
parent 6bcaa91a2c
commit 67e38759d7
5 changed files with 17 additions and 12 deletions

4
run.py
View File

@ -8,11 +8,11 @@ logger = setup_logging(__name__)
async def main(): async def main():
# 配置下载参数 # 配置下载参数
#manga_url = "https://rouman5.com/books/cm693tf2z0170dr07ve0hpa7s" #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) #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}") await MangaManager().download_list_manga(f"{manga_list_url}&page={i}")
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -2,7 +2,7 @@
class MangaException(Exception): class MangaException(Exception):
"""漫画下载相关异常的基类""" """漫画下载相关异常的基类"""
pass exit
class NetworkError(MangaException): class NetworkError(MangaException):
"""网络相关错误""" """网络相关错误"""

View File

@ -84,6 +84,8 @@ class ListManga(BaseModel):
list_url.append(HttpUrl("https://rouman5.com" + url)) list_url.append(HttpUrl("https://rouman5.com" + url))
return list_url return list_url
created_at: List[str] = []
class MangaInfo(BaseModel): class MangaInfo(BaseModel):
project: str project: str
"""漫画项目名称""" """漫画项目名称"""

View File

@ -7,6 +7,7 @@ selectors:
manga_list: manga_list:
title: '//div[@class="truncate text-foreground"]/text()' 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' 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: manga_info:
title: '//div[@class="basis-3/5 text-sm sm:text-base"]//div[@class="text-xl text-foreground"]/text()' title: '//div[@class="basis-3/5 text-sm sm:text-base"]//div[@class="text-xl text-foreground"]/text()'
author: author:

View File

@ -15,7 +15,7 @@ logger = setup_logging(__name__)
class MangaManager: class MangaManager:
"""漫画下载管理器""" """漫画下载管理器"""
SITE_MAP: Dict[str, Type[BaseSite]] = { SITE_MAP: Dict[str, Type[BaseSite]] = {
# 'manhuagui.com': ManhuaguiSite, # 'manhuagui.com': ManhuaguiSite,
'roum20.xyz': RoumanSite, 'roum20.xyz': RoumanSite,
@ -73,9 +73,6 @@ class MangaManager:
if not chapter.status == "downloaded": if not chapter.status == "downloaded":
total += 1 total += 1
total_chapters = total total_chapters = total
# 找到0个章节则证明已全部下载跳过
if total == 0: MangaUtils().add_manga(manga_name)
else: MangaUtils().delete_manga(manga_name)
logger.info(f"找到 {total_chapters} 个章节") logger.info(f"找到 {total_chapters} 个章节")
manga_item.chapters.extend(chapters) # 添加章节到 MangaItem manga_item.chapters.extend(chapters) # 添加章节到 MangaItem
yield { yield {
@ -155,18 +152,19 @@ class MangaManager:
raise MangaException(f"不支持的网站: {manga_url}") raise MangaException(f"不支持的网站: {manga_url}")
async with list_site_handler() as site: async with list_site_handler() as site:
manga_list = await site.get_manga_list(manga_url) 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) title = FileNaming.chinese_file_name(title)
save_manga = MangaUtils().search_manga(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} 已存在") logger.info(f"{save_manga} 已存在")
else: else:
logger.info(f"开始下载 漫画: {title}") logger.info(f"开始下载 漫画: {title}")
logger.info(f"{url}") logger.info(f"{url}")
await self.download_manga(str(url)) await self.download_manga(str(url), title = title, created_at = created_at)
@classmethod @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) manager = MangaManager(save_dir)
@ -199,7 +197,11 @@ class MangaManager:
elif result['type'] == 'error': elif result['type'] == 'error':
logger.error(f"下载出错: {result['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: except MangaException as e:
logger.error(f"下载失败: {str(e)}") logger.error(f"下载失败: {str(e)}")
except Exception as e: except Exception as e: