Skip to content

Commit 1bf0e74

Browse files
committed
Move float->standard str used in PD2V & PLS to helpers
1 parent a377e90 commit 1bf0e74

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

pvsfunc/helpers.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@
44
from typing import Iterable, List
55

66

7+
def get_standard(aspect: float) -> str:
8+
"""Convert an aspect float to a standard string."""
9+
return {
10+
0: "?",
11+
24 / 1: "FILM",
12+
25 / 1: "PAL",
13+
50 / 1: "PALi",
14+
30000 / 1001: "NTSC",
15+
60000 / 1001: "NTSCi",
16+
24000 / 1001: "NTSC (FILM)"
17+
}[aspect]
18+
19+
720
def calculate_aspect_ratio(width: int, height: int) -> str:
821
"""Calculate the aspect-ratio gcd string from resolution."""
922
r = math.gcd(width, height)

pvsfunc/pd2v.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from pyd2v import D2V
1212
from vapoursynth import core
1313

14-
from pvsfunc.helpers import group_by_int, list_select_every, calculate_aspect_ratio, calculate_par
14+
from pvsfunc.helpers import group_by_int, list_select_every, calculate_aspect_ratio, calculate_par, get_standard
1515

1616

1717
class PD2V:
@@ -47,15 +47,7 @@ def __init__(self, file: str, verbose=False):
4747
coded_f = len(self.flags)
4848
progressive_f = sum(f["progressive_frame"] for f in self.flags)
4949
progressive_p = (progressive_f / coded_f) * 100
50-
standard = {
51-
0: "?",
52-
24 / 1: "FILM",
53-
25 / 1: "PAL",
54-
50 / 1: "PALi",
55-
30000 / 1001: "NTSC",
56-
60000 / 1001: "NTSCi",
57-
24000 / 1001: "NTSC (FILM)"
58-
}[self.clip.fps.numerator / self.clip.fps.denominator]
50+
standard = get_standard(self.clip.fps.numerator / self.clip.fps.denominator)
5951
dar = self.d2v.settings["Aspect_Ratio"]
6052
if isinstance(dar, list):
6153
dar = dar[0]

pvsfunc/pls.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from pymediainfo import MediaInfo
77
from vapoursynth import core
88

9-
from pvsfunc.helpers import calculate_aspect_ratio
9+
from pvsfunc.helpers import calculate_aspect_ratio, get_standard
1010

1111

1212
class PLS:
@@ -32,15 +32,7 @@ def __init__(self, file: str, verbose=False):
3232
)
3333

3434
if verbose:
35-
standard = {
36-
0: "?",
37-
24 / 1: "FILM",
38-
25 / 1: "PAL",
39-
50 / 1: "PALi",
40-
30000 / 1001: "NTSC",
41-
60000 / 1001: "NTSCi",
42-
24000 / 1001: "NTSC (FILM)"
43-
}[self.clip.fps.numerator / self.clip.fps.denominator]
35+
standard = get_standard(self.clip.fps.numerator / self.clip.fps.denominator)
4436
sar = calculate_aspect_ratio(self.clip.width, self.clip.height)
4537
self.clip = core.text.Text(
4638
self.clip,

0 commit comments

Comments
 (0)