diff options
Diffstat (limited to 'youtube_dl/InfoExtractors.py')
| -rwxr-xr-x | youtube_dl/InfoExtractors.py | 153 | 
1 files changed, 152 insertions, 1 deletions
diff --git a/youtube_dl/InfoExtractors.py b/youtube_dl/InfoExtractors.py index 3c95012b1..a25ccc173 100755 --- a/youtube_dl/InfoExtractors.py +++ b/youtube_dl/InfoExtractors.py @@ -1410,6 +1410,9 @@ class GenericIE(InfoExtractor):              # Broaden the search a little bit: JWPlayer JS loader              mobj = re.search(r'[^A-Za-z0-9]?file:\s*["\'](http[^\'"&]*)', webpage)          if mobj is None: +            # Try to find twitter cards info +            mobj = re.search(r'<meta (?:property|name)="twitter:player:stream" (?:content|value)="(.+?)"', webpage) +        if mobj is None:              raise ExtractorError(u'Invalid URL: %s' % url)          # It's possible that one of the regexes @@ -1456,7 +1459,6 @@ class YoutubeSearchIE(SearchInfoExtractor):      def report_download_page(self, query, pagenum):          """Report attempt to download search page with given number.""" -        query = query.decode(preferredencoding())          self._downloader.to_screen(u'[youtube] query "%s": Downloading page %s' % (query, pagenum))      def _get_n_results(self, query, n): @@ -4001,6 +4003,64 @@ class ARDIE(InfoExtractor):              info["url"] = stream["video_url"]          return [info] +class ZDFIE(InfoExtractor): +    _VALID_URL = r'^http://www\.zdf\.de\/ZDFmediathek\/(.*beitrag\/video\/)(?P<video_id>[^/\?]+)(?:\?.*)?' +    _TITLE = r'<h1(?: class="beitragHeadline")?>(?P<title>.*)</h1>' +    _MEDIA_STREAM = r'<a href="(?P<video_url>.+(?P<media_type>.streaming).+/zdf/(?P<quality>[^\/]+)/[^"]*)".+class="play".+>' +    _MMS_STREAM = r'href="(?P<video_url>mms://[^"]*)"' +    _RTSP_STREAM = r'(?P<video_url>rtsp://[^"]*.mp4)' + +    def _real_extract(self, url): +        mobj = re.match(self._VALID_URL, url) +        if mobj is None: +            raise ExtractorError(u'Invalid URL: %s' % url) +        video_id = mobj.group('video_id') + +        html = self._download_webpage(url, video_id) +        streams = [m.groupdict() for m in re.finditer(self._MEDIA_STREAM, html)] +        if streams is None: +            raise ExtractorError(u'No media url found.') + +        # s['media_type'] == 'wstreaming' -> use 'Windows Media Player' and mms url +        # s['media_type'] == 'hstreaming' -> use 'Quicktime' and rtsp url +        # choose first/default media type and highest quality for now +        for s in streams:        #find 300 - dsl1000mbit +            if s['quality'] == '300' and s['media_type'] == 'wstreaming': +                stream_=s +                break +        for s in streams:        #find veryhigh - dsl2000mbit +            if s['quality'] == 'veryhigh' and s['media_type'] == 'wstreaming': # 'hstreaming' - rtsp is not working +                stream_=s +                break +        if stream_ is None: +            raise ExtractorError(u'No stream found.') + +        media_link = self._download_webpage(stream_['video_url'], video_id,'Get stream URL') + +        self.report_extraction(video_id) +        mobj = re.search(self._TITLE, html) +        if mobj is None: +            raise ExtractorError(u'Cannot extract title') +        title = unescapeHTML(mobj.group('title')) + +        mobj = re.search(self._MMS_STREAM, media_link) +        if mobj is None: +            mobj = re.search(self._RTSP_STREAM, media_link) +            if mobj is None: +                raise ExtractorError(u'Cannot extract mms:// or rtsp:// URL') +        mms_url = mobj.group('video_url') + +        mobj = re.search('(.*)[.](?P<ext>[^.]+)', mms_url) +        if mobj is None: +            raise ExtractorError(u'Cannot extract extention') +        ext = mobj.group('ext') + +        return [{'id': video_id, +                 'url': mms_url, +                 'title': title, +                 'ext': ext +                 }] +  class TumblrIE(InfoExtractor):      _VALID_URL = r'http://(?P<blog_name>.*?)\.tumblr\.com/((post)|(video))/(?P<id>\d*)/(.*?)' @@ -4394,6 +4454,94 @@ class HypemIE(InfoExtractor):              'artist':   artist,          }] +class Vbox7IE(InfoExtractor): +    """Information Extractor for Vbox7""" +    _VALID_URL = r'(?:http://)?(?:www\.)?vbox7\.com/play:([^/]+)' + +    def _real_extract(self,url): +        mobj = re.match(self._VALID_URL, url) +        if mobj is None: +            raise ExtractorError(u'Invalid URL: %s' % url) +        video_id = mobj.group(1) + +        redirect_page, urlh = self._download_webpage_handle(url, video_id) +        redirect_url = urlh.geturl() + re.search(r'window\.location = \'(.*)\';', redirect_page).group(1) +        webpage = self._download_webpage(redirect_url, video_id, u'Downloading redirect page') + +        title = re.search(r'<title>(.*)</title>', webpage) +        title = (title.group(1)).split('/')[0].strip() + +        ext = "flv" +        info_url = "http://vbox7.com/play/magare.do" +        data = compat_urllib_parse.urlencode({'as3':'1','vid':video_id}) +        info_request = compat_urllib_request.Request(info_url, data) +        info_request.add_header('Content-Type', 'application/x-www-form-urlencoded') +        info_response = self._download_webpage(info_request, video_id, u'Downloading info webpage') +        if info_response is None: +            raise ExtractorError(u'Unable to extract the media url') +        (final_url, thumbnail_url) = map(lambda x: x.split('=')[1], info_response.split('&')) + +        return [{ +            'id':        video_id, +            'url':       final_url, +            'ext':       ext, +            'title':     title, +            'thumbnail': thumbnail_url, +        }] + +class GametrailersIE(InfoExtractor): +    _VALID_URL = r'http://www.gametrailers.com/(?P<type>videos|reviews|full-episodes)/(?P<id>.*?)/(?P<title>.*)' + +    def _real_extract(self, url): +        mobj = re.match(self._VALID_URL, url) +        if mobj is None: +            raise ExtractorError(u'Invalid URL: %s' % url) +        video_id = mobj.group('id') +        video_type = mobj.group('type') +        webpage = self._download_webpage(url, video_id) +        if video_type == 'full-episodes': +            mgid_re = r'data-video="(?P<mgid>mgid:.*?)"' +        else: +            mgid_re = r'data-contentId=\'(?P<mgid>mgid:.*?)\'' +        m_mgid = re.search(mgid_re, webpage) +        if m_mgid is None: +            raise ExtractorError(u'Unable to extract mgid') +        mgid = m_mgid.group(1) +        data = compat_urllib_parse.urlencode({'uri': mgid, 'acceptMethods': 'fms'}) + +        info_page = self._download_webpage('http://www.gametrailers.com/feeds/mrss?' + data, +                                           video_id, u'Downloading video info') +        links_webpage = self._download_webpage('http://www.gametrailers.com/feeds/mediagen/?' + data, +                                               video_id, u'Downloading video urls info') + +        self.report_extraction(video_id) +        info_re = r'''<title><!\[CDATA\[(?P<title>.*?)\]\]></title>.* +                      <description><!\[CDATA\[(?P<description>.*?)\]\]></description>.* +                      <image>.* +                        <url>(?P<thumb>.*?)</url>.* +                      </image>''' + +        m_info = re.search(info_re, info_page, re.VERBOSE|re.DOTALL) +        if m_info is None: +            raise ExtractorError(u'Unable to extract video info') +        video_title = m_info.group('title') +        video_description = m_info.group('description') +        video_thumb = m_info.group('thumb') + +        m_urls = re.finditer(r'<src>(?P<url>.*)</src>', links_webpage) +        if m_urls is None: +            raise ExtractError(u'Unable to extrat video url') +        # They are sorted from worst to best quality +        video_url = list(m_urls)[-1].group('url') + +        return {'url':         video_url, +                'id':          video_id, +                'title':       video_title, +                # Videos are actually flv not mp4 +                'ext':         'flv', +                'thumbnail':   video_thumb, +                'description': video_description, +                }  def gen_extractors():      """ Return a list of an instance of every supported extractor. @@ -4448,6 +4596,7 @@ def gen_extractors():          SpiegelIE(),          LiveLeakIE(),          ARDIE(), +        ZDFIE(),          TumblrIE(),          BandcampIE(),          RedTubeIE(), @@ -4458,6 +4607,8 @@ def gen_extractors():          TeamcocoIE(),          XHamsterIE(),          HypemIE(), +        Vbox7IE(), +        GametrailersIE(),          GenericIE()      ]  | 
