diff --git a/editing/captions/6/en.srt b/editing/captions/6/en.srt index fb0f3e2..04987ea 100644 --- a/editing/captions/6/en.srt +++ b/editing/captions/6/en.srt @@ -2057,4 +2057,3 @@ thanks a lot for answering all my questions, going deep into 01:00:15,335 --> 01:00:21,018 the history and into the technical parts. It's really awesome. It was really a pleasure. - diff --git a/editing/captions/6/ru.srt b/editing/captions/6/ru.srt index 63d5e86..a4ad449 100644 --- a/editing/captions/6/ru.srt +++ b/editing/captions/6/ru.srt @@ -2485,4 +2485,3 @@ IBM взяла на вооружение технологию Intel для пр 622 01:00:19,790000 --> 01:00:21,210000 это было действительно приятно. - diff --git a/editing/pyproject.toml b/editing/pyproject.toml index d1f2714..02e5953 100644 --- a/editing/pyproject.toml +++ b/editing/pyproject.toml @@ -19,3 +19,12 @@ srt = "^3.5" [build-system] requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" + + +[tool.ruff] +line-length = 80 +fix = true + +[tool.ruff.lint] +select = ['F', 'I'] +fixable = ['ALL'] diff --git a/editing/srt-from-json.py b/editing/srt-from-json.py index 4bb10e7..570ace1 100644 --- a/editing/srt-from-json.py +++ b/editing/srt-from-json.py @@ -1,43 +1,50 @@ -import sys -import json import datetime as dt +import json +import sys from typing import Final -_TIME_FORMAT: Final = '%H:%M:%S,%f' +_TIME_FORMAT: Final = "%H:%M:%S,%f" def _srt_from_json(filepath: str) -> int: - with open(filepath, encoding='utf8') as json_file: + with open(filepath, encoding="utf8") as json_file: contents = json.loads(json_file.read()) start_time = None resulting_lines = [] - for index, entry in enumerate(contents['subtitles']): + for index, entry in enumerate(contents["subtitles"]): # Number - resulting_lines.append(f'{index + 1}\n') + resulting_lines.append(f"{index + 1}\n") # Time if start_time is None: start_time = dt.datetime( - year=1, month=1, day=1, hour=0, minute=0, second=0, - ) + dt.timedelta(milliseconds=entry['startMs']) - end = start_time + dt.timedelta(milliseconds=entry['durationMs']) - resulting_lines.append('{0} --> {1}\n'.format( - start_time.strftime(_TIME_FORMAT), - end.strftime(_TIME_FORMAT), - )) + year=1, + month=1, + day=1, + hour=0, + minute=0, + second=0, + ) + dt.timedelta(milliseconds=entry["startMs"]) + end = start_time + dt.timedelta(milliseconds=entry["durationMs"]) + resulting_lines.append( + "{0} --> {1}\n".format( + start_time.strftime(_TIME_FORMAT), + end.strftime(_TIME_FORMAT), + ) + ) start_time = None # Content - resulting_lines.append(entry['text']) + resulting_lines.append(entry["text"]) # Newlines - resulting_lines.extend(['\n'] * 2) + resulting_lines.extend(["\n"] * 2) - with open('out.srt', 'w', encoding='utf8') as output_file: + with open("out.srt", "w", encoding="utf8") as output_file: output_file.writelines(resulting_lines) return 0 -if __name__ == '__main__': +if __name__ == "__main__": sys.exit(_srt_from_json(filepath=sys.argv[1])) diff --git a/editing/srt-shift.py b/editing/srt-shift.py index 3d13bae..4c689bc 100644 --- a/editing/srt-shift.py +++ b/editing/srt-shift.py @@ -1,6 +1,6 @@ import argparse -import sys import datetime as dt +import sys from io import TextIOWrapper import srt @@ -33,23 +33,27 @@ def _cut_since_with_duration( for caption in captions: if caption.index >= since: caption.start = _update_time( - caption.start, delta, is_negative=is_negative, + caption.start, + delta, + is_negative=is_negative, ) caption.end = _update_time( - caption.end, delta, is_negative=is_negative, + caption.end, + delta, + is_negative=is_negative, ) updated_srt.append(caption) - with open('out.srt', mode='w', encoding='utf8') as out: + with open("out.srt", mode="w", encoding="utf8") as out: out.write(srt.compose(updated_srt)) -if __name__ == '__main__': +if __name__ == "__main__": parser = argparse.ArgumentParser(__name__) - parser.add_argument('fileobj', type=argparse.FileType()) - parser.add_argument('--since', type=int) - parser.add_argument('--seconds', type=int) - parser.add_argument('--negative', action='store_true') + parser.add_argument("fileobj", type=argparse.FileType()) + parser.add_argument("--since", type=int) + parser.add_argument("--seconds", type=int) + parser.add_argument("--negative", action="store_true") args = parser.parse_args() code = _cut_since_with_duration( diff --git a/lectures/0-intro.key b/lectures/0-intro.key index 6e341c7..33cbd6c 100755 Binary files a/lectures/0-intro.key and b/lectures/0-intro.key differ diff --git a/lectures/1-int.key b/lectures/1-int.key index aff685d..dcdc803 100755 Binary files a/lectures/1-int.key and b/lectures/1-int.key differ diff --git a/lectures/2-+.key b/lectures/2-+.key index 86ab2da..0105815 100755 Binary files a/lectures/2-+.key and b/lectures/2-+.key differ diff --git a/lectures/3-what-is-python.key b/lectures/3-what-is-python.key index ba77b04..40fffc1 100755 Binary files a/lectures/3-what-is-python.key and b/lectures/3-what-is-python.key differ diff --git a/lectures/4-bool.key b/lectures/4-bool.key index 2675b54..fb45488 100755 Binary files a/lectures/4-bool.key and b/lectures/4-bool.key differ diff --git a/lectures/5-None.key b/lectures/5-None.key index 0142fbe..7e3c9f7 100755 Binary files a/lectures/5-None.key and b/lectures/5-None.key differ diff --git a/lectures/6-float.key b/lectures/6-float.key index b5cf28d..e3dbb93 100755 Binary files a/lectures/6-float.key and b/lectures/6-float.key differ