Nick Ficano
commited on
Commit
·
198e311
1
Parent(s):
8740488
minor rearrangment.
Browse files- pytube/api.py +29 -29
pytube/api.py
CHANGED
@@ -129,8 +129,8 @@ class YouTube(object):
|
|
129 |
|
130 |
@filename.setter
|
131 |
def filename(self, filename):
|
132 |
-
"""Set the filename (This method is deprecated. Use
|
133 |
-
|
134 |
|
135 |
:param str filename:
|
136 |
The filename of the video.
|
@@ -227,6 +227,31 @@ class YouTube(object):
|
|
227 |
results.append(v)
|
228 |
return results
|
229 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
230 |
def _parse_stream_map(self, blob):
|
231 |
"""A modified version of `urlparse.parse_qs` that is able to decode
|
232 |
YouTube's stream map.
|
@@ -256,31 +281,6 @@ class YouTube(object):
|
|
256 |
log.debug('decoded stream map: %s', dct)
|
257 |
return dct
|
258 |
|
259 |
-
def get_video_data(self):
|
260 |
-
"""Fetch the page and extract out the video data."""
|
261 |
-
self.title = None
|
262 |
-
|
263 |
-
response = urlopen(self.url)
|
264 |
-
|
265 |
-
if not response:
|
266 |
-
return False
|
267 |
-
html = response.read().decode("utf-8")
|
268 |
-
|
269 |
-
if "og:restrictions:age" in html:
|
270 |
-
raise AgeRestricted
|
271 |
-
|
272 |
-
json_object = self._extract_json_data(html)
|
273 |
-
|
274 |
-
if not json_object:
|
275 |
-
raise YouTubeError("Unable to extract json.")
|
276 |
-
|
277 |
-
encoded_stream_map = json_object.get("args", {}).get(
|
278 |
-
"url_encoded_fmt_stream_map")
|
279 |
-
|
280 |
-
json_object['args']['stream_map'] = self._parse_stream_map(
|
281 |
-
encoded_stream_map)
|
282 |
-
return json_object
|
283 |
-
|
284 |
def _extract_json_data(self, html):
|
285 |
"""Extract the json from the html.
|
286 |
|
@@ -339,8 +339,8 @@ class YouTube(object):
|
|
339 |
return initial_function([signature])
|
340 |
except Exception as e:
|
341 |
raise CipherError("Couldn't cipher the signature. Maybe YouTube "
|
342 |
-
|
343 |
-
|
344 |
|
345 |
def _extract_fmt(self, text):
|
346 |
"""YouTube does not pass you a completely valid URLencoded form, I
|
|
|
129 |
|
130 |
@filename.setter
|
131 |
def filename(self, filename):
|
132 |
+
"""Set the filename (This method is deprecated. Use `set_filename()`
|
133 |
+
instead).
|
134 |
|
135 |
:param str filename:
|
136 |
The filename of the video.
|
|
|
227 |
results.append(v)
|
228 |
return results
|
229 |
|
230 |
+
def get_video_data(self):
|
231 |
+
"""Fetch the page and extract out the video data."""
|
232 |
+
self.title = None
|
233 |
+
|
234 |
+
response = urlopen(self.url)
|
235 |
+
|
236 |
+
if not response:
|
237 |
+
return False
|
238 |
+
html = response.read().decode("utf-8")
|
239 |
+
|
240 |
+
if "og:restrictions:age" in html:
|
241 |
+
raise AgeRestricted
|
242 |
+
|
243 |
+
json_object = self._extract_json_data(html)
|
244 |
+
|
245 |
+
if not json_object:
|
246 |
+
raise YouTubeError("Unable to extract json.")
|
247 |
+
|
248 |
+
encoded_stream_map = json_object.get("args", {}).get(
|
249 |
+
"url_encoded_fmt_stream_map")
|
250 |
+
|
251 |
+
json_object['args']['stream_map'] = self._parse_stream_map(
|
252 |
+
encoded_stream_map)
|
253 |
+
return json_object
|
254 |
+
|
255 |
def _parse_stream_map(self, blob):
|
256 |
"""A modified version of `urlparse.parse_qs` that is able to decode
|
257 |
YouTube's stream map.
|
|
|
281 |
log.debug('decoded stream map: %s', dct)
|
282 |
return dct
|
283 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
284 |
def _extract_json_data(self, html):
|
285 |
"""Extract the json from the html.
|
286 |
|
|
|
339 |
return initial_function([signature])
|
340 |
except Exception as e:
|
341 |
raise CipherError("Couldn't cipher the signature. Maybe YouTube "
|
342 |
+
"has changed the cipher algorithm. Notify this "
|
343 |
+
"issue on GitHub: %s" % e)
|
344 |
|
345 |
def _extract_fmt(self, text):
|
346 |
"""YouTube does not pass you a completely valid URLencoded form, I
|