aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWitold Baryluk <baryluk@smp.if.uj.edu.pl>2012-03-23 06:17:29 +0100
committerWitold Baryluk <baryluk@smp.if.uj.edu.pl>2012-03-23 06:17:29 +0100
commit69d3b2d8249e677c40d529e017cb765f50ba3fa0 (patch)
treecedea80fa7b6ab373be1d55e188ff0838ff7faa7
parentd891ff9fd9952b2829a47b508acf40d951546123 (diff)
Extract original URL from next_url parameter of verify_age page, before actual extract
-rwxr-xr-xyoutube-dl12
1 files changed, 11 insertions, 1 deletions
diff --git a/youtube-dl b/youtube-dl
index b466c1570..d8b33e52c 100755
--- a/youtube-dl
+++ b/youtube-dl
@@ -1171,7 +1171,9 @@ class InfoExtractor(object):
class YoutubeIE(InfoExtractor):
"""Information extractor for youtube.com."""
- _VALID_URL = r'^((?:https?://)?(?:youtu\.be/|(?:\w+\.)?youtube(?:-nocookie)?\.com/)(?!view_play_list|my_playlists|artist|playlist)(?:(?:(?:v|embed|e)/)|(?:(?:watch(?:_popup)?(?:\.php)?)?(?:\?|#!?)(?:.+&)?v=))?)?([0-9A-Za-z_-]+)(?(1).+)?$'
+ _PREFIX = r'(?:https?://)?(?:youtu\.be/|(?:\w+\.)?youtube(?:-nocookie)?\.com/)'
+ _VALID_URL = r'^('+_PREFIX+r'(?!view_play_list|my_playlists|artist|playlist)(?:(?:(?:v|embed|e)/)|(?:(?:watch(?:_popup)?(?:\.php)?)?(?:\?|#!?)(?:.+&)?v=))?)?([0-9A-Za-z_-]+)(?(1).+)?$'
+ _VALID_URL_WITH_AGE = r'^('+_PREFIX+')verify_age\?next_url=([^&]+)(?:.+)?$'
_LANG_URL = r'http://www.youtube.com/?hl=en&persist_hl=1&gl=US&persist_gl=1&opt_out_ackd=1'
_LOGIN_URL = 'https://www.youtube.com/signup?next=/&gl=US&hl=en'
_AGE_URL = 'http://www.youtube.com/verify_age?next_url=/&gl=US&hl=en'
@@ -1335,6 +1337,14 @@ class YoutubeIE(InfoExtractor):
return
def _real_extract(self, url):
+ # Extract original video URL from URL with age verification, using next_url parameter
+ mobj = re.match(self._VALID_URL_WITH_AGE, url)
+ if mobj:
+ urldecode = lambda x: re.sub(r'%([0-9a-hA-H][0-9a-hA-H])', lambda m: chr(int(m.group(1), 16)), x)
+ # Keep original domain. We can probably change to www.youtube.com, but it should not hurt so keep it.
+ # We just make sure we do not have double //, in URL, so we strip starting slash in next_url.
+ url = mobj.group(1) + re.sub(r'^/', '', urldecode(mobj.group(2)))
+
# Extract video id from URL
mobj = re.match(self._VALID_URL, url)
if mobj is None: