Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
#
  • Loading branch information
eggplants authored Oct 1, 2024
1 parent 8014be9 commit 902628f
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions getjump/getjump.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,16 @@ def get( # noqa: PLR0913
self.__check_url(url)
self.login(url, username=username, password=password)

url = url if url.endswith(".json") else re.sub(r"((episode|magazine|volume)/\d+)", r"\1.json", url)
url = url[:-5] if url.endswith(".json") else url

res = self._session.get(url, headers=HEADERS)

self.__check_content_type(res.headers["content-type"])

j = res.json()["readableProduct"]
json_value = BeautifulSoup(res.content, "html.parser").find("script", id="episode-json").attrs.get("data-value", None)
if json_value is None:
raise ValueError("json data is missing.")

j = json.loads(json_value)["readableProduct"]

nxt = j["nextReadableProductUri"]
nxt = self.__check_next(nxt)
Expand Down Expand Up @@ -191,8 +194,8 @@ def __check_url(self, url: str) -> None:

@staticmethod
def __check_content_type(type_: str) -> None:
if "application/json" not in type_:
msg = f"got '{type_}', expect 'application/json'. Is given URL correct?"
if "text/html" not in type_:
msg = f"got '{type_}', expect 'text/html'. Is given URL correct?"
raise TypeError(msg)

@staticmethod
Expand Down

0 comments on commit 902628f

Please sign in to comment.