Skip to content

Commit

Permalink
剪映 subtitle
Browse files Browse the repository at this point in the history
  • Loading branch information
Benature committed Feb 26, 2023
1 parent 67d26ec commit 8b94a83
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
**/.DS_Store
*.zip
**/out/*
!**/out/.gitkeep
Empty file added other/out/.gitkeep
Empty file.
54 changes: 54 additions & 0 deletions other/subtitle_JianYing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import json
import re


def secToTimecode(t):
s, ms = divmod(t, 1000)
m, s = divmod(s, 60)
h, m = divmod(m, 60)
return "%02d:%02d:%02d,%03d" % (h, m, s, ms)


print(r'''draft_info.json
- Windows: C:\Users\Admin\AppData\Local\JianyingPro\User Data\Projects\com.lveditor.draft
- Android: /data/data/com.lemon.lv/files/newdrafts/
- MacOS: /Users/Admin/Movies/JianyinPro/User Data/Projects/com.lveditor.draft/'''
)

json_path = input("`draft_info.json` path of JianYing: ")
with open(json_path, "r") as f:
data = json.load(f)

text_list = data['materials']['texts']
texts_dict = {t['id']: t for t in text_list}

srt_index = 1
srt_content, raw_content = "", ""
contents = []
for track in data['tracks']:
for segment in track['segments']:
text_id = segment['material_id']

if text_id not in texts_dict:
continue

timerange = segment['target_timerange']
content = texts_dict[text_id]['content']
content = re.sub(r"</?(?:font|color|size).*?>", "",
content).strip("[]")

contents.append(content)

startTime = secToTimecode(int(timerange["start"]) / 1000)
endTime = secToTimecode(
(int(timerange["start"]) + int(timerange["duration"])) / 1000)

srt_content += f'{srt_index}\n{startTime} --> {endTime}\n{content}\n\n'
raw_content += f'{content}\n'
srt_index += 1

with open(f"out/subtitle.srt", "w") as f:
f.write(srt_content)

with open(f"out/subtitle.txt", "w") as f:
f.write("\n".join(contents))
1 change: 1 addition & 0 deletions spider/video/download_ts_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ async def fetch(client, url, folder):
async with client.get(url) as resp:
assert resp.status == 200
content = await resp.read()
# content = await resp.text()
with open(file_path, 'bw') as f:
f.write(content)
print("", ts_name, end="|")
Expand Down

0 comments on commit 8b94a83

Please sign in to comment.