From 1b6b01ba0c608c75cb5f0771daf08c2651bc31e5 Mon Sep 17 00:00:00 2001 From: WyattBlue Date: Thu, 24 Oct 2024 02:59:59 -0400 Subject: [PATCH 1/2] Remove unused merge function --- auto_editor/utils/func.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/auto_editor/utils/func.py b/auto_editor/utils/func.py index 3fb6dfffd..b4fcd0bc3 100644 --- a/auto_editor/utils/func.py +++ b/auto_editor/utils/func.py @@ -81,17 +81,6 @@ def mut_margin(arr: BoolList, start_m: int, end_m: int) -> None: arr[max(i + end_m, 0) : i] = False -def merge(start_list: np.ndarray, end_list: np.ndarray) -> BoolList: - result = np.zeros((len(start_list)), dtype=np.bool_) - - for i, item in enumerate(start_list): - if item == True: - where = np.where(end_list[i:])[0] - if len(where) > 0: - result[i : where[0]] = True - return result - - def get_stdout(cmd: list[str]) -> str: from subprocess import DEVNULL, PIPE, Popen From f35716fec7c6bf2f9f44172da7daca3f9f438fd9 Mon Sep 17 00:00:00 2001 From: WyattBlue Date: Thu, 24 Oct 2024 03:16:58 -0400 Subject: [PATCH 2/2] Remove unused args, functions --- auto_editor/edit.py | 18 ++++++++++-------- auto_editor/formats/fcp7.py | 2 +- auto_editor/lang/palet.py | 4 +--- auto_editor/lang/stdenv.py | 7 ------- auto_editor/render/subtitle.py | 4 ++-- auto_editor/utils/cmdkw.py | 13 +++++-------- auto_editor/utils/func.py | 22 ---------------------- 7 files changed, 19 insertions(+), 51 deletions(-) diff --git a/auto_editor/edit.py b/auto_editor/edit.py index 012814bee..66c967587 100644 --- a/auto_editor/edit.py +++ b/auto_editor/edit.py @@ -3,6 +3,7 @@ import os import sys from fractions import Fraction +from os.path import splitext from subprocess import run from typing import Any @@ -11,7 +12,7 @@ from auto_editor.ffwrapper import FFmpeg, FileInfo, initFileInfo from auto_editor.lib.contracts import is_int, is_str -from auto_editor.make_layers import make_timeline +from auto_editor.make_layers import clipify, make_av, make_timeline from auto_editor.output import Ensure, parse_bitrate from auto_editor.render.audio import make_new_audio from auto_editor.render.subtitle import make_new_subtitles @@ -31,7 +32,7 @@ def set_output( if src is None: root, ext = "out", ".mp4" else: - root, ext = os.path.splitext(str(src.path) if out is None else out) + root, ext = splitext(src.path if out is None else out) if ext == "": ext = src.path.suffix @@ -164,7 +165,7 @@ def edit_media(paths: list[str], ffmpeg: FFmpeg, args: Args, log: Log) -> None: tl = None if paths: - path_ext = os.path.splitext(paths[0])[1].lower() + path_ext = splitext(paths[0])[1].lower() if path_ext == ".xml": from auto_editor.formats.fcp7 import fcp7_read_xml @@ -243,7 +244,7 @@ def edit_media(paths: list[str], ffmpeg: FFmpeg, args: Args, log: Log) -> None: from auto_editor.formats.fcp7 import fcp7_write_xml is_resolve = export.startswith("resolve") - fcp7_write_xml(export_ops["name"], output, is_resolve, tl, log) + fcp7_write_xml(export_ops["name"], output, is_resolve, tl) return if export == "final-cut-pro": @@ -267,7 +268,7 @@ def edit_media(paths: list[str], ffmpeg: FFmpeg, args: Args, log: Log) -> None: shotcut_write_mlt(output, tl) return - out_ext = os.path.splitext(output)[1].replace(".", "") + out_ext = splitext(output)[1].replace(".", "") # Check if export options make sense. ctr = container_constructor(out_ext.lower()) @@ -430,14 +431,15 @@ def make_media(tl: v3, output_path: str) -> None: if tl.v1 is None: log.error("Timeline too complex to use clip-sequence export") - from auto_editor.make_layers import clipify, make_av - from auto_editor.utils.func import append_filename - def pad_chunk(chunk: Chunk, total: int) -> Chunks: start = [] if chunk[0] == 0 else [(0, chunk[0], 99999.0)] end = [] if chunk[1] == total else [(chunk[1], total, 99999.0)] return start + [chunk] + end + def append_filename(path: str, val: str) -> str: + root, ext = splitext(path) + return root + val + ext + total_frames = tl.v1.chunks[-1][1] - 1 clip_num = 0 for chunk in tl.v1.chunks: diff --git a/auto_editor/formats/fcp7.py b/auto_editor/formats/fcp7.py index b51ba7bc1..fe6d2c9d2 100644 --- a/auto_editor/formats/fcp7.py +++ b/auto_editor/formats/fcp7.py @@ -485,7 +485,7 @@ def premiere_write_audio(audio: Element, make_filedef, src: FileInfo, tl: v3) -> audio.append(track) -def fcp7_write_xml(name: str, output: str, resolve: bool, tl: v3, log: Log) -> None: +def fcp7_write_xml(name: str, output: str, resolve: bool, tl: v3) -> None: width, height = tl.res timebase, ntsc = set_tb_ntsc(tl.tb) diff --git a/auto_editor/lang/palet.py b/auto_editor/lang/palet.py index 0e914fb70..baddaa764 100644 --- a/auto_editor/lang/palet.py +++ b/auto_editor/lang/palet.py @@ -353,9 +353,7 @@ def handle_strings() -> bool: if is_method: from auto_editor.utils.cmdkw import parse_method - return Token( - M, parse_method(name, result, env), self.lineno, self.column - ) + return Token(M, parse_method(name, result), self.lineno, self.column) if self.char == ".": # handle `object.method` syntax self.advance() diff --git a/auto_editor/lang/stdenv.py b/auto_editor/lang/stdenv.py index f5003d943..a1d402b5a 100644 --- a/auto_editor/lang/stdenv.py +++ b/auto_editor/lang/stdenv.py @@ -14,7 +14,6 @@ from numpy.typing import NDArray Number = int | float | complex | Fraction - Real = int | float | Fraction BoolList = NDArray[np.bool_] Node = tuple @@ -831,12 +830,6 @@ def _xor(*vals: Any) -> bool | BoolList: check_args("xor", vals, (2, None), (is_bool,)) return reduce(lambda a, b: a ^ b, vals) - def string_ref(s: str, ref: int) -> Char: - try: - return Char(s[ref]) - except IndexError: - raise MyError(f"string index {ref} is out of range") - def number_to_string(val: Number) -> str: if isinstance(val, complex): join = "" if val.imag < 0 else "+" diff --git a/auto_editor/render/subtitle.py b/auto_editor/render/subtitle.py index fe2910dc8..fee35cd52 100644 --- a/auto_editor/render/subtitle.py +++ b/auto_editor/render/subtitle.py @@ -157,7 +157,7 @@ def make_srt(input_: Input, stream: int) -> str: return output_bytes.getvalue() -def _ensure(input_: Input, format: str, stream: int, log: Log) -> str: +def _ensure(input_: Input, format: str, stream: int) -> str: output_bytes = io.BytesIO() output = av.open(output_bytes, "w", format=format) @@ -195,7 +195,7 @@ def make_new_subtitles(tl: v3, log: Log) -> list[str]: if sub.codec == "mov_text": ret = make_srt(input_, s) else: - ret = _ensure(input_, format, s, log) + ret = _ensure(input_, format, s) parser.parse(ret, sub.codec) parser.edit(tl.v1.chunks) diff --git a/auto_editor/utils/cmdkw.py b/auto_editor/utils/cmdkw.py index c8f294949..4566ff411 100644 --- a/auto_editor/utils/cmdkw.py +++ b/auto_editor/utils/cmdkw.py @@ -35,11 +35,6 @@ def __init__(self, name: str, *attrs: pAttr): self.attrs = attrs -def _norm_name(s: str) -> str: - # Python does not allow - in variable names - return s.replace("-", "_") - - class PLexer: __slots__ = ("text", "pos", "char") @@ -101,6 +96,10 @@ def parse_with_palet( KEYWORD_SEP = "=" kwargs: dict[str, Any] = {} + def _norm_name(s: str) -> str: + # Python does not allow - in variable names + return s.replace("-", "_") + def go(text: str, c: Any) -> Any: try: env = _env if isinstance(_env, Env) else Env(_env) @@ -174,9 +173,7 @@ def go(text: str, c: Any) -> Any: return kwargs -def parse_method( - name: str, text: str, env: Env -) -> tuple[str, list[Any], dict[str, Any]]: +def parse_method(name: str, text: str) -> tuple[str, list[Any], dict[str, Any]]: from auto_editor.lang.palet import Lexer, Parser # Positional Arguments diff --git a/auto_editor/utils/func.py b/auto_editor/utils/func.py index b4fcd0bc3..a779bc679 100644 --- a/auto_editor/utils/func.py +++ b/auto_editor/utils/func.py @@ -105,25 +105,3 @@ def gcd(a: int, b: int) -> int: c = gcd(width, height) return width // c, height // c - - -def human_readable_time(time_in_secs: float) -> str: - units = "seconds" - if time_in_secs >= 3600: - time_in_secs = round(time_in_secs / 3600, 1) - if time_in_secs % 1 == 0: - time_in_secs = round(time_in_secs) - units = "hours" - if time_in_secs >= 60: - time_in_secs = round(time_in_secs / 60, 1) - if time_in_secs >= 10 or time_in_secs % 1 == 0: - time_in_secs = round(time_in_secs) - units = "minutes" - return f"{time_in_secs} {units}" - - -def append_filename(path: str, val: str) -> str: - from os.path import splitext - - root, ext = splitext(path) - return root + val + ext