Created
September 12, 2023 23:06
-
-
Save sarmadgulzar/428bf024d0901f7d93d137fafa0b3ae8 to your computer and use it in GitHub Desktop.
Stitch YouTube subtitles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| data = {} | |
| with open("timedtext.json") as file: | |
| data = json.load(file) | |
| def extract_text(data): | |
| strings = [] | |
| for item in data.get("events", []): | |
| segs = item.get("segs", []) | |
| for seg in segs: | |
| strings.append(seg["utf8"]) | |
| return "".join(strings) | |
| result = extract_text(data) | |
| print(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment