Merge pull request #2 from ablanco/master
Browse files- pytube/__init__.py +11 -25
pytube/__init__.py
CHANGED
@@ -271,24 +271,24 @@ class YouTube(object):
|
|
271 |
|
272 |
#Use my cool traversing method to extract the specific
|
273 |
#attribute from the response body.
|
274 |
-
path = ('url_encoded_fmt_stream_map', '
|
275 |
-
|
276 |
-
#
|
277 |
-
|
|
|
278 |
self.title = self._fetch(('title',), content)
|
279 |
|
280 |
-
for
|
281 |
-
url =
|
282 |
-
|
283 |
-
#Sometimes the regex for matching the video returns
|
284 |
-
#a single empty element, so we'll skip those here.
|
285 |
-
continue
|
286 |
try:
|
287 |
-
fmt, data = self._extract_fmt(
|
288 |
filename = "%s.%s" % (self.filename, data['extension'])
|
289 |
except (TypeError, KeyError):
|
290 |
pass
|
291 |
else:
|
|
|
|
|
292 |
v = Video(url, filename, **data)
|
293 |
self.videos.append(v)
|
294 |
self._fmt_values.append(fmt)
|
@@ -313,20 +313,6 @@ class YouTube(object):
|
|
313 |
map(lambda k, v: data.update({k: v}), YT_ENCODING_KEYS, attr)
|
314 |
return itag, data
|
315 |
|
316 |
-
def _extract_url(self, text):
|
317 |
-
"""
|
318 |
-
(I hate to be redundant here, but whatever) YouTube does not
|
319 |
-
pass you a completely valid URLencoded form, I suspect this is
|
320 |
-
suppose to act as a deterrent.. Nothing some regulular
|
321 |
-
expressions couldn't handle.
|
322 |
-
|
323 |
-
Keyword arguments:
|
324 |
-
text -- The malformed data contained in the itag node.
|
325 |
-
"""
|
326 |
-
url = re.findall('url=(.*)', text)
|
327 |
-
if url and len(url) is 1:
|
328 |
-
return url[0]
|
329 |
-
|
330 |
|
331 |
def safe_filename(text, max_length=200):
|
332 |
"""
|
|
|
271 |
|
272 |
#Use my cool traversing method to extract the specific
|
273 |
#attribute from the response body.
|
274 |
+
path = ('url_encoded_fmt_stream_map', 'url')
|
275 |
+
video_urls = self._fetch(path, content)
|
276 |
+
#Get the video signatures, YouTube require them as an url component
|
277 |
+
path = ('url_encoded_fmt_stream_map', 'sig')
|
278 |
+
video_signatures = self._fetch(path, content)
|
279 |
self.title = self._fetch(('title',), content)
|
280 |
|
281 |
+
for idx in range(len(video_urls)):
|
282 |
+
url = video_urls[idx]
|
283 |
+
signature = video_signatures[idx]
|
|
|
|
|
|
|
284 |
try:
|
285 |
+
fmt, data = self._extract_fmt(url)
|
286 |
filename = "%s.%s" % (self.filename, data['extension'])
|
287 |
except (TypeError, KeyError):
|
288 |
pass
|
289 |
else:
|
290 |
+
#Add video signature to url
|
291 |
+
url = "%s&signature=%s" % (url, signature)
|
292 |
v = Video(url, filename, **data)
|
293 |
self.videos.append(v)
|
294 |
self._fmt_values.append(fmt)
|
|
|
313 |
map(lambda k, v: data.update({k: v}), YT_ENCODING_KEYS, attr)
|
314 |
return itag, data
|
315 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
316 |
|
317 |
def safe_filename(text, max_length=200):
|
318 |
"""
|