Skip to content

Commit

Permalink
type fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
freddy36 committed Jun 26, 2024
1 parent d58ca0f commit 7cc90a5
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion audiobookdl/sources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def find_compatible_source(url: str) -> type[Source]:
raise NoSourceFound


def get_source_classes():
def get_source_classes() -> list[type[Source]]:
"""Returns a list of all available sources"""
return [
AudiobooksdotcomSource,
Expand Down
9 changes: 6 additions & 3 deletions audiobookdl/sources/audiobooksdotcom.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .source import Source
from audiobookdl import AudiobookFile, logging, AudiobookMetadata, Cover, Audiobook
from audiobookdl.exceptions import NoSourceFound, DataNotPresent
from audiobookdl.exceptions import NoSourceFound, DataNotPresent, GenericAudiobookDLException

import re
from typing import List
Expand Down Expand Up @@ -56,8 +56,11 @@ def extract_useragent_from_cookies(self) -> str:
:returns: User-Agent string
"""
raw = self._session.cookies.get("ci_session", domain="www.audiobooks.com")
return unquote(raw).split("\"")[11]
raw: str | None = self._session.cookies.get("ci_session", domain="www.audiobooks.com")
if not raw:
raise GenericAudiobookDLException(f"ci_session missing from cookie")
else:
return unquote(raw).split("\"")[11]


def extract_file(self, scrape_url: str) -> List[AudiobookFile]:
Expand Down
2 changes: 1 addition & 1 deletion audiobookdl/sources/bookbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def download(self, url: str) -> Audiobook:
)


def download_license_url(self, book_info):
def download_license_url(self, book_info)-> str:
dl_info = self.get_json(
"https://api.bookbeat.com/api/downloadinfo/" + str(book_info["bookid"])
)
Expand Down
2 changes: 1 addition & 1 deletion audiobookdl/sources/ereolen.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def get_files(self, book_id: str) -> List[AudiobookFile]:
)


def _get_libraries(self):
def _get_libraries(self) -> dict:
"""Returns list of available libraries for login"""
libraries_raw = self.find_in_page(
LOGIN_PAGE_URL,
Expand Down
2 changes: 1 addition & 1 deletion audiobookdl/sources/everand.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def format_metadata(book_info: dict) -> AudiobookMetadata:


@staticmethod
def get_chapter_title(chapter):
def get_chapter_title(chapter) -> str:
"""Extract title for chapter"""
number = chapter["chapter_number"]
if number == 0:
Expand Down
4 changes: 2 additions & 2 deletions audiobookdl/sources/source/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def find_elem_in_page(self, url: str, selector: str, data=None, **kwargs):
return elem.get(data)


def find_elems_in_page(self, url: str, selector: str, **kwargs) -> list:
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`.
Will cache the page.
Expand Down Expand Up @@ -177,7 +177,7 @@ def find_all_in_page(self, url: str, regex: str, **kwargs) -> list:
get_stream_files = networking.get_stream_files

def create_ssl_context(self, options: Any) -> SSLContext:
ssl_context: SSLContext = urllib3.util.create_urllib3_context()
ssl_context: SSLContext = urllib3.util.create_urllib3_context() # type: ignore[attr-defined]
# Prevent the padding extension from appearing in the TLS ClientHello
# It's used by Cloudflare for bot detection
# See issue #106
Expand Down
5 changes: 3 additions & 2 deletions audiobookdl/sources/storytel-legacy.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from requests.models import Response
from .source import Source
from audiobookdl import AudiobookFile, Chapter, logging, AudiobookMetadata, Cover, Audiobook
from audiobookdl.exceptions import UserNotAuthorized, MissingBookAccess, DataNotPresent
Expand Down Expand Up @@ -83,7 +84,7 @@ def get_book_id(url: str) -> str:
raise DataNotPresent
return parsed.path.split("-")[-1]

def download_bookshelf(self):
def download_bookshelf(self) -> Response:
"""Download bookshelf data"""
return self._session.get(
f"https://www.storytel.com/api/getBookShelf.action",
Expand Down Expand Up @@ -143,7 +144,7 @@ def get_metadata(book_info) -> AudiobookMetadata:
return metadata


def download_audiobook_info(self, book_info):
def download_audiobook_info(self, book_info) -> dict[str, Any]:
"""Download information about the audiobook files"""
consumable_id = book_info["book"]["consumableId"]
url = f"https://api.storytel.net/playback-metadata/consumable/{consumable_id}"
Expand Down

0 comments on commit 7cc90a5

Please sign in to comment.