Thomas Aylott
commited on
json_captions — Download and parse the json caption tracks
Browse files- 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 |
|