This commit is contained in:
cwx 2022-12-22 21:01:38 +08:00
parent b9c5c352c6
commit 1760bc82f8
5 changed files with 24 additions and 13 deletions

View File

@ -3,7 +3,7 @@ from utils.comic.ComicInfo import comicInfo
import os,shutil import os,shutil
def comics(): def comics():
for x in range(0,5): for x in range(0,30):
comicEntity.downladsComcis("https://rm01.xyz/books?&page="+str(x)) comicEntity.downladsComcis("https://rm01.xyz/books?&page="+str(x))
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -1,5 +1,5 @@
from fake_useragent import UserAgent from fake_useragent import UserAgent
import requests,os import requests,os,json
from lxml import html from lxml import html
import traceback import traceback
import time import time
@ -68,7 +68,8 @@ class htmlUtils:
if type == "bytes": if type == "bytes":
url_text = res url_text = res
if type == "json": if type == "json":
url_text = res.json() #url_text = res.json()
url_text = json.loads(res.text)
cls.saveHtml(curl,res.text) cls.saveHtml(curl,res.text)
if type == None: if type == None:
url_text = html.fromstring(res.text) url_text = html.fromstring(res.text)
@ -91,7 +92,9 @@ class htmlUtils:
@classmethod @classmethod
def getJSON(cls,url): def getJSON(cls,url):
return cls.getHTML(url,type="json") url_text = requests.get(url,headers=cls.headers, timeout=180).text
return json.loads(url_text)
#return cls.getHTML(url,type="json")
@classmethod @classmethod
def xpathData(cls,c_xpath,url=None,num=None,not_eq=None,update=False): def xpathData(cls,c_xpath,url=None,num=None,not_eq=None,update=False):

View File

@ -249,7 +249,10 @@ class comicInfo():
dir_name = os.path.dirname(path) dir_name = os.path.dirname(path)
if not os.path.exists(dir_name): if not os.path.exists(dir_name):
os.makedirs(dir_name) os.makedirs(dir_name)
save_path = os.path.join(path) save_path = os.path.join(path)
if os.path.exists(save_path):
os.remove(save_path)
data = json.dumps(data) data = json.dumps(data)
if mode == None: if mode == None:
mode = "w+" mode = "w+"
@ -261,6 +264,7 @@ class comicInfo():
result = path + "文件写入成功" result = path + "文件写入成功"
except: except:
result = path + "文件写入失败" result = path + "文件写入失败"
print(result)
return result return result
@classmethod @classmethod

View File

@ -1,8 +1,8 @@
import os,datetime import os,datetime
from time import strftime from time import strftime
class pathStr: class pathStr:
base_comic_out = "COMICOUT" #base_comic_out = "COMICOUT"
#base_comic_out = os.path.join("/mnt", "bigTComics") base_comic_out = os.path.join("/mnt", "bigTComics")
base_CBZ = os.path.join(base_comic_out,"CBZ") base_CBZ = os.path.join(base_comic_out,"CBZ")
base_comic_img = os.path.join(base_comic_out,"outputComic") base_comic_img = os.path.join(base_comic_out,"outputComic")
base_conf_path = os.path.join(base_comic_out,".conf") base_conf_path = os.path.join(base_comic_out,".conf")

View File

