Skip to content

Commit

Permalink
Merge pull request #131 from Zeal-L/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Zeal-L authored Mar 31, 2024
2 parents cdc3680 + af92f4e commit ada825d
Show file tree
Hide file tree
Showing 9 changed files with 7,556 additions and 7,596 deletions.
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 30 additions & 13 deletions src/BiliPlus.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from typing import TYPE_CHECKING

import time
import requests
from bs4 import BeautifulSoup
from retrying import retry
Expand Down Expand Up @@ -72,7 +73,7 @@ def retrieveAvailableEpisode(self, episodes: list[BiliPlusEpisode], comic_id: st
biliplus_html = ""

@retry(stop_max_delay=MAX_RETRY_SMALL, wait_exponential_multiplier=RETRY_WAIT_EX)
def _(url: str) -> str | None:
def _(url: str) -> str:
try:
res = requests.post(
url,
Expand All @@ -83,27 +84,25 @@ def _(url: str) -> str | None:
logger.warning(f"漫画id:{self.comic_id} 在BiliPlus获取漫画信息失败! 重试中...\n{e}")
raise e
if "未登录" in res.text:
self.mainGUI.signal_message_box.emit(
"您的BiliPlus Cookie无效,请更新您的BiliPlus Cookie"
)
return None
return "cookie invalid"
if 'src="http' not in res.text:
self.mainGUI.signal_message_box.emit(
"BiliPlus无此漫画的缓存记录\n"
"请在BiliPlus的该漫画详情页面使用功能“获取未缓存索引”后重试"
)
return None
return ""
if res.status_code != 200:
logger.warning(
f"漫画id:{self.comic_id} 在BiliPlus爬取漫画信息失败! "
"状态码:{res.status_code}, 理由: {res.reason} 重试中..."
f"状态码:{res.status_code}, 理由: {res.reason} 重试中..."
)
raise requests.HTTPError()
return res.text

try:
biliplus_html = _(biliplus_detail_url)
if None is biliplus_html:
if "" == biliplus_html:
return None
if "cookie invalid" == biliplus_html:
self.mainGUI.signal_message_box.emit(
"您的BiliPlus Cookie无效,请更新您的BiliPlus Cookie!"
)
return None
except requests.RequestException as e:
logger.error(f"漫画id:{self.comic_id} 在BiliPlus重复获取漫画信息多次后失败!\n{e}")
Expand Down Expand Up @@ -133,9 +132,26 @@ def _(url: str) -> str | None:
for ep in ep_items:
if ep.img["src"] != "about:blank":
ep_available.append(ep.a["href"].split("epid=")[1])

unlock_times = 0
for ep in episodes:
if str(ep.id) in ep_available:
if ep.available is False:
unlock_times += 1
ep.available = True

if len(ep_available) == 0:
msg = "BiliPlus无此漫画的缓存记录\n\n" \
"请在BiliPlus的该漫画详情页面使用功能“获取未缓存索引”后重试\n\n"
elif unlock_times != 0:
msg = f"BiliPlus为本漫画额外解锁{unlock_times}个章节\n\n"
else:
msg = "BiliPlus未能为此漫画解锁更多章节\n\n"
self.mainGUI.signal_information_box.emit(
f"{msg}Ciallo~(∠・ω< )⌒★\n"
"您的主动分享能温暖每一个漫画人\n"
"请在BiliPlus漫画主页进入功能“查看已购漫画”展示你的实力!"
)
except requests.RequestException as e:
msg = f"漫画id:{self.comic_id} 处理BiliPlus解锁章节数据多次后失败!"
logger.error(msg)
Expand Down Expand Up @@ -180,6 +196,7 @@ def init_imgsList(self) -> bool:
biliplus_img_url = (
f"https://www.biliplus.com/manga/?act=read&mangaid={self.comic_id}&epid={self.id}"
)
biliplus_img_url += f"&t={time.time()}"
biliplus_html = ""

@retry(stop_max_delay=MAX_RETRY_SMALL, wait_exponential_multiplier=RETRY_WAIT_EX)
Expand Down Expand Up @@ -221,7 +238,7 @@ def _() -> list[dict]:
# ? 解析BiliPlus解锁章节图片地址
try:
biliplus_imgs_token = []
if "获取凭证出错" in biliplus_html:
if "获取凭证出错" in biliplus_html and 'src="http' not in biliplus_html:
msg = f"《{self.comic_name}》章节:{self.title} " \
"在BiliPlus上的章节共享者已退出登陆,下载失败!"
logger.error(msg)
Expand Down
1 change: 0 additions & 1 deletion src/DownloadManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ def __thread__EpisodeTask(self, curr_id: int, epi: Episode) -> None:
save_path = None
if rate == 1:
save_path = epi.save(imgs_path)
epi.clearAfterSave(imgs_path)

self.updateTaskInfo(curr_id, rate)
self.signal_rate_progress.emit(
Expand Down
13 changes: 7 additions & 6 deletions src/Episode.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import re
import shutil
from typing import TYPE_CHECKING
from zipfile import ZipFile
from zipfile import ZipFile, ZIP_DEFLATED

import piexif
import requests
Expand Down Expand Up @@ -197,13 +197,13 @@ def _() -> list[dict]:
############################################################

def clearAfterSave(self, imgs_path: list[str]) -> None:
"""删除临时图片, 偶尔会出现删除失败的情况,故给与重试5次
"""删除临时图片, 偶尔会出现删除失败的情况,故给与重试3次
Args:
imgs_path (list): 临时图片路径列表
"""

@retry(stop_max_attempt_number=5)
@retry(stop_max_attempt_number=3)
def _() -> None:
for img in reversed(imgs_path):
try:
Expand Down Expand Up @@ -297,6 +297,7 @@ def _() -> None:
# 关闭所有图像, 释放内存
for img in temp_imgs:
img.close()
self.clearAfterSave(imgs_path)

# 在pdf文件属性中记录章节标题作者和软件版本以及版权信息
if not self.exif_setting:
Expand Down Expand Up @@ -370,7 +371,7 @@ def jpg_exif(img_path: str):
logger.exception(e)

# 复制图片到文件夹
shutil.copy2(
shutil.move(
img_path,
os.path.join(self.epi_path, f"{str(index).zfill(3)}.{img_format}"),
)
Expand Down Expand Up @@ -445,7 +446,7 @@ def saveToZip(self, imgs_path: list[str]) -> None:
@retry(stop_max_attempt_number=5)
def _() -> None:
try:
with ZipFile(f"{self.epi_path}.zip", "w") as z:
with ZipFile(f"{self.epi_path}.zip", "w", compression=ZIP_DEFLATED) as z:
# 压缩文件里不要子目录,全部存在根目录
for root, _dirs, files in os.walk(self.epi_path):
for file in files:
Expand Down Expand Up @@ -484,7 +485,7 @@ def saveToCbz(self, imgs_path: list[str]) -> None:
@retry(stop_max_attempt_number=5)
def _() -> None:
try:
with ZipFile(f"{self.epi_path}.cbz", "w") as z:
with ZipFile(f"{self.epi_path}.cbz", "w", compression=ZIP_DEFLATED) as z:
# 压缩文件里不要子目录,全部存在根目录
for root, _dirs, files in os.walk(self.epi_path):
for file in files:
Expand Down
20 changes: 7 additions & 13 deletions src/ui/MangaUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def _() -> None:
self.present_comic_id = comic_id
self.resolveEnable("resolving")
comic = Comic(self.present_comic_id, self.mainGUI)
self.updateComicInfoEvent(comic, "bilibili")
self.updateComicInfoEvent(comic, "done")

self.mainGUI.lineEdit_manga_search_id.returnPressed.connect(_)
self.mainGUI.pushButton_manga_search_id.clicked.connect(_)
Expand All @@ -138,7 +138,7 @@ def _(item: QListWidgetItem) -> None:
self.present_comic_id = self.search_info[index]["id"]
self.resolveEnable("resolving")
comic = Comic(self.present_comic_id, self.mainGUI)
self.updateComicInfoEvent(comic, "bilibili")
self.updateComicInfoEvent(comic, "done")

self.mainGUI.listWidget_manga_search.itemDoubleClicked.connect(_)

Expand Down Expand Up @@ -375,7 +375,7 @@ def updateComicInfoEvent(self, comic: Comic, resolve_type: str, _event: QEvent =
Args:
comic (Comic): 漫画类实例
resolve_type (str): 更新的解析类型
resolve_type (str): 更新的进度类型
"""

if self.mainGUI.label_resolve_status.text() == "":
Expand All @@ -392,7 +392,7 @@ def getComicInfo(self, comic: Comic, resolve_type: str) -> None:
Args:
comic (Comic): 获取的漫画实例
resolve_type (str): 更新的解析类型
resolve_type (str): 更新的进度类型
"""

Expand Down Expand Up @@ -785,7 +785,7 @@ def _() -> None:
return
self.resolveEnable("resolving")
comic = Comic(self.present_comic_id, self.mainGUI)
self.updateComicInfoEvent(comic, "bilibili")
self.updateComicInfoEvent(comic, "done")

self.mainGUI.pushButton_resolve_detail.clicked.connect(_)

Expand All @@ -802,7 +802,7 @@ def _() -> None:
return
self.resolveEnable("resolving")
comic = BiliPlusComic(self.present_comic_id, self.mainGUI)
self.updateComicInfoEvent(comic, "biliplus")
self.updateComicInfoEvent(comic, "done")

self.mainGUI.pushButton_biliplus_resolve_detail.clicked.connect(_)

Expand Down Expand Up @@ -869,7 +869,6 @@ def _() -> None:
self.mainGUI.tabWidget_download_list.setCurrentIndex(0)

self.mainGUI.pushButton_chp_detail_download_selected.clicked.connect(_)
self.mainGUI.pushButton_biliplus_detail_download_selected.clicked.connect(_)

###########################################################

Expand All @@ -883,17 +882,12 @@ def resolveEnable(self, resolve_type: str) -> None:
self.mainGUI.pushButton_resolve_detail.setEnabled(False)
self.mainGUI.pushButton_biliplus_resolve_detail.setEnabled(False)
self.mainGUI.pushButton_chp_detail_download_selected.setEnabled(False)
self.mainGUI.pushButton_biliplus_detail_download_selected.setEnabled(False)
else:
self.mainGUI.pushButton_resolve_detail.setEnabled(True)
self.mainGUI.pushButton_biliplus_resolve_detail.setEnabled(True)

if resolve_type == "bilibili":
if resolve_type == "done":
self.mainGUI.pushButton_chp_detail_download_selected.setEnabled(True)
self.mainGUI.pushButton_biliplus_detail_download_selected.setEnabled(False)
elif resolve_type == "biliplus":
self.mainGUI.pushButton_chp_detail_download_selected.setEnabled(False)
self.mainGUI.pushButton_biliplus_detail_download_selected.setEnabled(True)

############################################################

Expand Down
30 changes: 0 additions & 30 deletions src/ui/PySide_src/mainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -462,36 +462,6 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_biliplus_empty">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_11">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_biliplus_detail_download_selected">
<property name="enabled">
<bool>false</bool>
</property>
<property name="maximumSize">
<size>
<width>130</width>
<height>25</height>
</size>
</property>
<property name="text">
<string>下载BiliPlus选中章节</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
Expand Down
21 changes: 0 additions & 21 deletions src/ui/PySide_src/mainWindow_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,25 +333,6 @@ def setupUi(self, MainWindow):

self.h_Layout_biliplus_detail.addWidget(self.label_resolve_status)

self.label_biliplus_empty = QLabel(self.widget_biliplus_detail)
self.label_biliplus_empty.setObjectName(u"label_biliplus_empty")

self.h_Layout_biliplus_detail.addWidget(self.label_biliplus_empty)

self.line_11 = QFrame(self.widget_biliplus_detail)
self.line_11.setObjectName(u"line_11")
self.line_11.setFrameShape(QFrame.VLine)
self.line_11.setFrameShadow(QFrame.Sunken)

self.h_Layout_biliplus_detail.addWidget(self.line_11)

self.pushButton_biliplus_detail_download_selected = QPushButton(self.widget_biliplus_detail)
self.pushButton_biliplus_detail_download_selected.setObjectName(u"pushButton_biliplus_detail_download_selected")
self.pushButton_biliplus_detail_download_selected.setEnabled(False)
self.pushButton_biliplus_detail_download_selected.setMaximumSize(QSize(130, 25))

self.h_Layout_biliplus_detail.addWidget(self.pushButton_biliplus_detail_download_selected)


self.h_Layout_widget_biliplus_detail.addLayout(self.h_Layout_biliplus_detail)

Expand Down Expand Up @@ -922,8 +903,6 @@ def retranslateUi(self, MainWindow):
self.pushButton_resolve_detail.setText(QCoreApplication.translate("MainWindow", u"B\u7ad9\u89e3\u6790", None))
self.pushButton_biliplus_resolve_detail.setText(QCoreApplication.translate("MainWindow", u"BiliPlus\u89e3\u6790", None))
self.label_resolve_status.setText("")
self.label_biliplus_empty.setText("")
self.pushButton_biliplus_detail_download_selected.setText(QCoreApplication.translate("MainWindow", u"\u4e0b\u8f7dBiliPlus\u9009\u4e2d\u7ae0\u8282", None))
self.textBrowser_tutorial.setHtml(QCoreApplication.translate("MainWindow", u"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><meta charset=\"utf-8\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
Expand Down
Loading

0 comments on commit ada825d

Please sign in to comment.