add sections to readme
Browse files- README.md +9 -2
- pytube/monostate.py +2 -2
README.md
CHANGED
@@ -87,6 +87,9 @@ Next, let's explore how we would view what video streams are available:
|
|
87 |
<Stream: itag="250" mime_type="audio/webm" abr="70kbps" acodec="opus">,
|
88 |
<Stream: itag="251" mime_type="audio/webm" abr="160kbps" acodec="opus">]
|
89 |
```
|
|
|
|
|
|
|
90 |
You may notice that some streams listed have both a video codec and audio codec, while others have just video or just audio, this is a result of YouTube supporting a streaming technique called Dynamic Adaptive Streaming over HTTP (DASH).
|
91 |
|
92 |
In the context of pytube, the implications are for the highest quality streams; you now need to download both the audio and video tracks and then post-process them with software like FFmpeg to merge them.
|
@@ -139,6 +142,8 @@ You can also download a complete Youtube playlist:
|
|
139 |
This will download the highest progressive stream available (generally 720p) from the given playlist. Later more options would be given for user's flexibility
|
140 |
to choose video resolution.
|
141 |
|
|
|
|
|
142 |
Pytube allows you to filter on every property available (see the documentation for the complete list), let's take a look at some of the most useful ones.
|
143 |
|
144 |
To list the audio only streams:
|
@@ -190,10 +195,12 @@ If you need to optimize for a specific feature, such as the "highest resolution"
|
|
190 |
```
|
191 |
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.
|
192 |
|
|
|
|
|
193 |
If your application requires post-processing logic, pytube allows you to specify an "on download complete" callback function:
|
194 |
|
195 |
```python
|
196 |
-
>>> def convert_to_aac(stream,
|
197 |
return # do work
|
198 |
|
199 |
>>> yt.register_on_complete_callback(convert_to_aac)
|
@@ -202,7 +209,7 @@ If your application requires post-processing logic, pytube allows you to specify
|
|
202 |
Similarly, if your application requires on-download progress logic, pytube exposes a callback for this as well:
|
203 |
|
204 |
```python
|
205 |
-
>>> def show_progress_bar(stream, chunk,
|
206 |
return # do work
|
207 |
|
208 |
>>> yt.register_on_progress_callback(show_progress_bar)
|
|
|
87 |
<Stream: itag="250" mime_type="audio/webm" abr="70kbps" acodec="opus">,
|
88 |
<Stream: itag="251" mime_type="audio/webm" abr="160kbps" acodec="opus">]
|
89 |
```
|
90 |
+
|
91 |
+
### Selecting an itag
|
92 |
+
|
93 |
You may notice that some streams listed have both a video codec and audio codec, while others have just video or just audio, this is a result of YouTube supporting a streaming technique called Dynamic Adaptive Streaming over HTTP (DASH).
|
94 |
|
95 |
In the context of pytube, the implications are for the highest quality streams; you now need to download both the audio and video tracks and then post-process them with software like FFmpeg to merge them.
|
|
|
142 |
This will download the highest progressive stream available (generally 720p) from the given playlist. Later more options would be given for user's flexibility
|
143 |
to choose video resolution.
|
144 |
|
145 |
+
### Filtering
|
146 |
+
|
147 |
Pytube allows you to filter on every property available (see the documentation for the complete list), let's take a look at some of the most useful ones.
|
148 |
|
149 |
To list the audio only streams:
|
|
|
195 |
```
|
196 |
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.
|
197 |
|
198 |
+
### Callbacks
|
199 |
+
|
200 |
If your application requires post-processing logic, pytube allows you to specify an "on download complete" callback function:
|
201 |
|
202 |
```python
|
203 |
+
>>> def convert_to_aac(stream, file_handler):
|
204 |
return # do work
|
205 |
|
206 |
>>> yt.register_on_complete_callback(convert_to_aac)
|
|
|
209 |
Similarly, if your application requires on-download progress logic, pytube exposes a callback for this as well:
|
210 |
|
211 |
```python
|
212 |
+
>>> def show_progress_bar(stream, chunk, file_handler, bytes_remaining):
|
213 |
return # do work
|
214 |
|
215 |
>>> yt.register_on_progress_callback(show_progress_bar)
|
pytube/monostate.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
-
from __future__ import annotations
|
2 |
-
|
3 |
import io
|
4 |
from typing import Any, Optional
|
5 |
from typing_extensions import Protocol
|
6 |
|
|
|
|
|
7 |
|
8 |
class OnProgress(Protocol):
|
9 |
def __call__(
|
|
|
|
|
|
|
1 |
import io
|
2 |
from typing import Any, Optional
|
3 |
from typing_extensions import Protocol
|
4 |
|
5 |
+
# from __future__ import annotations
|
6 |
+
|
7 |
|
8 |
class OnProgress(Protocol):
|
9 |
def __call__(
|