Skip to content

Instantly share code, notes, and snippets.

@sarmadgulzar
Created September 12, 2023 23:06
Show Gist options
  • Select an option

  • Save sarmadgulzar/428bf024d0901f7d93d137fafa0b3ae8 to your computer and use it in GitHub Desktop.

Select an option

Save sarmadgulzar/428bf024d0901f7d93d137fafa0b3ae8 to your computer and use it in GitHub Desktop.
Stitch YouTube subtitles
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