Skip to content

Commit

Permalink
mkdir video
Browse files Browse the repository at this point in the history
  • Loading branch information
Benature committed Nov 10, 2023
1 parent 2d44404 commit 88d463d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
36 changes: 36 additions & 0 deletions video/srt2md.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from pathlib import Path
import sys
# import subprocess


# Get directory path from command line argument
directory_path = Path(sys.argv[1])

# Check if directory exists
if not directory_path.exists():
print("Directory does not exist.")
sys.exit()

# Use a list comprehension to extract all files with a .srt extension
srt_files = [file for file in directory_path.glob("*.srt")]

for srt_file in srt_files:
md_content = ""
with open(srt_file, 'r') as f:
lines = f.readlines()
for i in range(0, len(lines), 4):
start_time, _ = lines[i+1].strip().split(' --> ')
subtitle = lines[i+2].strip()
# print(start_time, subtitle)
t = start_time.split(',')[0]
md_content += f"{subtitle} [🔗](kmtrigger://macro=1E194478-AABF-46EA-A53B-872E0554DCC2&value={t}) \n"

md_file = (srt_file.parent / "md" / srt_file.stem).with_suffix('.md')
with open(md_file, 'w') as md_f:
md_f.write(md_content)


# # Convert all .md files in the directory to .pdf files using pandoc
# pdf_file = (md_file.parent / md_file.stem).with_suffix('.html')
# subprocess.run(['pandoc', str(md_file), '-o', str(pdf_file)])
# break
1 change: 1 addition & 0 deletions other/subtitle_JianYing.py → video/subtitle_JianYing.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def analysis_videos(data):
video_infos = []
for video in data['materials']['videos']:
if len(video_infos) > 0 and video_infos[-1].path==video['path']:
# merge for same file
video_infos[-1].duration += int(video['duration'])
else:
video_infos.append(VIDEO_INFO(video['path'], video['duration']))
Expand Down

0 comments on commit 88d463d

Please sign in to comment.