diff --git a/app.py b/app.py index 28b304d..c0f0111 100644 --- a/app.py +++ b/app.py @@ -357,7 +357,10 @@ def authenticate() -> bool: # Validate credentials against database try: - conn = sqlite3.connect(CWA_DB_PATH) + # Open database in true read-only mode to avoid journal/WAL writes on RO mounts + db_path = os.fspath(CWA_DB_PATH) + db_uri = f"file:{db_path}?mode=ro&immutable=1" + conn = sqlite3.connect(db_uri, uri=True) cur = conn.cursor() cur.execute("SELECT password FROM user WHERE name = ?", (username,)) row = cur.fetchone() diff --git a/book_manager.py b/book_manager.py index 88497a7..b046a81 100644 --- a/book_manager.py +++ b/book_manager.py @@ -9,7 +9,7 @@ from bs4 import BeautifulSoup, Tag, NavigableString, ResultSet import downloader from logger import setup_logger from config import SUPPORTED_FORMATS, BOOK_LANGUAGE, AA_BASE_URL -from env import AA_DONATOR_KEY, USE_CF_BYPASS +from env import AA_DONATOR_KEY, USE_CF_BYPASS, PRIORITIZE_WELIB from models import BookInfo, SearchFilters logger = setup_logger(__name__) @@ -198,7 +198,7 @@ def _parse_book_info_page(soup: BeautifulSoup, book_id: str) -> BookInfo: ): libgen_url = url["href"] # TODO : Temporary fix ? Maybe get URLs from https://open-slum.org/ ? - libgen_url = libgen_url = re.sub(r'libgen\.(\w+)', 'libgen.bz', url["href"]) + libgen_url = libgen_url = re.sub(r'libgen\.(\w+)', 'libgen.gs', url["href"]) external_urls_libgen.add(libgen_url) elif url.text.strip().lower().startswith("z-lib"): if ".onion/" not in url["href"]: @@ -206,11 +206,13 @@ def _parse_book_info_page(soup: BeautifulSoup, book_id: str) -> BookInfo: except: pass + external_urls_welib = _get_download_urls_from_welib(book_id) if USE_CF_BYPASS else set() urls = [] + urls += list(external_urls_welib) if PRIORITIZE_WELIB else [] urls += list(slow_urls_no_waitlist) if USE_CF_BYPASS else [] urls += list(external_urls_libgen) - urls += list( _get_download_urls_from_welib(book_id)) if USE_CF_BYPASS else [] + urls += list(external_urls_welib) if not PRIORITIZE_WELIB else [] urls += list(slow_urls_with_waitlist) if USE_CF_BYPASS else [] urls += list(external_urls_z_lib) @@ -244,9 +246,10 @@ def _parse_book_info_page(soup: BeautifulSoup, book_id: str) -> BookInfo: return book_info -def _get_download_urls_from_welib(book_id: str) -> List[str]: +def _get_download_urls_from_welib(book_id: str) -> set[str]: """Get download urls from welib.org.""" url = f"https://welib.org/md5/{book_id}" + logger.info(f"Getting download urls from welib.org for {book_id}. While this uses the bypasser, it will not start downloading them yet.") html = downloader.html_get_page(url, use_bypasser=True) if not html: return [] diff --git a/env.py b/env.py index cc6229d..15f62eb 100644 --- a/env.py +++ b/env.py @@ -25,7 +25,9 @@ _BOOK_LANGUAGE = os.getenv("BOOK_LANGUAGE", "en").lower() _CUSTOM_SCRIPT = os.getenv("CUSTOM_SCRIPT", "").strip() FLASK_HOST = os.getenv("FLASK_HOST", "0.0.0.0") FLASK_PORT = int(os.getenv("FLASK_PORT", "8084")) -DEBUG = string_to_bool(os.getenv("DEBUG", "False")) +DEBUG = string_to_bool(os.getenv("DEBUG", "false")) +PRIORITIZE_WELIB = string_to_bool(os.getenv("PRIORITIZE_WELIB", "false")) + # If debug is true, we want to log everything if DEBUG: LOG_LEVEL = "DEBUG" diff --git a/readme.md b/readme.md index a721fcc..f69fdf8 100644 --- a/readme.md +++ b/readme.md @@ -82,6 +82,7 @@ Note that if using TOR, the TZ will be calculated automatically based on IP. | `BOOK_LANGUAGE` | Preferred language for books | `en` | | `AA_DONATOR_KEY` | Optional Donator key for Anna's Archive fast download API | `` | | `USE_BOOK_TITLE` | Use book title as filename instead of ID | `false` | +| `PRIORITIZE_WELIB` | When downloading, download from WELIB first instead of AA | `false` | If you change `BOOK_LANGUAGE`, you can add multiple comma separated languages, such as `en,fr,ru` etc. @@ -90,7 +91,7 @@ If you change `BOOK_LANGUAGE`, you can add multiple comma separated languages, s | Variable | Description | Default Value | | ---------------------- | --------------------------------------------------------- | --------------------------------- | | `AA_BASE_URL` | Base URL of Annas-Archive (could be changed for a proxy) | `https://annas-archive.org` | -| `USE_CF_BYPASS` | Disable CF bypass and use alternative links instead | `true` | +| `USE_CF_BYPASS` | Disable CF bypass and use alternative links instead | `true` | If you are a donator on AA, you can use your Key in `AA_DONATOR_KEY` to speed up downloads and bypass the wait times. If disabling the cloudflare bypass, you will be using alternative download hosts, such as libgen or z-lib, but they usually have a delay before getting the more recent books and their collection is not as big as aa's. But this setting should work for the majority of books.