Skip to content

Commit

Permalink
Don't need ffmpeg for reading json
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed Mar 6, 2024
1 parent 390b232 commit c098ab1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 19 deletions.
2 changes: 1 addition & 1 deletion auto_editor/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def edit_media(
elif path_ext == ".json":
from auto_editor.formats.json import read_json

tl = read_json(paths[0], ffmpeg, log)
tl = read_json(paths[0], log)
sources = [] if tl.src is None else [tl.src]
src = tl.src
else:
Expand Down
12 changes: 6 additions & 6 deletions auto_editor/formats/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from fractions import Fraction
from typing import Any

from auto_editor.ffwrapper import FFmpeg, FileInfo, initFileInfo
from auto_editor.ffwrapper import FileInfo, initFileInfo
from auto_editor.lang.json import Lexer, Parser, dump
from auto_editor.lib.err import MyError
from auto_editor.timeline import (
Expand Down Expand Up @@ -42,7 +42,7 @@ def check_file(path: str, log: Log) -> None:
log.error(f"Could not locate media file: '{path}'")


def read_v3(tl: Any, ffmpeg: FFmpeg, log: Log) -> v3:
def read_v3(tl: Any, log: Log) -> v3:
check_attrs(
tl,
log,
Expand Down Expand Up @@ -158,7 +158,7 @@ def parse_obj(obj: dict[str, Any], build: pAttrs) -> dict[str, Any]:
return v3(src, tb, sr, res, bg, v, a, v1=None)


def read_v1(tl: Any, ffmpeg: FFmpeg, log: Log) -> v3:
def read_v1(tl: Any, log: Log) -> v3:
from auto_editor.make_layers import clipify

check_attrs(tl, log, "source", "chunks")
Expand Down Expand Up @@ -194,7 +194,7 @@ def read_v1(tl: Any, ffmpeg: FFmpeg, log: Log) -> v3:
)


def read_json(path: str, ffmpeg: FFmpeg, log: Log) -> v3:
def read_json(path: str, log: Log) -> v3:
with open(path, encoding="utf-8", errors="ignore") as f:
try:
tl = Parser(Lexer(path, f)).expr()
Expand All @@ -206,9 +206,9 @@ def read_json(path: str, ffmpeg: FFmpeg, log: Log) -> v3:
ver = tl["version"]

if ver == "3":
return read_v3(tl, ffmpeg, log)
return read_v3(tl, log)
if ver == "1":
return read_v1(tl, ffmpeg, log)
return read_v1(tl, log)
if type(ver) is not str:
log.error("version needs to be a string")
log.error(f"Importing version {ver} timelines is not supported.")
Expand Down
13 changes: 2 additions & 11 deletions auto_editor/subcommands/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from dataclasses import dataclass, field
from typing import Any, Literal, TypedDict

from auto_editor.ffwrapper import FFmpeg, initFileInfo
from auto_editor.ffwrapper import initFileInfo
from auto_editor.lang.json import dump
from auto_editor.timeline import v3
from auto_editor.utils.func import aspect_ratio
Expand All @@ -16,21 +16,13 @@
@dataclass(slots=True)
class InfoArgs:
json: bool = False
ffmpeg_location: str | None = None
my_ffmpeg: bool = False
help: bool = False
input: list[str] = field(default_factory=list)


def info_options(parser: ArgumentParser) -> ArgumentParser:
parser.add_required("input", nargs="*")
parser.add_argument("--json", flag=True, help="Export info in JSON format")
parser.add_argument("--ffmpeg-location", help="Point to your custom ffmpeg file")
parser.add_argument(
"--my-ffmpeg",
flag=True,
help="Use the ffmpeg on your PATH instead of the one packaged",
)
return parser


Expand Down Expand Up @@ -83,7 +75,6 @@ class MediaJson(TypedDict, total=False):
def main(sys_args: list[str] = sys.argv[1:]) -> None:
args = info_options(ArgumentParser("info")).parse_args(InfoArgs, sys_args)

ffmpeg = FFmpeg(args.ffmpeg_location, args.my_ffmpeg)
log = Log(quiet=not args.json)

file_info: dict[str, MediaJson] = {}
Expand All @@ -96,7 +87,7 @@ def main(sys_args: list[str] = sys.argv[1:]) -> None:
if ext == ".json":
from auto_editor.formats.json import read_json

tl = read_json(file, ffmpeg, log)
tl = read_json(file, log)
file_info[file] = {"type": "timeline"}
file_info[file]["version"] = "v3" if isinstance(tl, v3) else "v1"

Expand Down
2 changes: 1 addition & 1 deletion auto_editor/subcommands/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import numpy as np

from auto_editor.ffwrapper import FFmpeg, FileInfo, initFileInfo
from auto_editor.ffwrapper import FileInfo, initFileInfo
from auto_editor.lang.palet import Lexer, Parser, env, interpret
from auto_editor.lib.data_structs import Char
from auto_editor.lib.err import MyError
Expand Down

0 comments on commit c098ab1

Please sign in to comment.