updated readme
Browse files- README.rst +48 -9
README.rst
CHANGED
@@ -34,7 +34,7 @@ Installation
|
|
34 |
|
35 |
Download using pip via pypi.
|
36 |
|
37 |
-
.. code:: bash
|
38 |
|
39 |
pip install pytube
|
40 |
|
@@ -87,7 +87,7 @@ The legacy streams that contain the audio and video in a single file (referred t
|
|
87 |
|
88 |
To only view these progressive download streams:
|
89 |
|
90 |
-
.. code::
|
91 |
|
92 |
>>> yt.streams.filter(progressive=True).all()
|
93 |
[<Stream: itag="22" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.64001F" acodec="mp4a.40.2">,
|
@@ -98,7 +98,7 @@ To only view these progressive download streams:
|
|
98 |
|
99 |
Conversely, if you only want to see the DASH streams (also referred to as "adaptive") you can do:
|
100 |
|
101 |
-
.. code::
|
102 |
|
103 |
>>> yt.streams.filter(adaptive=True).all()
|
104 |
[<Stream: itag="137" mime_type="video/mp4" res="1080p" fps="30fps" vcodec="avc1.640028">,
|
@@ -124,7 +124,7 @@ Pytube allows you to filter on every property available (see the documentation f
|
|
124 |
|
125 |
To list the audio only streams:
|
126 |
|
127 |
-
.. code::
|
128 |
|
129 |
>>> yt.streams.filter(only_audio=True).all()
|
130 |
[<Stream: itag="140" mime_type="audio/mp4" abr="128kbps" acodec="mp4a.40.2">,
|
@@ -136,7 +136,7 @@ To list the audio only streams:
|
|
136 |
|
137 |
To list only ``mp4`` streams:
|
138 |
|
139 |
-
.. code::
|
140 |
|
141 |
>>> yt.streams.filter(subtype='mp4').all()
|
142 |
[<Stream: itag="22" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.64001F" acodec="mp4a.40.2">,
|
@@ -152,7 +152,7 @@ To list only ``mp4`` streams:
|
|
152 |
|
153 |
Multiple filters can also be specified:
|
154 |
|
155 |
-
.. code::
|
156 |
|
157 |
>>> yt.streams.filter(subtype='mp4', progressive=True).all()
|
158 |
>>> # this can also be expressed as:
|
@@ -162,7 +162,7 @@ Multiple filters can also be specified:
|
|
162 |
|
163 |
You also have an interface to select streams by their itag, without needing to filter:
|
164 |
|
165 |
-
.. code::
|
166 |
|
167 |
>>> yt.streams.get_by_itag(22)
|
168 |
<Stream: itag="22" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.64001F" acodec="mp4a.40.2">
|
@@ -170,8 +170,47 @@ You also have an interface to select streams by their itag, without needing to f
|
|
170 |
|
171 |
If you need to optimize for a specific feature, such as the "highest resolution" or "lowest average bitrate":
|
172 |
|
173 |
-
.. code::
|
174 |
-
>>> yt.streams.filter(progressive=True).order_by('resolution').desc().all()
|
175 |
|
|
|
176 |
|
177 |
Note that ``order_by`` cannot be used if your attribute is undefined in any of the Stream instances, so be sure to apply a filter to remove those before calling it.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
Download using pip via pypi.
|
36 |
|
37 |
+
.. code-block:: bash
|
38 |
|
39 |
pip install pytube
|
40 |
|
|
|
87 |
|
88 |
To only view these progressive download streams:
|
89 |
|
90 |
+
.. code-block:: python
|
91 |
|
92 |
>>> yt.streams.filter(progressive=True).all()
|
93 |
[<Stream: itag="22" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.64001F" acodec="mp4a.40.2">,
|
|
|
98 |
|
99 |
Conversely, if you only want to see the DASH streams (also referred to as "adaptive") you can do:
|
100 |
|
101 |
+
.. code-block:: python
|
102 |
|
103 |
>>> yt.streams.filter(adaptive=True).all()
|
104 |
[<Stream: itag="137" mime_type="video/mp4" res="1080p" fps="30fps" vcodec="avc1.640028">,
|
|
|
124 |
|
125 |
To list the audio only streams:
|
126 |
|
127 |
+
.. code-block:: python
|
128 |
|
129 |
>>> yt.streams.filter(only_audio=True).all()
|
130 |
[<Stream: itag="140" mime_type="audio/mp4" abr="128kbps" acodec="mp4a.40.2">,
|
|
|
136 |
|
137 |
To list only ``mp4`` streams:
|
138 |
|
139 |
+
.. code-block:: python
|
140 |
|
141 |
>>> yt.streams.filter(subtype='mp4').all()
|
142 |
[<Stream: itag="22" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.64001F" acodec="mp4a.40.2">,
|
|
|
152 |
|
153 |
Multiple filters can also be specified:
|
154 |
|
155 |
+
.. code-block:: python
|
156 |
|
157 |
>>> yt.streams.filter(subtype='mp4', progressive=True).all()
|
158 |
>>> # this can also be expressed as:
|
|
|
162 |
|
163 |
You also have an interface to select streams by their itag, without needing to filter:
|
164 |
|
165 |
+
.. code-block:: python
|
166 |
|
167 |
>>> yt.streams.get_by_itag(22)
|
168 |
<Stream: itag="22" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.64001F" acodec="mp4a.40.2">
|
|
|
170 |
|
171 |
If you need to optimize for a specific feature, such as the "highest resolution" or "lowest average bitrate":
|
172 |
|
173 |
+
.. code-block:: python
|
|
|
174 |
|
175 |
+
>>> yt.streams.filter(progressive=True).order_by('resolution').desc().all()
|
176 |
|
177 |
Note that ``order_by`` cannot be used if your attribute is undefined in any of the Stream instances, so be sure to apply a filter to remove those before calling it.
|
178 |
+
|
179 |
+
If your application requires post-processing logic, pytube allows you to specify an "on download complete" callback function:
|
180 |
+
|
181 |
+
.. code-block:: python
|
182 |
+
|
183 |
+
>>> def convert_to_aac(stream, file_handle):
|
184 |
+
# do work
|
185 |
+
>>> yt.register_on_complete_callback(convert_to_aac)
|
186 |
+
|
187 |
+
|
188 |
+
Similarly, if your application requires on-download progress logic, pytube exposes a callback for this as well:
|
189 |
+
|
190 |
+
.. code-block:: python
|
191 |
+
|
192 |
+
>>> def show_progress_bar(stream, chunk, file_handle, bytes_remaining):
|
193 |
+
# do work
|
194 |
+
>>> yt.register_on_progress_callback(show_progress_bar)
|
195 |
+
|
196 |
+
|
197 |
+
|
198 |
+
Command-line interface
|
199 |
+
======================
|
200 |
+
|
201 |
+
pytube also ships with a tiny cli interface for downloading and probing videos.
|
202 |
+
|
203 |
+
Let's start with downloading:
|
204 |
+
|
205 |
+
.. code-block:: bash
|
206 |
+
|
207 |
+
pytube http://youtube.com/watch?v=9bZkp7q19f0 --itag=22
|
208 |
+
|
209 |
+
To view available streams:
|
210 |
+
|
211 |
+
.. code-block:: bash
|
212 |
+
|
213 |
+
pytube http://youtube.com/watch?v=9bZkp7q19f0 --list
|
214 |
+
|
215 |
+
|
216 |
+
Finally, if you're filing a bug report, the cli contains a switch called ``--build-playback-report``, which bundles up the state, allowing others to easily replay your issue.
|