forked from kenzuya/unshackle
style: turn on ruff UP and B rules and fix every finding
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
from typing import Union
|
||||
|
||||
from .episode import Episode, Series
|
||||
from .movie import Movie, Movies
|
||||
from .music import Album, Music, Song
|
||||
|
||||
Title_T = Union[Movie, Episode, Song]
|
||||
Titles_T = Union[Movies, Series, Music, Album]
|
||||
Title_T = Movie | Episode | Song
|
||||
Titles_T = Movies | Series | Music | Album
|
||||
|
||||
|
||||
def remap_titles(titles: Titles_T, title_map: dict) -> Titles_T:
|
||||
|
||||
@@ -4,14 +4,14 @@ Keep this allowlist separate from title.data: that dict can contain credentials,
|
||||
playback URLs and other private service state which must never cross the API.
|
||||
"""
|
||||
|
||||
from typing import Any, Dict, Optional
|
||||
from typing import Any
|
||||
|
||||
|
||||
def availability_metadata(value: Any) -> Optional[Dict[str, Any]]:
|
||||
def availability_metadata(value: Any) -> dict[str, Any] | None:
|
||||
"""Return only well-typed display fields; absent metadata remains absent."""
|
||||
if not isinstance(value, dict):
|
||||
return None
|
||||
result: Dict[str, Any] = {}
|
||||
result: dict[str, Any] = {}
|
||||
if isinstance(value.get("paid"), bool):
|
||||
result["paid"] = value["paid"]
|
||||
access = value.get("access")
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import re
|
||||
from abc import ABC
|
||||
from collections import Counter
|
||||
from collections.abc import Collection, Iterable
|
||||
from datetime import date, datetime
|
||||
from typing import Any, Collection, Iterable, Optional, Union
|
||||
from typing import Any
|
||||
|
||||
from langcodes import Language
|
||||
from pymediainfo import MediaInfo
|
||||
@@ -19,8 +20,8 @@ from unshackle.core.utils.template_formatter import TemplateFormatter, detect_sp
|
||||
class Episode(Title):
|
||||
# class-level defaults so Episodes restored from an older title cache read as part-less,
|
||||
# without an absolute number and not as sport
|
||||
part: Optional[int] = None
|
||||
absolute: Optional[int] = None
|
||||
part: int | None = None
|
||||
absolute: int | None = None
|
||||
sport: bool = False
|
||||
|
||||
def __init__(
|
||||
@@ -28,16 +29,16 @@ class Episode(Title):
|
||||
id_: Any,
|
||||
service: type,
|
||||
title: str,
|
||||
season: Union[int, str],
|
||||
number: Union[int, str],
|
||||
name: Optional[str] = None,
|
||||
year: Optional[Union[int, str]] = None,
|
||||
language: Optional[Union[str, Language]] = None,
|
||||
data: Optional[Any] = None,
|
||||
description: Optional[str] = None,
|
||||
air_date: Optional[Union[date, str]] = None,
|
||||
part: Optional[Union[int, str]] = None,
|
||||
absolute: Optional[Union[int, str]] = None,
|
||||
season: int | str,
|
||||
number: int | str,
|
||||
name: str | None = None,
|
||||
year: int | str | None = None,
|
||||
language: str | Language | None = None,
|
||||
data: Any | None = None,
|
||||
description: str | None = None,
|
||||
air_date: date | str | None = None,
|
||||
part: int | str | None = None,
|
||||
absolute: int | str | None = None,
|
||||
sport: bool = False,
|
||||
) -> None:
|
||||
super().__init__(id_, service, language, data)
|
||||
@@ -224,7 +225,7 @@ class Episode(Title):
|
||||
def get_filename(self, media_info: MediaInfo, folder: bool = False, show_service: bool = True) -> str:
|
||||
if folder:
|
||||
sports = self.sport and bool(config.folder_templates.get("sports"))
|
||||
template: Optional[str] = config.get_folder_template("sports" if sports else "series")
|
||||
template: str | None = config.get_folder_template("sports" if sports else "series")
|
||||
if template:
|
||||
# all parts of an episode land in the same season folder
|
||||
context = self.build_template_context(media_info, show_service, include_part=False)
|
||||
@@ -283,7 +284,7 @@ class Episode(Title):
|
||||
|
||||
|
||||
class Series(SortedKeyList, ABC):
|
||||
def __init__(self, iterable: Optional[Iterable] = None) -> None:
|
||||
def __init__(self, iterable: Iterable | None = None) -> None:
|
||||
# part slots before year so existing ties still resolve by year
|
||||
super().__init__(iterable, key=lambda x: (x.season, x.number, x.part or 0, x.year or 0))
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import re
|
||||
from abc import ABC
|
||||
from typing import Any, Iterable, Optional, Union
|
||||
from collections.abc import Iterable
|
||||
from typing import Any
|
||||
|
||||
from langcodes import Language
|
||||
from pymediainfo import MediaInfo
|
||||
@@ -20,10 +21,10 @@ class Movie(Title):
|
||||
id_: Any,
|
||||
service: type,
|
||||
name: str,
|
||||
year: Optional[Union[int, str]] = None,
|
||||
language: Optional[Union[str, Language]] = None,
|
||||
data: Optional[Any] = None,
|
||||
description: Optional[str] = None,
|
||||
year: int | str | None = None,
|
||||
language: str | Language | None = None,
|
||||
data: Any | None = None,
|
||||
description: str | None = None,
|
||||
) -> None:
|
||||
super().__init__(id_, service, language, data)
|
||||
|
||||
@@ -61,7 +62,7 @@ class Movie(Title):
|
||||
|
||||
def get_filename(self, media_info: MediaInfo, folder: bool = False, show_service: bool = True) -> str:
|
||||
if folder:
|
||||
template: Optional[str] = config.get_folder_template("movies")
|
||||
template: str | None = config.get_folder_template("movies")
|
||||
if template:
|
||||
context = self.build_template_context(media_info, show_service)
|
||||
spacer = detect_spacer(template) # one style for the whole path
|
||||
@@ -86,7 +87,7 @@ class Movie(Title):
|
||||
|
||||
|
||||
class Movies(SortedKeyList, ABC):
|
||||
def __init__(self, iterable: Optional[Iterable] = None) -> None:
|
||||
def __init__(self, iterable: Iterable | None = None) -> None:
|
||||
super().__init__(iterable, key=lambda x: x.year or 0)
|
||||
|
||||
def __str__(self) -> str:
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import re
|
||||
from abc import ABC
|
||||
from typing import Any, Collection, Iterable, Optional, Union
|
||||
from collections.abc import Collection, Iterable
|
||||
from typing import Any
|
||||
|
||||
from langcodes import Language
|
||||
from pymediainfo import MediaInfo
|
||||
@@ -85,23 +86,23 @@ class Song(Title):
|
||||
album: str,
|
||||
track: int,
|
||||
disc: int = 1,
|
||||
year: Optional[int] = None,
|
||||
language: Optional[Union[str, Language]] = None,
|
||||
data: Optional[Any] = None,
|
||||
album_artist: Optional[str] = None,
|
||||
year: int | None = None,
|
||||
language: str | Language | None = None,
|
||||
data: Any | None = None,
|
||||
album_artist: str | None = None,
|
||||
release_type: str = "album",
|
||||
total_tracks: Optional[int] = None,
|
||||
total_discs: Optional[int] = None,
|
||||
genre: Optional[str] = None,
|
||||
explicit: Optional[bool] = None,
|
||||
isrc: Optional[str] = None,
|
||||
upc: Optional[str] = None,
|
||||
copyright: Optional[str] = None,
|
||||
label: Optional[str] = None,
|
||||
lyrics: Optional[str] = None,
|
||||
artwork_url: Optional[str] = None,
|
||||
synced_lyrics: Optional[str] = None,
|
||||
lyrics_suffix: Optional[str] = None,
|
||||
total_tracks: int | None = None,
|
||||
total_discs: int | None = None,
|
||||
genre: str | None = None,
|
||||
explicit: bool | None = None,
|
||||
isrc: str | None = None,
|
||||
upc: str | None = None,
|
||||
copyright: str | None = None,
|
||||
label: str | None = None,
|
||||
lyrics: str | None = None,
|
||||
artwork_url: str | None = None,
|
||||
synced_lyrics: str | None = None,
|
||||
lyrics_suffix: str | None = None,
|
||||
) -> None:
|
||||
"""`lyrics` is the plain text the tagger embeds.
|
||||
|
||||
@@ -275,17 +276,17 @@ class Music(SortedKeyList, ABC):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
iterable: Optional[Iterable] = None,
|
||||
iterable: Iterable | None = None,
|
||||
kind: str = "album",
|
||||
title: Optional[str] = None,
|
||||
artist: Optional[str] = None,
|
||||
year: Optional[int] = None,
|
||||
total_tracks: Optional[int] = None,
|
||||
total_discs: Optional[int] = None,
|
||||
artwork_url: Optional[str] = None,
|
||||
total_duration: Optional[int] = None,
|
||||
owner: Optional[str] = None,
|
||||
description: Optional[str] = None,
|
||||
title: str | None = None,
|
||||
artist: str | None = None,
|
||||
year: int | None = None,
|
||||
total_tracks: int | None = None,
|
||||
total_discs: int | None = None,
|
||||
artwork_url: str | None = None,
|
||||
total_duration: int | None = None,
|
||||
owner: str | None = None,
|
||||
description: str | None = None,
|
||||
) -> None:
|
||||
if not isinstance(kind, str):
|
||||
raise TypeError(f"Expected kind to be a str, not {kind!r}")
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from abc import abstractmethod
|
||||
from typing import Any, Optional, Union
|
||||
from typing import Any
|
||||
|
||||
from langcodes import Language
|
||||
from pymediainfo import MediaInfo
|
||||
@@ -17,7 +17,7 @@ from unshackle.core.tracks import Tracks, Video
|
||||
from unshackle.core.utilities import spoken_language, standard_resolution
|
||||
|
||||
|
||||
def rename(name: Optional[str]) -> str:
|
||||
def rename(name: str | None) -> str:
|
||||
"""Return the user's `codec_names` override for a filename label, read here so per-service overrides are covered."""
|
||||
value = config.codec_names.get(name, name) if name else name
|
||||
return "" if value is None else str(value)
|
||||
@@ -25,7 +25,7 @@ def rename(name: Optional[str]) -> str:
|
||||
|
||||
class Title:
|
||||
def __init__(
|
||||
self, id_: Any, service: type, language: Optional[Union[str, Language]] = None, data: Optional[Any] = None
|
||||
self, id_: Any, service: type, language: str | Language | None = None, data: Any | None = None
|
||||
) -> None:
|
||||
"""
|
||||
Media Title from a Service.
|
||||
@@ -59,8 +59,8 @@ class Title:
|
||||
self.service = service
|
||||
self.language = language
|
||||
self.data: Any = data
|
||||
self.anime: Optional[bool] = None
|
||||
self.daily: Optional[bool] = None
|
||||
self.anime: bool | None = None
|
||||
self.daily: bool | None = None
|
||||
|
||||
self.tracks = Tracks()
|
||||
|
||||
@@ -82,7 +82,7 @@ class Title:
|
||||
primary_audio_track = next(
|
||||
(
|
||||
t
|
||||
for t, lang in zip(media_info.audio_tracks, spoken_audio)
|
||||
for t, lang in zip(media_info.audio_tracks, spoken_audio, strict=True)
|
||||
if original_lang_tag and lang == original_lang_tag
|
||||
),
|
||||
next(iter(media_info.audio_tracks), None),
|
||||
|
||||
Reference in New Issue
Block a user