adding stanford open class courses
[youtube-dl] / youtube_dl / InfoExtractors.py
index 88973cce8982b70a57039a26208a9c647474160f..6e59ba8fd740c789435c3ada8ba0a13dcb2297a8 100644 (file)
@@ -102,6 +102,7 @@ class YoutubeIE(InfoExtractor):
                             (?:https?://)?                                       # http(s):// (optional)
                             (?:youtu\.be/|(?:\w+\.)?youtube(?:-nocookie)?\.com/|
                                tube\.majestyc\.net/)                             # the various hostnames, with wildcard subdomains
+                            (?:.*?\#/)?                                          # handle anchor (#/) redirect urls
                             (?!view_play_list|my_playlists|artist|playlist)      # ignore playlist URLs
                             (?:                                                  # the various things that can precede the ID:
                                 (?:(?:v|embed|e)/)                               # v/ or embed/ or e/
@@ -413,6 +414,12 @@ class YoutubeIE(InfoExtractor):
                        except Trouble as trouble:
                                self._downloader.trouble(trouble[0])
 
+               if 'length_seconds' not in video_info:
+                       self._downloader.trouble(u'WARNING: unable to extract video duration')
+                       video_duration = ''
+               else:
+                       video_duration = urllib.unquote_plus(video_info['length_seconds'][0])
+
                # token
                video_token = urllib.unquote_plus(video_info['token'][0])
 
@@ -479,7 +486,8 @@ class YoutubeIE(InfoExtractor):
                                'thumbnail':    video_thumbnail.decode('utf-8'),
                                'description':  video_description,
                                'player_url':   player_url,
-                               'subtitles':    video_subtitles
+                               'subtitles':    video_subtitles,
+                               'duration':             video_duration
                        })
                return results
 
@@ -1508,7 +1516,7 @@ class YahooSearchIE(InfoExtractor):
 class YoutubePlaylistIE(InfoExtractor):
        """Information Extractor for YouTube playlists."""
 
-       _VALID_URL = r'(?:https?://)?(?:\w+\.)?youtube\.com/(?:(?:course|view_play_list|my_playlists|artist|playlist)\?.*?(p|a|list)=|user/.*?/user/|p/|user/.*?#[pg]/c/)(?:PL|EC)?([0-9A-Za-z-_]+)(?:/.*?/([0-9A-Za-z_-]+))?.*'
+       _VALID_URL = r'(?:(?:https?://)?(?:\w+\.)?youtube\.com/(?:(?:course|view_play_list|my_playlists|artist|playlist)\?.*?(p|a|list)=|user/.*?/user/|p/|user/.*?#[pg]/c/)(?:PL|EC)?|PL|EC)([0-9A-Za-z-_]+)(?:/.*?/([0-9A-Za-z_-]+))?.*'
        _TEMPLATE_URL = 'http://www.youtube.com/%s?%s=%s&page=%s&gl=US&hl=en'
        _VIDEO_INDICATOR_TEMPLATE = r'/watch\?v=(.+?)&([^&"]+&)*list=.*?%s'
        _MORE_PAGES_INDICATOR = r'yt-uix-pager-next'