mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-27 03:15:08 +00:00
feat(dl): add --sample and --include-sample
--sample downloads only a time window of a title (default 120-180 s) and cuts the mux to it. --include-sample cuts a 60 s sample from a finished file. Both write to a Sample folder with a SAMPLE tag on the filename
This commit is contained in:
@@ -9,7 +9,7 @@ from enum import Enum
|
||||
from functools import partial
|
||||
from io import BytesIO
|
||||
from pathlib import Path
|
||||
from typing import Any, Callable, Iterable, Optional, Union
|
||||
from typing import Any, Callable, Iterable, Optional, Sequence, Union
|
||||
|
||||
import pycaption
|
||||
import requests
|
||||
@@ -1001,6 +1001,32 @@ class Subtitle(Track):
|
||||
|
||||
return captions, language
|
||||
|
||||
def sample_slice(
|
||||
self, starts: Sequence[float], timescale: float = 1, window: Optional[tuple[int, int]] = None
|
||||
) -> slice:
|
||||
"""Keep every segment: ``trim`` cuts a subtitle by its cue times after the download."""
|
||||
return slice(None)
|
||||
|
||||
def trim(self, start: float, end: float) -> bool:
|
||||
"""Keep the cues between ``start`` and ``end`` seconds and move them to start at zero.
|
||||
|
||||
Returns False and leaves the file whole when pysubs2 cannot read or write its format.
|
||||
"""
|
||||
import pysubs2
|
||||
|
||||
low, high = round(start * 1000), round(end * 1000)
|
||||
try:
|
||||
subs = pysubs2.load(str(self.path), encoding="utf-8")
|
||||
subs.events = [event for event in subs.events if event.end > low and event.start < high]
|
||||
for event in subs.events:
|
||||
event.start = max(event.start, low) - low
|
||||
event.end = min(event.end, high) - low
|
||||
subs.save(str(self.path))
|
||||
except (pysubs2.exceptions.Pysubs2Error, UnicodeDecodeError):
|
||||
return False
|
||||
self.sample_start = start
|
||||
return True
|
||||
|
||||
def strip_hearing_impaired(self) -> None:
|
||||
"""
|
||||
Remove the SDH captions.
|
||||
|
||||
Reference in New Issue
Block a user