From 88d463dc97859fee6964efc6979bc3caf73a1885 Mon Sep 17 00:00:00 2001 From: Benature Date: Fri, 10 Nov 2023 15:58:05 +0800 Subject: [PATCH] mkdir video --- video/srt2md.py | 36 +++++++++++++++++++++++++++ {other => video}/subtitle_JianYing.py | 1 + 2 files changed, 37 insertions(+) create mode 100644 video/srt2md.py rename {other => video}/subtitle_JianYing.py (99%) diff --git a/video/srt2md.py b/video/srt2md.py new file mode 100644 index 0000000..4bbab4d --- /dev/null +++ b/video/srt2md.py @@ -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 diff --git a/other/subtitle_JianYing.py b/video/subtitle_JianYing.py similarity index 99% rename from other/subtitle_JianYing.py rename to video/subtitle_JianYing.py index 609febb..c6e020f 100644 --- a/other/subtitle_JianYing.py +++ b/video/subtitle_JianYing.py @@ -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']))