update docs, repr's return lists
Browse files- README.md +12 -14
- pytube/contrib/playlist.py +3 -0
- pytube/query.py +6 -0
README.md
CHANGED
@@ -36,14 +36,12 @@ $ pip install pytube3 --upgrade
|
|
36 |
## Quick start
|
37 |
```python
|
38 |
>>> from pytube import YouTube
|
39 |
-
>>> YouTube('https://youtu.be/9bZkp7q19f0').streams.
|
40 |
>>>
|
41 |
>>> yt = YouTube('http://youtube.com/watch?v=9bZkp7q19f0')
|
42 |
>>> yt.streams
|
43 |
... .filter(progressive=True, file_extension='mp4')
|
44 |
-
... .order_by('resolution')
|
45 |
-
... .desc()
|
46 |
-
... .first()
|
47 |
... .download()
|
48 |
```
|
49 |
|
@@ -64,7 +62,7 @@ Let's begin with showing how easy it is to download a video with pytube:
|
|
64 |
|
65 |
```python
|
66 |
>>> from pytube import YouTube
|
67 |
-
>>> YouTube('http://youtube.com/watch?v=9bZkp7q19f0').streams.
|
68 |
```
|
69 |
This example will download the highest quality progressive download stream available.
|
70 |
|
@@ -72,7 +70,7 @@ Next, let's explore how we would view what video streams are available:
|
|
72 |
|
73 |
```python
|
74 |
>>> yt = YouTube('http://youtube.com/watch?v=9bZkp7q19f0')
|
75 |
-
>>> yt.streams
|
76 |
[<Stream: itag="22" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.64001F" acodec="mp4a.40.2">,
|
77 |
<Stream: itag="43" mime_type="video/webm" res="360p" fps="30fps" vcodec="vp8.0" acodec="vorbis">,
|
78 |
<Stream: itag="18" mime_type="video/mp4" res="360p" fps="30fps" vcodec="avc1.42001E" acodec="mp4a.40.2">,
|
@@ -108,7 +106,7 @@ The legacy streams that contain the audio and video in a single file (referred t
|
|
108 |
To only view these progressive download streams:
|
109 |
|
110 |
```python
|
111 |
-
>>> yt.streams.filter(progressive=True)
|
112 |
[<Stream: itag="22" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.64001F" acodec="mp4a.40.2">,
|
113 |
<Stream: itag="43" mime_type="video/webm" res="360p" fps="30fps" vcodec="vp8.0" acodec="vorbis">,
|
114 |
<Stream: itag="18" mime_type="video/mp4" res="360p" fps="30fps" vcodec="avc1.42001E" acodec="mp4a.40.2">,
|
@@ -119,7 +117,7 @@ To only view these progressive download streams:
|
|
119 |
Conversely, if you only want to see the DASH streams (also referred to as "adaptive") you can do:
|
120 |
|
121 |
```python
|
122 |
-
>>> yt.streams.filter(adaptive=True)
|
123 |
[<Stream: itag="137" mime_type="video/mp4" res="1080p" fps="30fps" vcodec="avc1.640028">,
|
124 |
<Stream: itag="248" mime_type="video/webm" res="1080p" fps="30fps" vcodec="vp9">,
|
125 |
<Stream: itag="136" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.4d401f">,
|
@@ -146,7 +144,7 @@ You can also download a complete Youtube playlist:
|
|
146 |
```python
|
147 |
>>> from pytube import Playlist
|
148 |
>>> playlist = Playlist("https://www.youtube.com/playlist?list=PLynhp4cZEpTbRs_PYISQ8v_uwO0_mDg_X")
|
149 |
-
>>> for video in playlist
|
150 |
>>> video.streams.get_highest_resolution().download()
|
151 |
```
|
152 |
This will download the highest progressive stream available (generally 720p) from the given playlist.
|
@@ -158,7 +156,7 @@ Pytube allows you to filter on every property available (see the documentation f
|
|
158 |
To list the audio only streams:
|
159 |
|
160 |
```python
|
161 |
-
>>> yt.streams.filter(only_audio=True)
|
162 |
[<Stream: itag="140" mime_type="audio/mp4" abr="128kbps" acodec="mp4a.40.2">,
|
163 |
<Stream: itag="171" mime_type="audio/webm" abr="128kbps" acodec="vorbis">,
|
164 |
<Stream: itag="249" mime_type="audio/webm" abr="50kbps" acodec="opus">,
|
@@ -169,7 +167,7 @@ To list the audio only streams:
|
|
169 |
To list only ``mp4`` streams:
|
170 |
|
171 |
```python
|
172 |
-
>>> yt.streams.filter(subtype='mp4')
|
173 |
[<Stream: itag="22" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.64001F" acodec="mp4a.40.2">,
|
174 |
<Stream: itag="18" mime_type="video/mp4" res="360p" fps="30fps" vcodec="avc1.42001E" acodec="mp4a.40.2">,
|
175 |
<Stream: itag="137" mime_type="video/mp4" res="1080p" fps="30fps" vcodec="avc1.640028">,
|
@@ -184,9 +182,9 @@ To list only ``mp4`` streams:
|
|
184 |
Multiple filters can also be specified:
|
185 |
|
186 |
```python
|
187 |
-
>>> yt.streams.filter(subtype='mp4', progressive=True)
|
188 |
>>> # this can also be expressed as:
|
189 |
-
>>> yt.streams.filter(subtype='mp4').filter(progressive=True)
|
190 |
[<Stream: itag="22" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.64001F" acodec="mp4a.40.2">,
|
191 |
<Stream: itag="18" mime_type="video/mp4" res="360p" fps="30fps" vcodec="avc1.42001E" acodec="mp4a.40.2">]
|
192 |
```
|
@@ -200,7 +198,7 @@ You also have an interface to select streams by their itag, without needing to f
|
|
200 |
If you need to optimize for a specific feature, such as the "highest resolution" or "lowest average bitrate":
|
201 |
|
202 |
```python
|
203 |
-
>>> yt.streams.filter(progressive=True).order_by('resolution').desc()
|
204 |
```
|
205 |
Note: Using ``order_by`` on a given attribute will filter out all streams missing that attribute.
|
206 |
|
|
|
36 |
## Quick start
|
37 |
```python
|
38 |
>>> from pytube import YouTube
|
39 |
+
>>> YouTube('https://youtu.be/9bZkp7q19f0').streams[0].download()
|
40 |
>>>
|
41 |
>>> yt = YouTube('http://youtube.com/watch?v=9bZkp7q19f0')
|
42 |
>>> yt.streams
|
43 |
... .filter(progressive=True, file_extension='mp4')
|
44 |
+
... .order_by('resolution')[-1]
|
|
|
|
|
45 |
... .download()
|
46 |
```
|
47 |
|
|
|
62 |
|
63 |
```python
|
64 |
>>> from pytube import YouTube
|
65 |
+
>>> YouTube('http://youtube.com/watch?v=9bZkp7q19f0').streams[0].download()
|
66 |
```
|
67 |
This example will download the highest quality progressive download stream available.
|
68 |
|
|
|
70 |
|
71 |
```python
|
72 |
>>> yt = YouTube('http://youtube.com/watch?v=9bZkp7q19f0')
|
73 |
+
>>> print(yt.streams)
|
74 |
[<Stream: itag="22" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.64001F" acodec="mp4a.40.2">,
|
75 |
<Stream: itag="43" mime_type="video/webm" res="360p" fps="30fps" vcodec="vp8.0" acodec="vorbis">,
|
76 |
<Stream: itag="18" mime_type="video/mp4" res="360p" fps="30fps" vcodec="avc1.42001E" acodec="mp4a.40.2">,
|
|
|
106 |
To only view these progressive download streams:
|
107 |
|
108 |
```python
|
109 |
+
>>> yt.streams.filter(progressive=True)
|
110 |
[<Stream: itag="22" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.64001F" acodec="mp4a.40.2">,
|
111 |
<Stream: itag="43" mime_type="video/webm" res="360p" fps="30fps" vcodec="vp8.0" acodec="vorbis">,
|
112 |
<Stream: itag="18" mime_type="video/mp4" res="360p" fps="30fps" vcodec="avc1.42001E" acodec="mp4a.40.2">,
|
|
|
117 |
Conversely, if you only want to see the DASH streams (also referred to as "adaptive") you can do:
|
118 |
|
119 |
```python
|
120 |
+
>>> yt.streams.filter(adaptive=True)
|
121 |
[<Stream: itag="137" mime_type="video/mp4" res="1080p" fps="30fps" vcodec="avc1.640028">,
|
122 |
<Stream: itag="248" mime_type="video/webm" res="1080p" fps="30fps" vcodec="vp9">,
|
123 |
<Stream: itag="136" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.4d401f">,
|
|
|
144 |
```python
|
145 |
>>> from pytube import Playlist
|
146 |
>>> playlist = Playlist("https://www.youtube.com/playlist?list=PLynhp4cZEpTbRs_PYISQ8v_uwO0_mDg_X")
|
147 |
+
>>> for video in playlist:
|
148 |
>>> video.streams.get_highest_resolution().download()
|
149 |
```
|
150 |
This will download the highest progressive stream available (generally 720p) from the given playlist.
|
|
|
156 |
To list the audio only streams:
|
157 |
|
158 |
```python
|
159 |
+
>>> yt.streams.filter(only_audio=True)
|
160 |
[<Stream: itag="140" mime_type="audio/mp4" abr="128kbps" acodec="mp4a.40.2">,
|
161 |
<Stream: itag="171" mime_type="audio/webm" abr="128kbps" acodec="vorbis">,
|
162 |
<Stream: itag="249" mime_type="audio/webm" abr="50kbps" acodec="opus">,
|
|
|
167 |
To list only ``mp4`` streams:
|
168 |
|
169 |
```python
|
170 |
+
>>> yt.streams.filter(subtype='mp4')
|
171 |
[<Stream: itag="22" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.64001F" acodec="mp4a.40.2">,
|
172 |
<Stream: itag="18" mime_type="video/mp4" res="360p" fps="30fps" vcodec="avc1.42001E" acodec="mp4a.40.2">,
|
173 |
<Stream: itag="137" mime_type="video/mp4" res="1080p" fps="30fps" vcodec="avc1.640028">,
|
|
|
182 |
Multiple filters can also be specified:
|
183 |
|
184 |
```python
|
185 |
+
>>> yt.streams.filter(subtype='mp4', progressive=True)
|
186 |
>>> # this can also be expressed as:
|
187 |
+
>>> yt.streams.filter(subtype='mp4').filter(progressive=True)
|
188 |
[<Stream: itag="22" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.64001F" acodec="mp4a.40.2">,
|
189 |
<Stream: itag="18" mime_type="video/mp4" res="360p" fps="30fps" vcodec="avc1.42001E" acodec="mp4a.40.2">]
|
190 |
```
|
|
|
198 |
If you need to optimize for a specific feature, such as the "highest resolution" or "lowest average bitrate":
|
199 |
|
200 |
```python
|
201 |
+
>>> yt.streams.filter(progressive=True).order_by('resolution').desc()
|
202 |
```
|
203 |
Note: Using ``order_by`` on a given attribute will filter out all streams missing that attribute.
|
204 |
|
pytube/contrib/playlist.py
CHANGED
@@ -149,6 +149,9 @@ class Playlist(Sequence):
|
|
149 |
def __len__(self) -> int:
|
150 |
return len(self.video_urls)
|
151 |
|
|
|
|
|
|
|
152 |
@deprecated(
|
153 |
"This call is unnecessary, you can directly access .video_urls or .videos"
|
154 |
)
|
|
|
149 |
def __len__(self) -> int:
|
150 |
return len(self.video_urls)
|
151 |
|
152 |
+
def __repr__(self) -> str:
|
153 |
+
return f"{self.video_urls}"
|
154 |
+
|
155 |
@deprecated(
|
156 |
"This call is unnecessary, you can directly access .video_urls or .videos"
|
157 |
)
|
pytube/query.py
CHANGED
@@ -350,6 +350,9 @@ class StreamQuery(Sequence):
|
|
350 |
def __len__(self) -> int:
|
351 |
return len(self.fmt_streams)
|
352 |
|
|
|
|
|
|
|
353 |
|
354 |
class CaptionQuery(Sequence):
|
355 |
"""Interface for querying the available captions."""
|
@@ -390,3 +393,6 @@ class CaptionQuery(Sequence):
|
|
390 |
|
391 |
def __len__(self) -> int:
|
392 |
return len(self.captions)
|
|
|
|
|
|
|
|
350 |
def __len__(self) -> int:
|
351 |
return len(self.fmt_streams)
|
352 |
|
353 |
+
def __repr__(self) -> str:
|
354 |
+
return f"{self.fmt_streams}"
|
355 |
+
|
356 |
|
357 |
class CaptionQuery(Sequence):
|
358 |
"""Interface for querying the available captions."""
|
|
|
393 |
|
394 |
def __len__(self) -> int:
|
395 |
return len(self.captions)
|
396 |
+
|
397 |
+
def __repr__(self) -> str:
|
398 |
+
return f"{self.captions}"
|