added caption track docs
Browse files- docs/user/quickstart.rst +53 -4
docs/user/quickstart.rst
CHANGED
@@ -133,7 +133,7 @@ Pytube allows you to filter on every property available (see
|
|
133 |
:py:meth:`pytube.StreamQuery.filter` for a complete list of filter options),
|
134 |
let's take a look at some common examples:
|
135 |
|
136 |
-
Query audio only
|
137 |
------------------------
|
138 |
|
139 |
To query the streams that contain only the audio track::
|
@@ -142,10 +142,10 @@ To query the streams that contain only the audio track::
|
|
142 |
[<Stream: itag="140" mime_type="audio/mp4" abr="128kbps" acodec="mp4a.40.2">,
|
143 |
<Stream: itag="171" mime_type="audio/webm" abr="128kbps" acodec="vorbis">]
|
144 |
|
145 |
-
Query
|
146 |
-
|
147 |
|
148 |
-
To query
|
149 |
|
150 |
>>> yt.streams.filter(file_extension='mp4').all()
|
151 |
[<Stream: itag="22" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.64001F" acodec="mp4a.40.2">,
|
@@ -157,3 +157,52 @@ To query the streams that are encoded as mp4::
|
|
157 |
<Stream: itag="133" mime_type="video/mp4" res="240p" fps="30fps" vcodec="avc1.4d4015">,
|
158 |
<Stream: itag="160" mime_type="video/mp4" res="144p" fps="30fps" vcodec="avc1.4d400c">,
|
159 |
<Stream: itag="140" mime_type="audio/mp4" abr="128kbps" acodec="mp4a.40.2">]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
:py:meth:`pytube.StreamQuery.filter` for a complete list of filter options),
|
134 |
let's take a look at some common examples:
|
135 |
|
136 |
+
Query audio only Streams
|
137 |
------------------------
|
138 |
|
139 |
To query the streams that contain only the audio track::
|
|
|
142 |
[<Stream: itag="140" mime_type="audio/mp4" abr="128kbps" acodec="mp4a.40.2">,
|
143 |
<Stream: itag="171" mime_type="audio/webm" abr="128kbps" acodec="vorbis">]
|
144 |
|
145 |
+
Query MPEG-4 Streams
|
146 |
+
--------------------
|
147 |
|
148 |
+
To query only streams in the MPEG-4 format::
|
149 |
|
150 |
>>> yt.streams.filter(file_extension='mp4').all()
|
151 |
[<Stream: itag="22" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.64001F" acodec="mp4a.40.2">,
|
|
|
157 |
<Stream: itag="133" mime_type="video/mp4" res="240p" fps="30fps" vcodec="avc1.4d4015">,
|
158 |
<Stream: itag="160" mime_type="video/mp4" res="144p" fps="30fps" vcodec="avc1.4d400c">,
|
159 |
<Stream: itag="140" mime_type="audio/mp4" abr="128kbps" acodec="mp4a.40.2">]
|
160 |
+
|
161 |
+
Get Streams by itag
|
162 |
+
-------------------
|
163 |
+
|
164 |
+
To get a stream by a specific itag::
|
165 |
+
|
166 |
+
>>> yt.streams.get_by_itag('22')
|
167 |
+
<Stream: itag="22" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.64001F" acodec="mp4a.40.2">
|
168 |
+
|
169 |
+
Subtitle/Caption Tracks
|
170 |
+
=======================
|
171 |
+
|
172 |
+
Pytube exposes the caption tracks in much the same way as querying the media
|
173 |
+
streams. Let's begin by switching to a video that contains them::
|
174 |
+
|
175 |
+
>>> yt = YouTube('https://youtube.com/watch?v=XJGiS83eQLk')
|
176 |
+
>>> yt.captions.all()
|
177 |
+
[<Caption lang="Arabic" code="ar">,
|
178 |
+
<Caption lang="English (auto-generated)" code="en">,
|
179 |
+
<Caption lang="English" code="en">,
|
180 |
+
<Caption lang="English (United Kingdom)" code="en-GB">,
|
181 |
+
<Caption lang="German" code="de">,
|
182 |
+
<Caption lang="Greek" code="el">,
|
183 |
+
<Caption lang="Indonesian" code="id">,
|
184 |
+
<Caption lang="Sinhala" code="si">,
|
185 |
+
<Caption lang="Spanish" code="es">,
|
186 |
+
<Caption lang="Turkish" code="tr">]
|
187 |
+
|
188 |
+
Now let's checkout the english captions::
|
189 |
+
|
190 |
+
>>> caption = yt.captions.get_by_language_code('en')
|
191 |
+
|
192 |
+
Great, now let's see how YouTube formats them::
|
193 |
+
|
194 |
+
>>> caption.xml_captions
|
195 |
+
'<?xml version="1.0" encoding="utf-8" ?><transcript><text start="0" dur="5.541">well i&#39...'
|
196 |
+
|
197 |
+
Oh, this isn't very easy to work with, let's convert them to the srt format::
|
198 |
+
|
199 |
+
>>> print(caption.generate_srt_captions())
|
200 |
+
1
|
201 |
+
000:000:00,000 --> 000:000:05,541
|
202 |
+
well i'm just an editor and i dont know what to type
|
203 |
+
|
204 |
+
2
|
205 |
+
000:000:05,541 --> 000:000:12,321
|
206 |
+
not new to video. In fact, most films before 1930 were silent and used captions with video
|
207 |
+
|
208 |
+
...
|