docstrings
Browse files- pytube/__main__.py +44 -9
pytube/__main__.py
CHANGED
|
@@ -81,7 +81,11 @@ class YouTube(object):
|
|
| 81 |
self.prefetch_init()
|
| 82 |
|
| 83 |
def prefetch_init(self):
|
| 84 |
-
"""Download data, descramble it, and build Stream instances.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
self.prefetch()
|
| 86 |
self.init()
|
| 87 |
|
|
@@ -92,6 +96,9 @@ class YouTube(object):
|
|
| 92 |
"call-by-reference evaluation," which allows dictionary transforms to
|
| 93 |
be applied in-place, instead of holding references to mutations at each
|
| 94 |
interstitial step.
|
|
|
|
|
|
|
|
|
|
| 95 |
"""
|
| 96 |
logger.info('init started')
|
| 97 |
|
|
@@ -129,6 +136,8 @@ class YouTube(object):
|
|
| 129 |
operations don't does need to make calls outside of the interpreter
|
| 130 |
which blocks for long periods of time.
|
| 131 |
|
|
|
|
|
|
|
| 132 |
"""
|
| 133 |
self.watch_html = request.get(url=self.watch_url)
|
| 134 |
if extract.is_age_restricted(self.watch_html):
|
|
@@ -149,9 +158,11 @@ class YouTube(object):
|
|
| 149 |
instances of :class:`Stream <Stream>` for each media stream.
|
| 150 |
|
| 151 |
:param str fmt:
|
| 152 |
-
Key in stream manifest (
|
| 153 |
-
download or adaptive streams (e.g.:
|
| 154 |
-
|
|
|
|
|
|
|
| 155 |
|
| 156 |
"""
|
| 157 |
stream_manifest = self.player_config['args'][fmt]
|
|
@@ -168,11 +179,15 @@ class YouTube(object):
|
|
| 168 |
|
| 169 |
Take the unscrambled player response data, and use it to initialize
|
| 170 |
instances of :class:`Caption <Caption>`.
|
|
|
|
|
|
|
|
|
|
| 171 |
"""
|
| 172 |
if 'captions' not in self.player_config['args']['player_response']:
|
| 173 |
return
|
| 174 |
caption_tracks = (
|
| 175 |
-
self.player_config
|
|
|
|
| 176 |
['player_response']
|
| 177 |
['captions']
|
| 178 |
['playerCaptionsTracklistRenderer']
|
|
@@ -183,22 +198,36 @@ class YouTube(object):
|
|
| 183 |
|
| 184 |
@property
|
| 185 |
def captions(self):
|
| 186 |
-
"""Interface to query caption tracks.
|
|
|
|
|
|
|
|
|
|
| 187 |
return CaptionQuery([c for c in self.caption_tracks])
|
| 188 |
|
| 189 |
@property
|
| 190 |
def streams(self):
|
| 191 |
-
"""Interface to query both adaptive (DASH) and progressive streams.
|
|
|
|
|
|
|
|
|
|
| 192 |
return StreamQuery([s for s in self.fmt_streams])
|
| 193 |
|
| 194 |
@property
|
| 195 |
def thumbnail_url(self):
|
| 196 |
-
"""Get the thumbnail url image.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
return self.player_config['args']['thumbnail_url']
|
| 198 |
|
| 199 |
@property
|
| 200 |
def title(self):
|
| 201 |
-
"""Get the video title.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
return self.player_config['args']['title']
|
| 203 |
|
| 204 |
def register_on_progress_callback(self, func):
|
|
@@ -207,6 +236,9 @@ class YouTube(object):
|
|
| 207 |
:param callable func:
|
| 208 |
A callback function that takes ``stream``, ``chunk``,
|
| 209 |
``file_handle``, ``bytes_remaining`` as parameters.
|
|
|
|
|
|
|
|
|
|
| 210 |
"""
|
| 211 |
self.stream_monostate['on_progress'] = func
|
| 212 |
|
|
@@ -215,5 +247,8 @@ class YouTube(object):
|
|
| 215 |
|
| 216 |
:param callable func:
|
| 217 |
A callback function that takes ``stream`` and ``file_handle``.
|
|
|
|
|
|
|
|
|
|
| 218 |
"""
|
| 219 |
self.stream_monostate['on_complete'] = func
|
|
|
|
| 81 |
self.prefetch_init()
|
| 82 |
|
| 83 |
def prefetch_init(self):
|
| 84 |
+
"""Download data, descramble it, and build Stream instances.
|
| 85 |
+
|
| 86 |
+
:rtype: ``None``
|
| 87 |
+
|
| 88 |
+
"""
|
| 89 |
self.prefetch()
|
| 90 |
self.init()
|
| 91 |
|
|
|
|
| 96 |
"call-by-reference evaluation," which allows dictionary transforms to
|
| 97 |
be applied in-place, instead of holding references to mutations at each
|
| 98 |
interstitial step.
|
| 99 |
+
|
| 100 |
+
:rtype: ``None``
|
| 101 |
+
|
| 102 |
"""
|
| 103 |
logger.info('init started')
|
| 104 |
|
|
|
|
| 136 |
operations don't does need to make calls outside of the interpreter
|
| 137 |
which blocks for long periods of time.
|
| 138 |
|
| 139 |
+
:rtype: ``None``
|
| 140 |
+
|
| 141 |
"""
|
| 142 |
self.watch_html = request.get(url=self.watch_url)
|
| 143 |
if extract.is_age_restricted(self.watch_html):
|
|
|
|
| 158 |
instances of :class:`Stream <Stream>` for each media stream.
|
| 159 |
|
| 160 |
:param str fmt:
|
| 161 |
+
Key in stream manifest (``ytplayer_config``) containing progressive
|
| 162 |
+
download or adaptive streams (e.g.: ``url_encoded_fmt_stream_map``
|
| 163 |
+
or ``adaptive_fmts``).
|
| 164 |
+
|
| 165 |
+
:rtype: ``None``
|
| 166 |
|
| 167 |
"""
|
| 168 |
stream_manifest = self.player_config['args'][fmt]
|
|
|
|
| 179 |
|
| 180 |
Take the unscrambled player response data, and use it to initialize
|
| 181 |
instances of :class:`Caption <Caption>`.
|
| 182 |
+
|
| 183 |
+
:rtype: ``None``
|
| 184 |
+
|
| 185 |
"""
|
| 186 |
if 'captions' not in self.player_config['args']['player_response']:
|
| 187 |
return
|
| 188 |
caption_tracks = (
|
| 189 |
+
self.player_config
|
| 190 |
+
['args']
|
| 191 |
['player_response']
|
| 192 |
['captions']
|
| 193 |
['playerCaptionsTracklistRenderer']
|
|
|
|
| 198 |
|
| 199 |
@property
|
| 200 |
def captions(self):
|
| 201 |
+
"""Interface to query caption tracks.
|
| 202 |
+
|
| 203 |
+
:rtype: :class:`CaptionQuery <CaptionQuery>`.
|
| 204 |
+
"""
|
| 205 |
return CaptionQuery([c for c in self.caption_tracks])
|
| 206 |
|
| 207 |
@property
|
| 208 |
def streams(self):
|
| 209 |
+
"""Interface to query both adaptive (DASH) and progressive streams.
|
| 210 |
+
|
| 211 |
+
:rtype: :class:`StreamQuery <StreamQuery>`.
|
| 212 |
+
"""
|
| 213 |
return StreamQuery([s for s in self.fmt_streams])
|
| 214 |
|
| 215 |
@property
|
| 216 |
def thumbnail_url(self):
|
| 217 |
+
"""Get the thumbnail url image.
|
| 218 |
+
|
| 219 |
+
:rtype: str
|
| 220 |
+
|
| 221 |
+
"""
|
| 222 |
return self.player_config['args']['thumbnail_url']
|
| 223 |
|
| 224 |
@property
|
| 225 |
def title(self):
|
| 226 |
+
"""Get the video title.
|
| 227 |
+
|
| 228 |
+
:rtype: str
|
| 229 |
+
|
| 230 |
+
"""
|
| 231 |
return self.player_config['args']['title']
|
| 232 |
|
| 233 |
def register_on_progress_callback(self, func):
|
|
|
|
| 236 |
:param callable func:
|
| 237 |
A callback function that takes ``stream``, ``chunk``,
|
| 238 |
``file_handle``, ``bytes_remaining`` as parameters.
|
| 239 |
+
|
| 240 |
+
:rtype: ``None``
|
| 241 |
+
|
| 242 |
"""
|
| 243 |
self.stream_monostate['on_progress'] = func
|
| 244 |
|
|
|
|
| 247 |
|
| 248 |
:param callable func:
|
| 249 |
A callback function that takes ``stream`` and ``file_handle``.
|
| 250 |
+
|
| 251 |
+
:rtype: ``None``
|
| 252 |
+
|
| 253 |
"""
|
| 254 |
self.stream_monostate['on_complete'] = func
|