Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pyproject.toml #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion editing/captions/6/en.srt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

1 change: 0 additions & 1 deletion editing/captions/6/ru.srt
Original file line number Diff line number Diff line change
Expand Up @@ -2485,4 +2485,3 @@ IBM взяла на вооружение технологию Intel для пр
622
01:00:19,790000 --> 01:00:21,210000
это было действительно приятно.

9 changes: 9 additions & 0 deletions editing/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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']
41 changes: 24 additions & 17 deletions editing/srt-from-json.py
Original file line number Diff line number Diff line change
@@ -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]))
22 changes: 13 additions & 9 deletions editing/srt-shift.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import argparse
import sys
import datetime as dt
import sys
from io import TextIOWrapper

import srt
Expand Down Expand Up @@ -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(
Expand Down
Binary file modified lectures/0-intro.key
Binary file not shown.
Binary file modified lectures/1-int.key
Binary file not shown.
Binary file modified lectures/2-+.key
Binary file not shown.
Binary file modified lectures/3-what-is-python.key
Binary file not shown.
Binary file modified lectures/4-bool.key
Binary file not shown.
Binary file modified lectures/5-None.key
Binary file not shown.
Binary file modified lectures/6-float.key
Binary file not shown.