Thomas Aylott commited on
Commit
d19b8d4
·
unverified ·
1 Parent(s): 84faec3

json_captions — Download and parse the json caption tracks

Browse files
Files changed (1) hide show
  1. pytube/captions.py +9 -0
pytube/captions.py CHANGED
@@ -42,6 +42,15 @@ class Caption:
42
  """Download the xml caption tracks."""
43
  return request.get(self.url)
44
 
 
 
 
 
 
 
 
 
 
45
  def generate_srt_captions(self) -> str:
46
  """Generate "SubRip Subtitle" captions.
47
 
 
42
  """Download the xml caption tracks."""
43
  return request.get(self.url)
44
 
45
+ @property
46
+ def json_captions(self) -> dict:
47
+ """Download and parse the json caption tracks."""
48
+ json_captions_url = self.url.replace('fmt=srv3','fmt=json3')
49
+ text = request.get(json_captions_url)
50
+ parsed = json.loads(text)
51
+ assert parsed['wireMagic'] == 'pb3', 'Unexpected captions format'
52
+ return parsed
53
+
54
  def generate_srt_captions(self) -> str:
55
  """Generate "SubRip Subtitle" captions.
56