Skip to content

Commit

Permalink
Merge pull request #1438 from subtleGradient/json_captions
Browse files Browse the repository at this point in the history
`caption.json_captions` — Download and parse the "json3" caption tracks
  • Loading branch information
nficano committed Dec 17, 2022
2 parents 84faec3 + d19b8d4 commit fb5d450
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pytube/captions.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ def xml_captions(self) -> str:
"""Download the xml caption tracks."""
return request.get(self.url)

@property
def json_captions(self) -> dict:
"""Download and parse the json caption tracks."""
json_captions_url = self.url.replace('fmt=srv3','fmt=json3')
text = request.get(json_captions_url)
parsed = json.loads(text)
assert parsed['wireMagic'] == 'pb3', 'Unexpected captions format'
return parsed

def generate_srt_captions(self) -> str:
"""Generate "SubRip Subtitle" captions.
Expand Down

0 comments on commit fb5d450

Please sign in to comment.