Skip to content

Commit

Permalink
update workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
freddy36 committed Jul 1, 2024
1 parent b470d65 commit b92b0eb
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 2 additions & 2 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
20 changes: 2 additions & 18 deletions audiobookdl/sources/source/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -77,40 +72,33 @@ 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:
logging.debug("Logging in")
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:
Expand All @@ -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`.
Expand All @@ -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`.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ with import <nixpkgs> {};
mkShell {
buildInputs = [
ffmpeg
(python3.withPackages(ps: with ps; [
(python312.withPackages(ps: with ps; [
mutagen
requests
rich
Expand All @@ -17,6 +17,7 @@ mkShell {
tomli
attrs
pycountry
urllib3

# Test
pytest
Expand Down

0 comments on commit b92b0eb

Please sign in to comment.