Skip to content

Commit

Permalink
fix(readcomiconline): use better id grabber
Browse files Browse the repository at this point in the history
Although cloudflare has been turned off, they have this really annoying system that makes it a pain to download anything (see Xonshiz/comic-dl#299)
  • Loading branch information
potatoeggy committed Oct 6, 2022
1 parent d8fb07f commit 0560e80
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions mandown/sources/source_readcomiconline.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
# pylint: disable=invalid-name


import re

import requests
Expand Down Expand Up @@ -34,7 +35,8 @@ def fetch_metadata(self) -> BaseMetadata:
)
]
genres: list[str] = [str(e.text) for e in soup.select("a[href^='/Genre']")]
description = str(soup.select_one("p[style='text-align: justify;']").text)
description_maybe = soup.select_one("p[style='text-align: justify;']")
description = str(description_maybe.text if description_maybe else "")
cover = self.domains[0] + str(soup.find("link")["href"])

return BaseMetadata(title, author, self.url, genres, description, cover)
Expand All @@ -58,16 +60,19 @@ def fetch_chapter_image_list(self, chapter: BaseChapter) -> list[str]:
images: list[str] = []
start = 0
while (index := text.find("lstImages.push(", start)) != -1:
s_index = index + len('lstImages.push("')
e_index = text.find('");', s_index)
s_index = index + len("lstImages.push('")
e_index = text.find("');", s_index)
images.append(text[s_index:e_index])
start = e_index
return images

@classmethod
def url_to_id(cls, url: str) -> str:
*_, last_item = filter(None, url.split("/"))
return last_item
segments = url.split("/")
for i, s in enumerate(segments):
if s == "Comic":
return segments[i + 1]
raise ValueError("Invalid comic URL")

@staticmethod
def check_url(url: str) -> bool:
Expand Down

0 comments on commit 0560e80

Please sign in to comment.