diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index de7abde..079d88e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,8 +8,8 @@ jobs: tests: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2.3.4 - - uses: cachix/install-nix-action@v13 + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v27 with: nix_path: nixpkgs=channel:nixos-unstable - run: nix-shell --command "mypy audiobookdl" diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 6c53537..6bbd949 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -8,8 +8,8 @@ jobs: tests: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2.3.4 - - uses: cachix/install-nix-action@v13 + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v27 with: nix_path: nixpkgs=channel:nixos-unstable - run: nix-shell --command "python3 -m pytest" diff --git a/audiobookdl/sources/source/__init__.py b/audiobookdl/sources/source/__init__.py index 6a353fe..80e2e7e 100644 --- a/audiobookdl/sources/source/__init__.py +++ b/audiobookdl/sources/source/__init__.py @@ -43,31 +43,26 @@ def __init__(self, options: Any): if self.create_storage_dir: os.makedirs(self.database_directory, exist_ok=True) - @property def name(self) -> str: """Primary name of source""" return self.names[0].lower() - @property def requires_authentication(self): """Returns `True` if this source requires authentication to download books""" return len(self._authentication_methods) > 0 - @property def authenticated(self): """Returns `True` if the source has been authenticated""" return self.__authenticated - @property def supports_cookies(self): """Returns `True` if the source supports authentication with cookies""" return "cookies" in self._authentication_methods - def load_cookie_file(self, cookie_file: str): """Loads cookies from a cookie file into session""" if self.supports_cookies: @@ -77,17 +72,14 @@ def load_cookie_file(self, cookie_file: str): self._session.cookies.update(cookie_jar) self.__authenticated = True - @property def supports_login(self): """Returns `True` if the source supports authentication with login""" return "login" in self._authentication_methods - def _login(self, url: str, username: str, password: str): pass - def login(self, url: str, **kwargs) -> None: """Authenticate with source using username and password""" if self.supports_login: @@ -95,22 +87,18 @@ def login(self, url: str, **kwargs) -> None: self._login(url, **kwargs) self.__authenticated = True - def download_from_id(self, book_id: T) -> Audiobook: """Download book specified by id""" raise NotImplementedError - def download(self, url: str) -> Result: """Download book or series""" raise NotImplementedError - - + def on_download_complete(self, audiobook: Audiobook): """Called after the download is complete""" pass - def _get_page(self, url: str, use_cache: bool = True, **kwargs) -> bytes: """Download a page and caches it""" if url not in self.__pages and use_cache: @@ -119,7 +107,6 @@ def _get_page(self, url: str, use_cache: bool = True, **kwargs) -> bytes: self.__pages[url] = resp return self.__pages[url] - def find_elem_in_page(self, url: str, selector: str, data=None, **kwargs): """ Find the first html element in page from `url` that matches `selector`. @@ -136,7 +123,6 @@ def find_elem_in_page(self, url: str, selector: str, data=None, **kwargs): return elem.text return elem.get(data) - def find_elems_in_page(self, url: str, selector: str, **kwargs) -> Any: """ Find all html elements in the page from `url` that's matches `selector`. @@ -148,7 +134,6 @@ def find_elems_in_page(self, url: str, selector: str, **kwargs) -> Any: results = sel(tree) return results - def find_in_page(self, url: str, regex: str, group_index: int = 0, **kwargs) -> str: """ Find some text in a page based on a regex. @@ -161,7 +146,6 @@ def find_in_page(self, url: str, regex: str, group_index: int = 0, **kwargs) -> raise DataNotPresent return m.group(group_index) - def find_all_in_page(self, url: str, regex: str, **kwargs) -> list: """ Find all places in a page that matches the regex. @@ -180,7 +164,7 @@ def create_ssl_context(self, options: Any) -> SSLContext: # Custom SSLContext's are broken in requests version 2.32.0/2.32.1/2.32.2 # fixed in version 2.32.3: https://github.com/psf/requests/pull/6716 try: - ssl_context: SSLContext = urllib3.util.create_urllib3_context() + ssl_context: SSLContext = urllib3.util.create_urllib3_context() # type: ignore[attr-defined] # Workaround for regression in requests version 2.32.3 # https://github.com/psf/requests/issues/6730 diff --git a/shell.nix b/shell.nix index 965c3a9..d0e2835 100644 --- a/shell.nix +++ b/shell.nix @@ -3,7 +3,7 @@ with import {}; mkShell { buildInputs = [ ffmpeg - (python3.withPackages(ps: with ps; [ + (python312.withPackages(ps: with ps; [ mutagen requests rich @@ -17,6 +17,7 @@ mkShell { tomli attrs pycountry + urllib3 # Test pytest