diff --git a/audiobookdl/output/download.py b/audiobookdl/output/download.py index 9f26e78..a24d1e8 100644 --- a/audiobookdl/output/download.py +++ b/audiobookdl/output/download.py @@ -142,7 +142,7 @@ def download_files_with_cli_output(audiobook: Audiobook, output_dir: str) -> Lis return filepaths -def create_filepath(audiobook: Audiobook, output_dir: str, index: int) -> tuple[str, str]: +def create_filepath(audiobook: Audiobook, output_dir: str, index: int) -> Tuple[str, str]: """ Create output file path for file number `index` in `audibook` diff --git a/audiobookdl/sources/__init__.py b/audiobookdl/sources/__init__.py index 19a7ca0..aa08446 100644 --- a/audiobookdl/sources/__init__.py +++ b/audiobookdl/sources/__init__.py @@ -16,9 +16,9 @@ from ..exceptions import NoSourceFound import re -from typing import Iterable, List +from typing import Iterable, List, Type -def find_compatible_source(url: str) -> type[Source]: +def find_compatible_source(url: str) -> Type[Source]: """Finds the first source that supports the given url""" sources = get_source_classes() for source in sources: @@ -28,7 +28,7 @@ def find_compatible_source(url: str) -> type[Source]: raise NoSourceFound -def get_source_classes() -> list[type[Source]]: +def get_source_classes() -> List[Type[Source]]: """Returns a list of all available sources""" return [ AudiobooksdotcomSource, diff --git a/audiobookdl/sources/audiobooksdotcom.py b/audiobookdl/sources/audiobooksdotcom.py index b18216c..6aaf995 100644 --- a/audiobookdl/sources/audiobooksdotcom.py +++ b/audiobookdl/sources/audiobooksdotcom.py @@ -3,7 +3,7 @@ from audiobookdl.exceptions import NoSourceFound, DataNotPresent, GenericAudiobookDLException import re -from typing import List +from typing import List, Union from urllib.parse import unquote from urllib3.util import parse_url import requests @@ -56,7 +56,7 @@ def extract_useragent_from_cookies(self) -> str: :returns: User-Agent string """ - raw: str | None = self._session.cookies.get("ci_session", domain="www.audiobooks.com") + raw: Union[str, None] = self._session.cookies.get("ci_session", domain="www.audiobooks.com") if not raw: raise GenericAudiobookDLException(f"ci_session missing from cookie") else: diff --git a/audiobookdl/sources/bookbeat.py b/audiobookdl/sources/bookbeat.py index 693785f..d857ace 100644 --- a/audiobookdl/sources/bookbeat.py +++ b/audiobookdl/sources/bookbeat.py @@ -1,6 +1,6 @@ from .source import Source from audiobookdl import AudiobookFile, Chapter, AudiobookMetadata, Cover, Audiobook -from typing import Any, List, Optional, Dict, MutableMapping +from typing import Any, List, Optional, Dict, MutableMapping, Union import uuid from audiobookdl.exceptions import UserNotAuthorized, MissingBookAccess import base64 @@ -30,7 +30,7 @@ def create_device_id() -> str: ) def _login(self, url: str, username: str, password: str): - headers: MutableMapping[str, str | bytes] = { + headers: MutableMapping[str, Union[str, bytes]] = { "accept": "application/hal+json", "bb-client": "BookBeatApp", "bb-device": self.create_device_id(), diff --git a/audiobookdl/sources/nextory.py b/audiobookdl/sources/nextory.py index 582e639..85ca223 100644 --- a/audiobookdl/sources/nextory.py +++ b/audiobookdl/sources/nextory.py @@ -159,7 +159,7 @@ def find_format_data(book_info: dict) -> dict: raise DataNotPresent - def get_files(self, audio_data) -> list[AudiobookFile]: + def get_files(self, audio_data) -> List[AudiobookFile]: files = [] for file in audio_data["files"]: # master url redirects to media url @@ -180,7 +180,7 @@ def get_metadata(self, book_info) -> AudiobookMetadata: ) - def get_chapters(self, audio_data: dict) -> list[Chapter]: + def get_chapters(self, audio_data: dict) -> List[Chapter]: chapters = [] for index, file in enumerate(audio_data["files"]): chapters.append( diff --git a/audiobookdl/sources/storytel.py b/audiobookdl/sources/storytel.py index 48ce0e6..5e533b5 100644 --- a/audiobookdl/sources/storytel.py +++ b/audiobookdl/sources/storytel.py @@ -22,7 +22,7 @@ ) from Crypto.Cipher import AES from Crypto.Util.Padding import pad -from typing import Any, List, Dict, Optional +from typing import Any, List, Dict, Optional, Union from urllib3.util import parse_url from urllib.parse import urlunparse, parse_qs from datetime import datetime, date @@ -32,7 +32,7 @@ import os # fmt: off -metadata_corrections: dict[str, dict[str, Any]] = { +metadata_corrections: Dict[str, Dict[str, Any]] = { "books": { "1623721": { "title": "Bibi & Tina: Schatten über dem Martinshof", "release_date": date(2010,3,12) }, "1623873": { "title": "Bibi & Tina: Die ungarischen Reiter", "release_date": date(2010,9,10) }, @@ -231,7 +231,7 @@ def download_lists_api( list_id: str = self.get_id_from_url(url) list_details = self.download_list_books(list_id, list_type, language) - books: list[BookId[str] | Audiobook] = [] + books: List[Union[BookId[str], Audiobook]] = [] for item in list_details["items"]: abook_formats = [ format for format in item["formats"] if format["type"] == "abook" @@ -335,7 +335,7 @@ def download_books_from_website(self, url: str) -> Series[str]: """ title = self.find_elems_in_page(url, "h1")[-1].text items = self.find_elems_in_page(url, 'a[href*="/books/"]') - books: list[BookId[str] | Audiobook] = [] + books: List[Union[BookId[str], Audiobook]] = [] for item in items: href: str = item.get("href") # check for headphone icon to filter out non audiobooks @@ -362,7 +362,7 @@ def download_list_books( list_type: str, languages: str, formats: str = "abook", - ) -> dict[str, Any]: + ) -> Dict[str, Any]: """Download details about book list :param formats: comma serapted list of formats (abook,ebook,podcast) @@ -372,7 +372,7 @@ def download_list_books( # API returns only 10 items per request # if the nextPageToken - result: dict[str, Any] = {"nextPageToken": False} + result: Dict[str, Any] = {"nextPageToken": False} while result["nextPageToken"] != None: params: dict[str, str] = { diff --git a/audiobookdl/utils/audiobook.py b/audiobookdl/utils/audiobook.py index 5989576..042fd13 100644 --- a/audiobookdl/utils/audiobook.py +++ b/audiobookdl/utils/audiobook.py @@ -38,7 +38,7 @@ class AudiobookFile: # Title of file title: Optional[str] = None # Headers for request - headers: MutableMapping[str, str | bytes] = Factory(dict) + headers: MutableMapping[str, Union[str, bytes]] = Factory(dict) # Encryption method encryption_method: Optional[AudiobookFileEncryption] = None # Expected content-type of the download request