Skip to content

Commit

Permalink
mypy/flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
LightArrowsEXE committed Aug 27, 2024
1 parent fc9e232 commit 39abe57
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
8 changes: 4 additions & 4 deletions vsdeinterlace/wobbly/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __apply_fieldmatches(
return clip.std.FrameEval(lambda n: match_clips.get(matches[n]))

def __apply_freezeframes(
self, clip: vs.VideoNode, freezes: set[FreezeFrame] = [],
self, clip: vs.VideoNode, freezes: set[FreezeFrame],
func_except: FuncExceptT | None = None
) -> vs.VideoNode:
"""Apply freezeframes to a clip."""
Expand Down Expand Up @@ -69,7 +69,7 @@ def __apply_freezeframes(
)

def __deinterlace_orphans(
self, clip: vs.VideoNode, orphans: Sequence[OrphanField] = [],
self, clip: vs.VideoNode, orphans: Sequence[OrphanField],
func_except: FuncExceptT | None = None
) -> vs.VideoNode:
"""Deinterlace orphaned fields."""
Expand Down Expand Up @@ -98,11 +98,11 @@ def __apply_combed_markers(self, clip: vs.VideoNode, combed_frames: set[int]) ->
return replace_ranges(
clip.std.SetFrameProps(wobbly_combed=0),
clip.std.SetFrameProps(wobbly_combed=1),
combed_frames
list(combed_frames)
)

def __apply_interlaced_fades(
self, clip: vs.VideoNode, ifades: set[InterlacedFade] = [],
self, clip: vs.VideoNode, ifades: set[InterlacedFade],
func_except: FuncExceptT | None = None
) -> vs.VideoNode:
# TODO: Figure out how to get the right `color` param per frame with an eval.
Expand Down
31 changes: 19 additions & 12 deletions vsdeinterlace/wobbly/wibbly.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import json
from dataclasses import dataclass, field
from typing import Any
from typing import Any, cast

from vstools import (CustomValueError, FramePropError, FunctionUtil, Keyframes,
SPath, SPathLike, clip_async_render, core, get_prop,
get_y, normalize_ranges, vs)

from .._metadata import __version__
from .info import WibblyConfig
from .info import FrameMetric, WibblyConfig, WibblyConfigSettings
from .types import Match

__all__ = [
Expand All @@ -26,12 +26,13 @@ class Wibbly:
trims: list[tuple[int | None, int | None]] | None = None
metrics: list[FrameMetric] = field(default_factory=list[FrameMetric])

# TODO: refactor
def _get_clip(self, display: bool = False) -> vs.VideoNode:
src, out_props = self.clip, list[str]()

func = FunctionUtil(src, Wibbly, None, (vs.YUV, vs.GRAY), 8)

wclip = func.work_clip
wclip = cast(vs.VideoNode, func.work_clip)

if not display:
norm_trims = normalize_ranges(func.work_clip, self.trims)
Expand Down Expand Up @@ -65,14 +66,16 @@ def _get_clip(self, display: bool = False) -> vs.VideoNode:
odd_avg = separated[1::2].std.PlaneStats()

if hasattr(core, 'akarin'):
wclip = core.akarin.PropExpr(
wclip = core.akarin.PropExpr( # type:ignore
[wclip, even_avg, odd_avg],
lambda: {'WibblyFieldDiff': 'y.PlaneStatsAverage z.PlaneStatsAverage - abs'}
)
else:
def _selector(n: int, f: list[vs.VideoFrame]) -> vs.VideoFrame:
f_out = f[0].copy()
f_out.props.WibblyFieldDiff = abs(f[1].props.PlaneStatsAverage - f[2].props.PlaneStatsAverage)
f_out.props.WibblyFieldDiff = abs(
f[1].props.PlaneStatsAverage - f[2].props.PlaneStatsAverage # type:ignore
)
return f_out

wclip = core.std.ModifyFrame(wclip.std.BlankClip(), [wclip, even_avg, odd_avg], _selector)
Expand Down Expand Up @@ -176,8 +179,7 @@ def all_matches_to_c(self) -> None:
self.all_matches_to_c
)

for metric in self.metrics:
metric.match = "c"
self.metrics = [metric._replace(match='c') for metric in self.metrics]

def _to_sections(self, scenechanges: list[int]) -> list[dict[str, Any]]:
if not scenechanges:
Expand Down Expand Up @@ -246,7 +248,7 @@ def _build_wob_json(self, video_path: SPath, metrics: list[FrameMetric]) -> dict
def _process_metrics(
self, metrics: list[FrameMetric]
) -> tuple[
list[int], list[int], list[Match], list[int], list[int],
list[list[int] | None], list[list[int] | None], list[Match | None], list[int], list[int],
list[int | None], list[int], list[dict[str, int | float]]
]:
"""Process all the metrics."""
Expand All @@ -269,12 +271,17 @@ def _process_metrics(
if metric.is_keyframe:
scenechanges.append(i)

if metric.field_diff >= self.config.fade_thr:
ifades.append({"frame": i, "field difference": metric.field_diff})
if self.config.fade_thr is not None:
assert isinstance(metric.field_diff, float), "Field difference must be a float!"

if metric.field_diff >= self.config.fade_thr:
ifades.append({"frame": i, "field difference": metric.field_diff})

return mics, mmetrics, matches, combed, dec_drop, dec_metrics, scenechanges, ifades

def _parse_config(self, config: WibblyConfigSettings | None) -> dict[str, Any]:
def _parse_config(
self, config: WibblyConfigSettings.VMFParams | WibblyConfigSettings.VDECParams | None
) -> dict[str, Any]:
"""Convert the config to a dictionary and handle boolean values."""

return {
Expand All @@ -293,7 +300,7 @@ def _get_resolution(self) -> tuple[int, int]:

return width, height

def _write_to_file(self, out_path: SPath, data: dict[str, Any]):
def _write_to_file(self, out_path: SPath, data: dict[str, Any]) -> None:
"""Write the JSON data to a file."""

out_path.touch(exist_ok=True)
Expand Down
6 changes: 3 additions & 3 deletions vsdeinterlace/wobbly/wobbly.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __init__(self, file_path: SPathLike, func_except: FuncExceptT | None = None)
with wob_file.open('r') as f:
self._wob_data: dict[str, Any] = dict(json.load(f))

self.work_clip = WobblyVideo( # type:ignore[call-arg]
self.work_clip = WobblyVideo(
self.__get_val("input file"),
self.__get_val("source filter"),
self.__get_val("trim", []),
Expand Down Expand Up @@ -319,7 +319,7 @@ def __get_orphans_to_process(
if isinstance(process, bool):
matches_check = orphan_matches
elif any(m in ('b', 'n', 'p', 'u') for m in list(process)):
matches_check = list(process) # type:ignore[list-item]
matches_check = list(process)
else:
raise CustomTypeError(
"Expected type (bool | OrphanMatch | Sequence[OrphanMatch]), "
Expand Down Expand Up @@ -371,7 +371,7 @@ def section_keyframes(self) -> Keyframes:
# TODO: Create a keyframes property that takes decimation into account.
return Keyframes([i.start_frame for i in self.sections])

#! TODO: Calculate the timecodes from the information provided, not a clip.
# TODO: Calculate the timecodes from the information provided, not a clip.
@property
def timecodes(self) -> Timecodes:
"""The timecodes represented as a Timecode object."""
Expand Down

0 comments on commit 39abe57

Please sign in to comment.