Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛修复BiliPlus解析失败问题(使用重定向) #157

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/BiliPlus.py
Original file line number Diff line number Diff line change
@@ -230,7 +230,7 @@ def _(url: str) -> str:
ep_items = soup.find_all("div", {"class": "episode-item"})
ep_available = []
for ep in ep_items:
if "https://" in ep.img["src"]:
if ep.img.get("_src") is not None:
ep_available.append(ep.a["href"].split("epid=")[1])
total_ep_element = soup.select_one("center p")
if total_ep_element:
@@ -244,7 +244,7 @@ def _(url: str) -> str:
soup = BeautifulSoup(page_html, "html.parser")
ep_items = soup.find_all("div", {"class": "episode-item"})
for ep in ep_items:
if "https://" in ep.img["src"]:
if ep.img.get("_src") is not None:
ep_available.append(ep.a["href"].split("epid=")[1])

unlock_times = 0
@@ -361,9 +361,8 @@ def _() -> list[dict]:
soup = BeautifulSoup(biliplus_html, "html.parser")
images = soup.find_all("img", {"class": "comic-single"})
for img in images:
img_url = img["_src"]
url, token = img_url.split("?token=")
biliplus_imgs_token.append({"url": url, "token": token})
img_url = f'https://www.biliplus.com/manga/{img["_src"]}'
biliplus_imgs_token.append({"url": img_url})
self.imgs_token = biliplus_imgs_token
if not biliplus_imgs_token:
msg = f"《{self.comic_name}》章节:{self.title} " \
5 changes: 4 additions & 1 deletion src/DownloadManager.py
Original file line number Diff line number Diff line change
@@ -151,7 +151,10 @@ def __thread__EpisodeTask(self, curr_id: int, epi: Episode) -> None:
if self.terminated:
epi.clear(imgs_path)
return
img_url = f"{img['url']}?token={img['token']}"
if img.get("token") is not None:
img_url = f"{img['url']}?token={img['token']}"
else:
img_url = img["url"]
img_path = epi.downloadImg(index, img_url)
if img_path is None:
self.reportError(curr_id)
8 changes: 6 additions & 2 deletions src/Episode.py
Original file line number Diff line number Diff line change
@@ -527,7 +527,11 @@ def downloadImg(self, index: int, img_url: str) -> str:
@retry(stop_max_delay=MAX_RETRY_LARGE, wait_exponential_multiplier=RETRY_WAIT_EX)
def _() -> bytes:
try:
res = requests.get(img_url, timeout=TIMEOUT_LARGE)
if img_url.find("token") != -1:
res = requests.get(img_url, timeout=TIMEOUT_LARGE)
else:
res = requests.get(img_url, headers=self.headers, timeout=TIMEOUT_LARGE)

except requests.RequestException as e:
logger.warning(
f"《{self.comic_name}》章节:{self.title} - {index} - {img_url} 下载图片失败! 重试中...\n{e}"
@@ -562,7 +566,7 @@ def _() -> bytes:

# ?###########################################################
# ? 保存图片
img_format = img_url.split(".")[-1].split("?")[0].lower()
img_format = img_url.split(".")[-1].split("?")[0].lower().replace("&append=", "")
path_to_save = os.path.join(self.save_path, f"{self.real_ord}_{index}.{img_format}")

@retry(stop_max_attempt_number=5)