@ -56,7 +56,7 @@ class comicEntity:
@classmethod @classmethod
def oneComic(cls,c_url,sleep=None): def oneComic(cls,c_url,sleep=None):
#漫画名 #漫画名
title = htmlUtils.xpathData('//div[@class="col"]/h5/text()',url=c_url,num=0) title = htmlUtils.xpathData('//div[@class="col"]/h5/text()',url=c_url,num=0,update=True)
#别名 #别名
alias = htmlUtils.xpathData('//span[contains(@class,"bookid_alias")]/text()',num=1) alias = htmlUtils.xpathData('//span[contains(@class,"bookid_alias")]/text()',num=1)
icon = htmlUtils.xpathData('//img[@class="img-thumbnail"]/@src',num=0) icon = htmlUtils.xpathData('//img[@class="img-thumbnail"]/@src',num=0)
@ -67,7 +67,7 @@ class comicEntity:
dep = htmlUtils.xpathData('//div[contains(@class,"bookid_bookInfo")]/p[4]/text()',num=1) dep = htmlUtils.xpathData('//div[contains(@class,"bookid_bookInfo")]/p[4]/text()',num=1)
update_date = htmlUtils.xpathData('//div[contains(@class,"bookid_bookInfo")]/p[5]/small/text()',num=1) update_date = htmlUtils.xpathData('//div[contains(@class,"bookid_bookInfo")]/p[5]/small/text()',num=1)
chapters = htmlUtils.xpathData('//div[contains(@class,"bookid_chapterBox")]//div[contains(@class,"bookid_chapter")]/a/text()') chapters = htmlUtils.xpathData('//div[contains(@class,"bookid_chapterBox")]//div[contains(@class,"bookid_chapter")]/a/text()')
chapter_href = htmlUtils.xpathData('//div[contains(@class,"bookid_chapterBox")]//div[contains(@class,"bookid_chapter")]/a/@href', update=True) chapter_href = htmlUtils.xpathData('//div[contains(@class,"bookid_chapterBox")]//div[contains(@class,"bookid_chapter")]/a/@href')
author = str(author).replace("&",",").replace(" ",",") author = str(author).replace("&",",").replace(" ",",")
comicInfo.setHomePage(c_url) comicInfo.setHomePage(c_url)
@ -168,7 +168,6 @@ class comicEntity:
description = x.get("description") description = x.get("description")
images = x.get("images") images = x.get("images")
chapterAPIPath = x.get("chapterAPIPath") chapterAPIPath = x.get("chapterAPIPath")
chapterAPIPath = str(chapterAPIPath).encode('utf-8').decode('unicode_escape')
comicInfo.setComicName(bookName) comicInfo.setComicName(bookName)
comicInfo.setChapterName(chapterName) comicInfo.setChapterName(chapterName)
comicInfo.setDep(description) comicInfo.setDep(description)
@ -177,11 +176,13 @@ class comicEntity:
#print("不存在ComicInfo.xml 生成中...") #print("不存在ComicInfo.xml 生成中...")
comicInfo.writeComicInfoXML(chapterName) comicInfo.writeComicInfoXML(chapterName)
if chapterAPIPath != None: if not chapterAPIPath == None:
chapterAPIPath = str(chapterAPIPath).encode('utf-8').decode('unicode_escape')
base_url = comicInfo.getBaseUrl(chapter_url) base_url = comicInfo.getBaseUrl(chapter_url)
chapterAPIUrl = base_url+chapterAPIPath chapterAPIUrl = base_url+chapterAPIPath
ntfy.sendMsg(f"chapterApiUrl= {chapterAPIUrl}") ntfy.sendMsg(f"chapterApiUrl= {chapterAPIUrl}")
data = json.loads(htmlUtils.getJSON(chapterAPIUrl)) data = htmlUtils.getJSON(chapterAPIUrl)
print(data)
data = data.get("chapter") data = data.get("chapter")
chapterName = data.get("name") chapterName = data.get("name")
images = data.get("images") images = data.get("images")
@ -227,8 +228,11 @@ class comicEntity:
ntfy.sendMsg(f"{bookName} {chapterName} 数据不完整尝试删除配置CBZ文件后重试") ntfy.sendMsg(f"{bookName} {chapterName} 数据不完整尝试删除配置CBZ文件后重试")
htmlUtils.remove_HtmlCache(chapter_url) htmlUtils.remove_HtmlCache(chapter_url)
try: try:
if cbz_size < len(list_img):
ntfy.sendMsg(f"删除 {cbz_path}") ntfy.sendMsg(f"删除 {cbz_path}")
os.remove(cbz_path) #os.remove(cbz_path)
else:
is_next = False
except: except:
ntfy(f"删除失败 {cbz_path}") ntfy(f"删除失败 {cbz_path}")
if is_next: if is_next: