Skip to content

Commit

Permalink
Always use utf-8, fix mypy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed Jul 24, 2023
1 parent b33118f commit 7bb559e
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 20 deletions.
8 changes: 4 additions & 4 deletions auto_editor/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def read_cache(self, tag: str, obj: dict[str, Any]) -> None | np.ndarray:
)

try:
with open(workfile) as file:
with open(workfile, encoding="utf-8") as file:
cache = Parser(Lexer(workfile, file)).expr()
except Exception:
return None
Expand All @@ -232,7 +232,7 @@ def cache(self, tag: str, obj: dict[str, Any], arr: np.ndarray) -> np.ndarray:
key = obj_tag(tag, self.tb, obj)

try:
with open(workfile) as file:
with open(workfile, encoding="utf-8") as file:
json_object = Parser(Lexer(workfile, file)).expr()
except Exception:
json_object = {}
Expand All @@ -249,7 +249,7 @@ def cache(self, tag: str, obj: dict[str, Any], arr: np.ndarray) -> np.ndarray:
else:
json_object[src_key] = {key: entry}

with open(os.path.join(workdur, "cache.json"), "w") as file:
with open(os.path.join(workdur, "cache.json"), "w", encoding="utf-8") as file:
dump(json_object, file)

return arr
Expand Down Expand Up @@ -330,7 +330,7 @@ def subtitle(
)
parser = SubtitleParser(self.tb)

with open(sub_file) as file:
with open(sub_file, encoding="utf-8") as file:
parser.parse(file.read(), "webvtt")

# stackoverflow.com/questions/9662346/python-code-to-remove-html-tags-from-a-string
Expand Down
2 changes: 1 addition & 1 deletion auto_editor/formats/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def read_v1(tl: Any, ffmpeg: FFmpeg, log: Log) -> v3:


def read_json(path: str, ffmpeg: FFmpeg, log: Log) -> v3:
with open(path) as f:
with open(path, encoding="utf-8", errors="ignore") as f:
try:
tl = Parser(Lexer(path, f)).expr()
except MyError as e:
Expand Down
13 changes: 9 additions & 4 deletions auto_editor/formats/shotcut.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
from __future__ import annotations

import xml.etree.ElementTree as ET
from typing import TYPE_CHECKING, Any, cast

from auto_editor.ffwrapper import FFmpeg
from auto_editor.timeline import v3
from auto_editor.utils.func import aspect_ratio, to_timecode
from auto_editor.utils.log import Log

if TYPE_CHECKING:
from collections.abc import Sequence

from auto_editor.ffwrapper import FFmpeg
from auto_editor.timeline import TlAudio, TlVideo
from auto_editor.utils.log import Log

"""
Shotcut uses the MLT timeline format
Expand Down Expand Up @@ -78,13 +84,12 @@ def shotcut_write_mlt(output: str, tl: v3) -> None:
producers = 0

if tl.v:
clips = tl.v[0]
clips: Sequence[TlVideo | TlAudio] = cast(Any, tl.v[0])
elif tl.a:
clips = tl.a[0]
else:
clips = []


for clip in clips:
src = tl.sources[clip.src]
length = to_timecode((clip.offset / clip.speed + clip.dur) / tb, "standard")
Expand Down
6 changes: 3 additions & 3 deletions auto_editor/render/subtitle.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def edit(self, chunks: Chunks) -> None:
self.contents = new_content

def write(self, file_path: str) -> None:
with open(file_path, "w") as file:
with open(file_path, "w", encoding="utf-8") as file:
file.write(self.header)
for c in self.contents:
file.write(
Expand All @@ -135,12 +135,12 @@ def make_new_subtitles(tl: v3, ffmpeg: FFmpeg, temp: str, log: Log) -> list[str]
parser = SubtitleParser(tl.tb)

if sub.codec in parser.supported_codecs:
with open(file_path) as file:
with open(file_path, encoding="utf-8") as file:
parser.parse(file.read(), sub.codec)
else:
convert_path = os.path.join(temp, f"{s}s_convert.vtt")
ffmpeg.run(["-i", file_path, convert_path])
with open(convert_path) as file:
with open(convert_path, encoding="utf-8") as file:
parser.parse(file.read(), "webvtt")

parser.edit(tl.v1.chunks)
Expand Down
2 changes: 1 addition & 1 deletion auto_editor/subcommands/palet.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

def main(sys_args: list[str] = sys.argv[1:]) -> None:
if sys_args:
with open(sys_args[0]) as file:
with open(sys_args[0], encoding="utf-8", errors="ignore") as file:
program_text = file.read()

try:
Expand Down
10 changes: 3 additions & 7 deletions auto_editor/timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,8 @@ def as_dict(self) -> dict:
}


class Tl:
pass


@dataclass
class TlVideo(Tl):
class TlVideo:
start: int
dur: int
src: str
Expand All @@ -46,7 +42,7 @@ class TlVideo(Tl):


@dataclass
class TlAudio(Tl):
class TlAudio:
start: int
dur: int
src: str
Expand All @@ -58,7 +54,7 @@ class TlAudio(Tl):


@dataclass
class _Visual(Tl):
class _Visual:
start: int
dur: int
x: int | float
Expand Down

0 comments on commit 7bb559e

Please sign in to comment.