mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-26 10:55:08 +00:00
feat(dl): add daily date-based episodes with tvdb air-date fill
--daily flag plus Service.DAILY/Title.daily, -w selection by ISO air date or colon date range, and a pre-1970 air-date guard.
This commit is contained in:
@@ -422,6 +422,7 @@ def _perform_download(
|
||||
"tvdb_order": params.get("tvdb_order"),
|
||||
"anilist_id": params.get("anilist_id"),
|
||||
"enrich": params.get("enrich", False),
|
||||
"daily": params.get("daily", False),
|
||||
"output_dir": Path(params["output_dir"]) if params.get("output_dir") else None,
|
||||
"no_cache": params.get("no_cache", False),
|
||||
"reset_cache": params.get("reset_cache", False),
|
||||
@@ -454,6 +455,7 @@ def _perform_download(
|
||||
tvdb_order=params.get("tvdb_order"),
|
||||
anilist_id=params.get("anilist_id"),
|
||||
enrich=params.get("enrich", False),
|
||||
daily=params.get("daily", False),
|
||||
output_dir=Path(params["output_dir"]) if params.get("output_dir") else None,
|
||||
)
|
||||
# Per-request CDM override (a device name in the WVDs dir); get_cdm() takes it first.
|
||||
|
||||
@@ -80,6 +80,7 @@ DEFAULT_DOWNLOAD_PARAMS = {
|
||||
"tvdb_order": None,
|
||||
"anilist_id": None,
|
||||
"enrich": False,
|
||||
"daily": False,
|
||||
"output_dir": None,
|
||||
"no_cache": False,
|
||||
"reset_cache": False,
|
||||
|
||||
@@ -767,6 +767,9 @@ async def download(request: web.Request) -> web.Response:
|
||||
enrich:
|
||||
type: boolean
|
||||
description: Overwrite show title, year and original language with the external source's. Requires one of tmdb_id, imdb_id, tvdb_id or anilist_id (default - false)
|
||||
daily:
|
||||
type: boolean
|
||||
description: Treat the title as daily/date-based content and fill missing air dates from TVDB. Needs enrich (default - false)
|
||||
no_folder:
|
||||
type: boolean
|
||||
description: Disable folder creation for TV shows (default - false)
|
||||
|
||||
@@ -94,6 +94,7 @@ class Service(metaclass=ABCMeta):
|
||||
ALIASES: tuple[str, ...] = () # list of aliases for the service; alternatives to the service tag.
|
||||
GEOFENCE: tuple[str, ...] = () # list of ip regions required to use the service. empty list == no specific region.
|
||||
ANIME: bool = False # service catalogue is anime; metadata lookups prefer AniList. Title.anime overrides per title.
|
||||
DAILY: bool = False # catalog is daily/date-based. episodes are named by air date. Title.daily overrides per title.
|
||||
# vault namespace override; when set, key vault read/write uses this tag instead of the service's own.
|
||||
VAULT_TAG: Optional[str] = None
|
||||
# Auth methods the service accepts ("cookies"/"credentials"); when None the REST /services
|
||||
|
||||
@@ -108,6 +108,9 @@ class Episode(Title):
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
if isinstance(air_date, date) and air_date.year < 1970:
|
||||
raise ValueError(f"Episode air date cannot be {air_date}")
|
||||
|
||||
self.title = title
|
||||
self.season = season
|
||||
self.number = number
|
||||
@@ -122,10 +125,13 @@ class Episode(Title):
|
||||
"""Whether a parsed ``-w`` key set selects this episode.
|
||||
|
||||
A part-ful episode answers to both its base key and its part key, so ``-w s1e1``
|
||||
takes every part. ``!`` keys are part-qualified exclusions resolved here.
|
||||
takes every part. A dated episode also answers to its ISO air date.
|
||||
``!`` keys are part-qualified exclusions resolved here.
|
||||
"""
|
||||
base = f"{self.season}x{self.number}"
|
||||
keys = (base,) if self.part is None else (base, f"{base}.{self.part}")
|
||||
if isinstance(self.air_date, date):
|
||||
keys = (*keys, self.air_date.isoformat())
|
||||
if any(f"!{k}" in wanted for k in keys):
|
||||
return False
|
||||
return any(k in wanted for k in keys)
|
||||
|
||||
@@ -48,6 +48,7 @@ class Title:
|
||||
self.language = language
|
||||
self.data = data
|
||||
self.anime: Optional[bool] = None
|
||||
self.daily: Optional[bool] = None
|
||||
|
||||
self.tracks = Tracks()
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import re
|
||||
from datetime import date, timedelta
|
||||
from typing import Any, Optional, Union
|
||||
|
||||
import click
|
||||
@@ -176,6 +177,23 @@ class SeasonRange(click.ParamType):
|
||||
MAX_EPISODE = 999
|
||||
MIN_PART = 1
|
||||
MAX_PART = 99
|
||||
MAX_DATE_SPAN = 1000
|
||||
|
||||
DATE_TOKEN = re.compile(r"^(?P<left>\d{4}-\d{2}-\d{2})(:(?P<right>\d{4}-\d{2}-\d{2}))?$")
|
||||
|
||||
def _parse_date_token(self, token: str, match: re.Match) -> list[str]:
|
||||
"""Expand an ISO date token or ':'-separated date range into ISO day keys."""
|
||||
try:
|
||||
left = date.fromisoformat(match.group("left"))
|
||||
right = date.fromisoformat(match.group("right")) if match.group("right") else left
|
||||
except ValueError:
|
||||
self.fail(f"Invalid date, must be a real YYYY-MM-DD date: {token}")
|
||||
if left > right:
|
||||
self.fail(f"Invalid range, left side date cannot be later than right side date: {token}")
|
||||
span = (right - left).days + 1
|
||||
if span > self.MAX_DATE_SPAN:
|
||||
self.fail(f"Invalid range, a date range cannot span more than {self.MAX_DATE_SPAN} days: {token}")
|
||||
return [(left + timedelta(days=i)).isoformat() for i in range(span)]
|
||||
|
||||
def parse_tokens(self, *tokens: str) -> list[str]:
|
||||
"""
|
||||
@@ -186,6 +204,9 @@ class SeasonRange(click.ParamType):
|
||||
is not knowable here. A part-qualified exclusion cannot be removed from the
|
||||
computed keys (they are base keys), so it becomes a '!' key resolved at match time.
|
||||
|
||||
Dated content is addressed by ISO air date. A date range uses ':' only, because
|
||||
a date's own '-' separators are not a range separator.
|
||||
|
||||
Supports exclusioning by putting a `-` before the token.
|
||||
|
||||
Example:
|
||||
@@ -200,6 +221,10 @@ class SeasonRange(click.ParamType):
|
||||
["1x1.1", "1x1.2", "1x1.3"]
|
||||
>>> sr.parse_tokens("S01E01", "-S01E01.2")
|
||||
["1x1", "!1x1.2"]
|
||||
>>> sr.parse_tokens("2026-08-11")
|
||||
["2026-08-11"]
|
||||
>>> sr.parse_tokens("2026-08-01:2026-08-03", "-2026-08-02")
|
||||
["2026-08-01", "2026-08-03"]
|
||||
"""
|
||||
if len(tokens) == 0:
|
||||
return []
|
||||
@@ -209,6 +234,11 @@ class SeasonRange(click.ParamType):
|
||||
exclude = token.startswith("-")
|
||||
if exclude:
|
||||
token = token[1:]
|
||||
# dates carry their own '-' separators, so they must be read before the range split
|
||||
date_match = self.DATE_TOKEN.match(token)
|
||||
if date_match:
|
||||
(computed if not exclude else exclusions).extend(self._parse_date_token(token, date_match))
|
||||
continue
|
||||
parsed = [
|
||||
re.match(r"^S(?P<season>\d+)(E(?P<episode>\d+)(\.(?P<part>\d+))?)?$", x, re.IGNORECASE)
|
||||
for x in re.split(r"[:-]", token)
|
||||
|
||||
Reference in New Issue
Block a user