Skip to content

Commit

Permalink
Feature: Support updated Kobo challenge page and isbn -> book id
Browse files Browse the repository at this point in the history
  • Loading branch information
NotSimone committed Oct 28, 2024
1 parent b971ffa commit d526e9f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class KoboMetadata(Source):
name = "Kobo Metadata"
author = "NotSimone"
version = (1, 6, 3)
version = (1, 7, 0)
minimum_calibre_version = (5, 0, 0)
description = _("Downloads metadata and covers from Kobo")

Expand Down
8 changes: 5 additions & 3 deletions kobo_metadata.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re
import string
import time
from queue import Queue
from typing import Dict, List, Optional, Tuple
from urllib.parse import urlencode
Expand Down Expand Up @@ -100,12 +101,13 @@ def _get_webpage(self, url: str, timeout: int, log: Log) -> Tuple[Optional[html.
while attempts < 10:
resp = session.get(url, timeout=timeout)
page = html.fromstring(resp.text)
# If we failed to get past the cloudflare protection, we get a page with this class
if not page.xpath("//form[@class='challenge-form']"):
# If we failed to get past the cloudflare protection, we get a page with one of these classes
if not page.xpath("//form[@class='challenge-form']") and not page.xpath("//form[@id='challenge-form']"):
is_search = "/search?" in resp.url
return (page, is_search)
log.info(f"KoboMetadata::get_webpage: Could not defeat cloudflare protection - trying again for {url}")
attempts += 1
time.sleep(0.01)
log.error(f"KoboMetadata::get_webpage: Could not defeat cloudflare protection - giving up for {url}")
return (None, False)
except Exception as e:
Expand Down Expand Up @@ -249,7 +251,7 @@ def _parse_book_page(self, page: html.Element, prefs: Dict[str, any], log: Log)
if descriptor == "Release Date:":
metadata.pubdate = parse_only_date(x.xpath("span")[0].text)
log.info(f"KoboMetadata::parse_book_page: Got pubdate: {metadata.pubdate}")
elif descriptor == "ISBN:":
elif descriptor == "ISBN:" or descriptor == "Book ID:":
metadata.isbn = x.xpath("span")[0].text
log.info(f"KoboMetadata::parse_book_page: Got isbn: {metadata.isbn}")
elif descriptor == "Language:":
Expand Down

0 comments on commit d526e9f

Please sign in to comment.