This commit is contained in:
cwx committed 2022-12-11 22:12:06 +08:00
1 parent d008efadcf
commit 234afcff7a
3 files changed
+31 -104

No files matched your search

-88
View File
@@ -1,88 +0,0 @@
from fake_useragent import UserAgent
import requests, os, shutil,re,json
from lxml import html
from utils.comic.ComicStr import comicStr
from utils.FileUtils import fileUtils
class comicUtils:
comic_title = None
temp_url = ""
@classmethod
def setKeyValue(cls,name, c_value,bool_list=None):
count = 0
len_value = len(c_value)
if bool_list:
count += 1
if cls.comics.get(count) == None:
cls.comics[count] = {name: c_value}
else:
cls.comics[count].update({name: c_value})
else:
for x in range(0, len_value):
value = c_value[x]
count += 1
if cls.comics.get(count) == None:
cls.comics[count] = {name: value}
else:
cls.comics[count].update({name: value})
@classmethod
def listImgDownload(cls,save_dir_name, links):
print("save_dir_name:", save_dir_name)
print("list_link:", links)
len_links = len(links)
count = 1
for link in links:
print("link:",count,":", link)
file_cout = ("{:0>3d}".format(count))
file_path = os.path.join("Comic", save_dir_name,str(file_cout)+".jpg")
netUtils.download(link, file_path)
count += 1
@classmethod
def downloadComic(cls,comic_name):
comic = fileUtils.read_comic(comic_name)
list_img = comic.get(comicStr.list_img)
len_list_img = len(list_img)
icon = comic.get(comicStr.icon)
for x in range(0, len_list_img):
chapter_img = list_img[x]
keys = chapter_img.keys()
for key in keys:
if not icon == None:
icon = netUtils.downloadComicIcon(comic_name,key,icon)
else:
print("icon已跳过")
netUtils.downloadComicChapterImages(comic_name, key, chapter_img[key])
'''
传入 comic_name读取配置文件中的各类信息
输出 "ComicInfo.xml" 并将图片打包成CBZ
'''
@classmethod
def packComicCBZ(cls,comic_name):
data = fileUtils.read_comic(comic_name)
title = data.get(comicStr.title)
author = data.get(comicStr.author)
author = str(author).replace("/",",").replace(" ","")
dep = data.get(comicStr.dep)
chapters = data.get(comicStr.chapters)
tags = "韩漫"
c_publisher = "韩漫"
print("title:", title,"author=",author,"dep=",dep,"chapters:",chapters)
for chapter in chapters:
CBZUtils.writeComicInfoXML(title, chapter, dep, author,
tags, c_publisher)
CBZUtils.packComicCBZ(title,chapter)
'''
获取网站主页
'''
@classmethod
def getBaseUrl(cls,url):
num = 3
index = 0
for x in range(0, num):
index = str(url).find("/",index)+1
return url[0:index-1]
+16 -1
View File
@@ -277,4 +277,19 @@ class comicInfo():
def nextExistsGetPath(cls,msg): def nextExistsGetPath(cls,msg):
path = cls.nextSavePath(msg) path = cls.nextSavePath(msg)
return os.path.exists(path) return os.path.exists(path)
@classmethod
def saveConfComicData(cls,fileName,data,comicName=None):
if not comicName == None:
cls.setComicName(comicName)
dirConfComic = cls.getDirConfComic()
save_path = os.path.join(dirConfComic,fileName)
cls.file_save(save_path, data)
@classmethod
def getPathInitConfComicData(cls,fileName,comicName=None):
if not comicName == None:
cls.setComicName(comicName)
dirConfComic = cls.getDirConfComic()
save_path = os.path.join(dirConfComic,fileName)
return save_path
+15 -15
View File
@@ -1,32 +1,37 @@
import json,os,time,random,shutil import json,os,time,random,shutil
from utils.ComicUtils import comicUtils
from utils.NetUtils import netUtils from utils.NetUtils import netUtils
from utils.HtmlUtils import htmlUtils from utils.HtmlUtils import htmlUtils
from utils.ImageUtils import imageUtils from utils.ImageUtils import imageUtils
from utils.comic.ComicInfo import comicInfo from utils.comic.ComicInfo import comicInfo
from utils.CBZUtils import CBZUtils from utils.CBZUtils import CBZUtils
from utils.downloader import download_images from utils.downloader import download_images
from utils.entity.BaseComicEntity import baseComic
class comicEntity: class comicEntity:
@classmethod @classmethod
def downladsComcis(cls,url): def baseComicData(cls,url):
#漫画名
data = htmlUtils.xpathData('//script[@id="__NEXT_DATA__"]/text()',url=url) data = htmlUtils.xpathData('//script[@id="__NEXT_DATA__"]/text()',url=url)
# #
data = json.loads(data[0]) data = json.loads(data[0])
data = data.get("props") data = data.get("props")
x = data.get("pageProps") x = data.get("pageProps")
return x
@classmethod
def downladsComcis(cls,url):
#漫画名
x = cls.baseComicData(url)
books = x.get("books") books = x.get("books")
len_books = len(books) len_books = len(books)
baseUrl = comicInfo.getBaseUrl(url) baseUrl = comicInfo.getBaseUrl(url)
for x in range(0, len_books): for x in range(0, len_books):
book = books[x] book = books[x]
#https://rm01.xyz/books/052426c3-ec7d-4035-b614-3c9290ee625b
book_id = book.get("id") book_id = book.get("id")
book_name = book.get("name") book_name = book.get("name")
comicHref = baseUrl+"/books/"+book_id updatedAt = book.get("updatedAt")
comicHref = baseUrl+"/books/"+book_id
random_int = random.uniform(5,20) random_int = random.uniform(5,20)
wait = print(f"{random_int}秒后开始下载 漫画:{book_name}") print(f"{random_int}秒后开始下载 漫画:{book_name}")
time.sleep(random_int) time.sleep(random_int)
cls.oneComic(comicHref, random.uniform(0,3)) cls.oneComic(comicHref, random.uniform(0,3))
@@ -131,12 +136,7 @@ class comicEntity:
@classmethod @classmethod
def comicChapterDownload(cls,chapter_url): def comicChapterDownload(cls,chapter_url):
#漫画名 x = cls.baseComicData(chapter_url)
data = htmlUtils.xpathData('//script[@id="__NEXT_DATA__"]/text()',url=chapter_url)
# #
data = json.loads(data[0])
data = data.get("props")
x = data.get("pageProps")
bookName = x.get("bookName") bookName = x.get("bookName")
chapterName = x.get("chapterName") chapterName = x.get("chapterName")
#fileUtils.saveConfComicChapterInfo(chapterName,x,bookName) #fileUtils.saveConfComicChapterInfo(chapterName,x,bookName)
@@ -156,7 +156,7 @@ class comicEntity:
comicInfo.writeComicInfoXML(chapterName) comicInfo.writeComicInfoXML(chapterName)
if not chapterAPIPath == None: if not chapterAPIPath == None:
base_url = comicUtils.getBaseUrl(chapter_url) base_url = comicInfo.getBaseUrl(chapter_url)
chapterAPIUrl = base_url+chapterAPIPath chapterAPIUrl = base_url+chapterAPIPath
data = htmlUtils.getJSON(chapterAPIUrl) data = htmlUtils.getJSON(chapterAPIUrl)
data = data.get("chapter") data = data.get("chapter")