Hopefully fix python 3.8 compat

This commit is contained in:
Ivan Habunek 2024-04-23 18:09:30 +02:00
parent f1924715ed
commit 1057fff61a
No known key found for this signature in database
GPG Key ID: F5F0623FF5EBCB3D
8 changed files with 32 additions and 28 deletions

View File

@ -53,6 +53,7 @@ twitch-dl = "twitchdl.cli:cli"
[tool.pyright]
include = ["twitchdl"]
typeCheckingMode = "strict"
pythonVersion = "3.8"
[tool.ruff]
line-length = 100

View File

@ -7,6 +7,7 @@ import subprocess
import tempfile
from os import path
from pathlib import Path
from typing import Dict, List
from urllib.parse import urlencode, urlparse
import click
@ -28,7 +29,7 @@ from twitchdl.playlists import (
from twitchdl.twitch import Chapter, Clip, ClipAccessToken, Video
def download(ids: list[str], args: DownloadOptions):
def download(ids: List[str], args: DownloadOptions):
for video_id in ids:
download_one(video_id, args)
@ -78,7 +79,7 @@ def _join_vods(playlist_path: str, target: str, overwrite: bool, video: Video):
raise ConsoleError("Joining files failed")
def _concat_vods(vod_paths: list[str], target: str):
def _concat_vods(vod_paths: List[str], target: str):
tool = "type" if platform.system() == "Windows" else "cat"
command = [tool] + vod_paths
@ -88,7 +89,7 @@ def _concat_vods(vod_paths: list[str], target: str):
raise ConsoleError(f"Joining files failed: {result.stderr}")
def get_video_placeholders(video: Video, format: str) -> dict[str, str]:
def get_video_placeholders(video: Video, format: str) -> Dict[str, str]:
date, time = video["publishedAt"].split("T")
game = video["game"]["name"] if video["game"] else "Unknown"
@ -350,7 +351,7 @@ def _determine_time_range(video_id: str, args: DownloadOptions):
return None, None
def _choose_chapter_interactive(chapters: list[Chapter]):
def _choose_chapter_interactive(chapters: List[Chapter]):
click.echo("\nChapters:")
for index, chapter in enumerate(chapters):
duration = utils.format_time(chapter["durationMilliseconds"] // 1000)

View File

@ -1,3 +1,5 @@
from typing import List
import click
import m3u8
@ -48,7 +50,7 @@ def info(id: str, *, json: bool = False):
raise ConsoleError(f"Invalid input: {id}")
def video_info(video: Video, playlists, chapters: list[Chapter]):
def video_info(video: Video, playlists, chapters: List[Chapter]):
click.echo()
print_video(video)

View File

@ -1,5 +1,5 @@
import sys
from typing import Optional
from typing import List, Optional
import click
@ -13,7 +13,7 @@ def videos(
*,
all: bool,
compact: bool,
games: list[str],
games: List[str],
json: bool,
limit: Optional[int],
pager: Optional[int],
@ -67,7 +67,7 @@ def videos(
)
def _get_game_ids(names: list[str]) -> list[str]:
def _get_game_ids(names: List[str]) -> List[str]:
if not names:
return []

View File

@ -1,5 +1,5 @@
from dataclasses import dataclass
from typing import Any, Optional
from typing import Any, Mapping, Optional
@dataclass
@ -22,4 +22,4 @@ class DownloadOptions:
# Type for annotating decoded JSON
# TODO: make data classes for common structs
Data = dict[str, Any]
Data = Mapping[str, Any]

View File

@ -1,6 +1,6 @@
import json
from itertools import islice
from typing import Any, Callable, Generator, Optional, TypeVar
from typing import Any, Callable, Generator, List, Optional, TypeVar
import click
@ -25,12 +25,12 @@ def print_log(message: Any):
click.secho(message, err=True, dim=True)
def print_table(headers: list[str], data: list[list[str]]):
def print_table(headers: List[str], data: List[List[str]]):
widths = [[len(cell) for cell in row] for row in data + [headers]]
widths = [max(width) for width in zip(*widths)]
underlines = ["-" * width for width in widths]
def print_row(row: list[str]):
def print_row(row: List[str]):
for idx, cell in enumerate(row):
width = widths[idx]
click.echo(cell.ljust(width), nl=False)

View File

@ -3,7 +3,7 @@ Parse and manipulate m3u8 playlists.
"""
from dataclasses import dataclass
from typing import Generator, Optional, OrderedDict
from typing import Generator, List, Optional, OrderedDict
import click
import m3u8
@ -55,7 +55,7 @@ def enumerate_vods(
document: m3u8.M3U8,
start: Optional[int] = None,
end: Optional[int] = None,
) -> list[Vod]:
) -> List[Vod]:
"""Extract VODs for download from document."""
vods = []
vod_start = 0
@ -78,8 +78,8 @@ def enumerate_vods(
def make_join_playlist(
playlist: m3u8.M3U8,
vods: list[Vod],
targets: list[str],
vods: List[Vod],
targets: List[str],
) -> m3u8.Playlist:
"""
Make a modified playlist which references downloaded VODs
@ -97,7 +97,7 @@ def make_join_playlist(
return playlist
def select_playlist(playlists: list[Playlist], quality: Optional[str]) -> Playlist:
def select_playlist(playlists: List[Playlist], quality: Optional[str]) -> Playlist:
return (
select_playlist_by_name(playlists, quality)
if quality is not None
@ -105,7 +105,7 @@ def select_playlist(playlists: list[Playlist], quality: Optional[str]) -> Playli
)
def select_playlist_by_name(playlists: list[Playlist], quality: str) -> Playlist:
def select_playlist_by_name(playlists: List[Playlist], quality: str) -> Playlist:
if quality == "source":
return playlists[0]
@ -118,7 +118,7 @@ def select_playlist_by_name(playlists: list[Playlist], quality: str) -> Playlist
raise click.ClickException(msg)
def select_playlist_interactive(playlists: list[Playlist]) -> Playlist:
def select_playlist_interactive(playlists: List[Playlist]) -> Playlist:
click.echo("\nAvailable qualities:")
for n, playlist in enumerate(playlists):
if playlist.resolution:

View File

@ -3,7 +3,7 @@ Twitch API access.
"""
import json
from typing import Dict, Generator, Literal, Optional, TypedDict
from typing import Dict, Generator, List, Literal, Mapping, Optional, TypedDict
import click
import httpx
@ -41,7 +41,7 @@ class VideoQuality(TypedDict):
class ClipAccessToken(TypedDict):
id: str
playbackAccessToken: AccessToken
videoQualities: list[VideoQuality]
videoQualities: List[VideoQuality]
class Clip(TypedDict):
@ -52,7 +52,7 @@ class Clip(TypedDict):
viewCount: int
durationSeconds: int
url: str
videoQualities: list[VideoQuality]
videoQualities: List[VideoQuality]
game: Game
broadcaster: User
@ -80,7 +80,7 @@ class Chapter(TypedDict):
class GQLError(click.ClickException):
def __init__(self, errors: list[str]):
def __init__(self, errors: List[str]):
message = "GraphQL query failed."
for error in errors:
message += f"\n* {error}"
@ -299,7 +299,7 @@ def get_channel_videos(
limit: int,
sort: str,
type: str = "archive",
game_ids: Optional[list[str]] = None,
game_ids: Optional[List[str]] = None,
after: Optional[str] = None,
):
game_ids = game_ids or []
@ -344,7 +344,7 @@ def channel_videos_generator(
max_videos: int,
sort: VideosSort,
type: VideosType,
game_ids: Optional[list[str]] = None,
game_ids: Optional[List[str]] = None,
) -> tuple[int, Generator[Video, None, None]]:
game_ids = game_ids or []
@ -386,7 +386,7 @@ def get_access_token(video_id: str, auth_token: Optional[str] = None) -> AccessT
}}
"""
headers: dict[str, str] = {}
headers: Mapping[str, str] = {}
if auth_token is not None:
headers["authorization"] = f"OAuth {auth_token}"
@ -443,7 +443,7 @@ def get_game_id(name: str):
return game["id"]
def get_video_chapters(video_id: str) -> list[Chapter]:
def get_video_chapters(video_id: str) -> List[Chapter]:
query = {
"operationName": "VideoPlayer_ChapterSelectButtonVideo",
"variables": {