Skip to content

Commit

Permalink
adjust type hints for old python versions
Browse files Browse the repository at this point in the history
  • Loading branch information
freddy36 committed Jun 27, 2024
1 parent f0963f7 commit 99dd796
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion audiobookdl/output/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
6 changes: 3 additions & 3 deletions audiobookdl/sources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions audiobookdl/sources/audiobooksdotcom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions audiobookdl/sources/bookbeat.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions audiobookdl/sources/nextory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down
12 changes: 6 additions & 6 deletions audiobookdl/sources/storytel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) },
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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] = {
Expand Down
2 changes: 1 addition & 1 deletion audiobookdl/utils/audiobook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 99dd796

Please sign in to comment.