Merge branch 'master' of github.com:rg3/youtube-dl
authorPhilipp Hagemeister <phihag@phihag.de>
Thu, 20 Dec 2012 20:28:32 +0000 (21:28 +0100)
committerPhilipp Hagemeister <phihag@phihag.de>
Thu, 20 Dec 2012 20:28:32 +0000 (21:28 +0100)
1  2 
test/tests.json
youtube_dl/InfoExtractors.py
youtube_dl/__init__.py

diff --combined test/tests.json
index 9bf56082e3deabbcab84119bb2c3e071a94ceee0,b573affc5d231523c2261007754a12538896c9ab..dbff62676c08757b132c7d715d3ead9477953770
@@@ -2,7 -2,14 +2,14 @@@
    {
      "name": "Youtube",
      "url":  "http://www.youtube.com/watch?v=BaW_jenozKc",
-     "file":  "BaW_jenozKc.mp4"
+     "file":  "BaW_jenozKc.mp4",
+     "info_dict": {
+       "title": "youtube-dl test video \"'/\\ä↭𝕐",
+       "uploader": "Philipp Hagemeister",
+       "uploader_id": "phihag",
+       "upload_date": "20121002",
+       "description": "test chars:  \"'/\\ä↭𝕐\n\nThis is a test video for youtube-dl.\n\nFor more information, contact phihag@phihag.de ."
+     }
    },
    {
      "name": "Dailymotion",
    },
    {
      "name": "Vimeo",
-     "md5":  "60540a4ec7cc378ec84b919c0aed5023",
-     "url":  "http://vimeo.com/14160053",
-     "file": "14160053.mp4"
+     "md5":  "8879b6cc097e987f02484baf890129e5",
+     "url":  "http://vimeo.com/56015672",
+     "file": "56015672.mp4",
+     "info_dict": {
+       "title": "youtube-dl test video - ★ \" ' 幸 / \\ ä ↭ 𝕐",
+       "uploader": "Filippo Valsorda",
+       "uploader_id": "user7108434",
+       "upload_date": "20121220",
+       "description": "This is a test case for youtube-dl.\nFor more information, see github.com/rg3/youtube-dl\nTest chars: ★ \" ' 幸 / \\ ä ↭ 𝕐"
+     }
    },
    {
      "name": "Soundcloud",
      "name": "Escapist",
      "url": "http://www.escapistmagazine.com/videos/view/the-escapist-presents/6618-Breaking-Down-Baldurs-Gate",
      "file": "6618-Breaking-Down-Baldurs-Gate.flv",
-     "md5": "c6793dbda81388f4264c1ba18684a74d"
+     "md5": "c6793dbda81388f4264c1ba18684a74d",
+     "skip": "Fails with timeout on Travis"
    },
    {
      "name": "GooglePlus",
      "url": "https://plus.google.com/u/0/108897254135232129896/posts/ZButuJc6CtH",
      "file": "ZButuJc6CtH.flv"
 +  },
 +  {
 +    "name": "FunnyOrDie",
 +    "url": "http://www.funnyordie.com/videos/0732f586d7/heart-shaped-box-literal-video-version",
 +    "file": "0732f586d7.mp4",
 +    "md5": "f647e9e90064b53b6e046e75d0241fbd"
    }
  ]
index d94ebde34d4f9fc4c4b5856ef66fa6520e5671be,5a903233142e0f2862f3cc37cfb5978676a5cc07..697c031c5119176874558aef23eadb163e45fcdd
@@@ -32,7 -32,7 +32,7 @@@ class InfoExtractor(object)
  
      id:             Video identifier.
      url:            Final video URL.
-     uploader:       Nickname of the video uploader, unescaped.
+     uploader:       Full name of the video uploader, unescaped.
      upload_date:    Video upload date (YYYYMMDD).
      title:          Video title, unescaped.
      ext:            Video filename extension.
@@@ -42,6 -42,7 +42,7 @@@
      format:         The video format, defaults to ext (used for --get-format)
      thumbnail:      Full URL to a video thumbnail image.
      description:    One-line video description.
+     uploader_id:    Nickname or id of the video uploader.
      player_url:     SWF Player URL (used for rtmpdump).
      subtitles:      The .srt file contents.
      urlhandle:      [internal] The urlHandle to be used to download the file,
@@@ -219,6 -220,34 +220,34 @@@ class YoutubeIE(InfoExtractor)
              srt += caption + '\n\n'
          return srt
  
+     def _extract_subtitles(self, video_id):
+         self.report_video_subtitles_download(video_id)
+         request = compat_urllib_request.Request('http://video.google.com/timedtext?hl=en&type=list&v=%s' % video_id)
+         try:
+             srt_list = compat_urllib_request.urlopen(request).read().decode('utf-8')
+         except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
+             return (u'WARNING: unable to download video subtitles: %s' % compat_str(err), None)
+         srt_lang_list = re.findall(r'name="([^"]*)"[^>]+lang_code="([\w\-]+)"', srt_list)
+         srt_lang_list = dict((l[1], l[0]) for l in srt_lang_list)
+         if not srt_lang_list:
+             return (u'WARNING: video has no closed captions', None)
+         if self._downloader.params.get('subtitleslang', False):
+             srt_lang = self._downloader.params.get('subtitleslang')
+         elif 'en' in srt_lang_list:
+             srt_lang = 'en'
+         else:
+             srt_lang = list(srt_lang_list.keys())[0]
+         if not srt_lang in srt_lang_list:
+             return (u'WARNING: no closed captions found in the specified language', None)
+         request = compat_urllib_request.Request('http://www.youtube.com/api/timedtext?lang=%s&name=%s&v=%s' % (srt_lang, srt_lang_list[srt_lang], video_id))
+         try:
+             srt_xml = compat_urllib_request.urlopen(request).read().decode('utf-8')
+         except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
+             return (u'WARNING: unable to download video subtitles: %s' % compat_str(err), None)
+         if not srt_xml:
+             return (u'WARNING: unable to download video subtitles', None)
+         return (None, self._closed_captions_xml_to_srt(srt_xml))
      def _print_formats(self, formats):
          print('Available formats:')
          for x in formats:
  
          # uploader
          if 'author' not in video_info:
-             self._downloader.trouble(u'ERROR: unable to extract uploader nickname')
+             self._downloader.trouble(u'ERROR: unable to extract uploader name')
              return
          video_uploader = compat_urllib_parse.unquote_plus(video_info['author'][0])
  
+         # uploader_id
+         video_uploader_id = None
+         mobj = re.search(r'<link itemprop="url" href="http://www.youtube.com/user/([^"]+)">', video_webpage)
+         if mobj is not None:
+             video_uploader_id = mobj.group(1)
+         else:
+             self._downloader.trouble(u'WARNING: unable to extract uploader nickname')
          # title
          if 'title' not in video_info:
              self._downloader.trouble(u'ERROR: unable to extract video title')
          # closed captions
          video_subtitles = None
          if self._downloader.params.get('writesubtitles', False):
-             try:
-                 self.report_video_subtitles_download(video_id)
-                 request = compat_urllib_request.Request('http://video.google.com/timedtext?hl=en&type=list&v=%s' % video_id)
-                 try:
-                     srt_list = compat_urllib_request.urlopen(request).read().decode('utf-8')
-                 except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
-                     raise Trouble(u'WARNING: unable to download video subtitles: %s' % compat_str(err))
-                 srt_lang_list = re.findall(r'name="([^"]*)"[^>]+lang_code="([\w\-]+)"', srt_list)
-                 srt_lang_list = dict((l[1], l[0]) for l in srt_lang_list)
-                 if not srt_lang_list:
-                     raise Trouble(u'WARNING: video has no closed captions')
-                 if self._downloader.params.get('subtitleslang', False):
-                     srt_lang = self._downloader.params.get('subtitleslang')
-                 elif 'en' in srt_lang_list:
-                     srt_lang = 'en'
-                 else:
-                     srt_lang = srt_lang_list.keys()[0]
-                 if not srt_lang in srt_lang_list:
-                     raise Trouble(u'WARNING: no closed captions found in the specified language')
-                 request = compat_urllib_request.Request('http://www.youtube.com/api/timedtext?lang=%s&name=%s&v=%s' % (srt_lang, srt_lang_list[srt_lang], video_id))
-                 try:
-                     srt_xml = compat_urllib_request.urlopen(request).read().decode('utf-8')
-                 except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
-                     raise Trouble(u'WARNING: unable to download video subtitles: %s' % compat_str(err))
-                 if not srt_xml:
-                     raise Trouble(u'WARNING: unable to download video subtitles')
-                 video_subtitles = self._closed_captions_xml_to_srt(srt_xml)
-             except Trouble as trouble:
-                 self._downloader.trouble(str(trouble))
+             (srt_error, video_subtitles) = self._extract_subtitles(video_id)
+             if srt_error:
+                 self._downloader.trouble(srt_error)
  
          if 'length_seconds' not in video_info:
              self._downloader.trouble(u'WARNING: unable to extract video duration')
          elif 'url_encoded_fmt_stream_map' in video_info and len(video_info['url_encoded_fmt_stream_map']) >= 1:
              url_data_strs = video_info['url_encoded_fmt_stream_map'][0].split(',')
              url_data = [compat_parse_qs(uds) for uds in url_data_strs]
-             url_data = filter(lambda ud: 'itag' in ud and 'url' in ud, url_data)
+             url_data = [ud for ud in url_data if 'itag' in ud and 'url' in ud]
              url_map = dict((ud['itag'][0], ud['url'][0] + '&signature=' + ud['sig'][0]) for ud in url_data)
  
              format_limit = self._downloader.params.get('format_limit', None)
                  'id':       video_id,
                  'url':      video_real_url,
                  'uploader': video_uploader,
+                 'uploader_id': video_uploader_id,
                  'upload_date':  upload_date,
                  'title':    video_title,
                  'ext':      video_extension,
@@@ -992,8 -1004,9 +1004,9 @@@ class VimeoIE(InfoExtractor)
          # Extract title
          video_title = config["video"]["title"]
  
-         # Extract uploader
+         # Extract uploader and uploader_id
          video_uploader = config["video"]["owner"]["name"]
+         video_uploader_id = config["video"]["owner"]["url"].split('/')[-1]
  
          # Extract video thumbnail
          video_thumbnail = config["video"]["thumbnail"]
  
          # Extract upload date
          video_upload_date = None
-         mobj = re.search(r'<span id="clip-date" style="display:none">[^:]*: (.*?)( \([^\(]*\))?</span>', webpage)
+         mobj = re.search(r'<meta itemprop="dateCreated" content="(\d{4})-(\d{2})-(\d{2})T', webpage)
          if mobj is not None:
-             video_upload_date = mobj.group(1)
+             video_upload_date = mobj.group(1) + mobj.group(2) + mobj.group(3)
  
          # Vimeo specific: extract request signature and timestamp
          sig = config['request']['signature']
              'id':       video_id,
              'url':      video_url,
              'uploader': video_uploader,
+             'uploader_id': video_uploader_id,
              'upload_date':  video_upload_date,
              'title':    video_title,
              'ext':      video_extension,
@@@ -2113,7 -2127,7 +2127,7 @@@ class FacebookIE(InfoExtractor)
          video_description = video_info.get('description', 'No description available.')
  
          url_map = video_info['video_urls']
-         if len(url_map.keys()) > 0:
+         if len(list(url_map.keys())) > 0:
              # Decide which formats to download
              req_format = self._downloader.params.get('format', None)
              format_limit = self._downloader.params.get('format_limit', None)
@@@ -2973,7 -2987,7 +2987,7 @@@ class MixcloudIE(InfoExtractor)
                  if file_url is not None:
                      break # got it!
          else:
-             if req_format not in formats.keys():
+             if req_format not in list(formats.keys()):
                  self._downloader.trouble(u'ERROR: format is not available')
                  return
  
@@@ -3272,7 -3286,7 +3286,7 @@@ class YoukuIE(InfoExtractor)
              seed = config['data'][0]['seed']
  
              format = self._downloader.params.get('format', None)
-             supported_format = config['data'][0]['streamfileids'].keys()
+             supported_format = list(config['data'][0]['streamfileids'].keys())
  
              if format is None or format == 'best':
                  if 'hd2' in supported_format:
@@@ -3630,52 -3644,3 +3644,52 @@@ class JustinTVIE(InfoExtractor)
                  break
              offset += limit
          return info
 +
 +class FunnyOrDieIE(InfoExtractor):
 +    _VALID_URL = r'^(?:https?://)?(?:www\.)?funnyordie\.com/videos/(?P<id>[0-9a-f]+)/.*$'
 +    IE_NAME = u'FunnyOrDie'
 +
 +    def report_extraction(self, video_id):
 +        self._downloader.to_screen(u'[%s] %s: Extracting information' % (self.IE_NAME, video_id))
 +
 +    def _real_extract(self, url):
 +        mobj = re.match(self._VALID_URL, url)
 +        if mobj is None:
 +            self._downloader.trouble(u'ERROR: invalid URL: %s' % url)
 +            return
 +
 +        video_id = mobj.group('id')
 +        self.report_extraction(video_id)
 +        try:
 +            urlh = compat_urllib_request.urlopen(url)
 +            webpage_bytes = urlh.read()
 +            webpage = webpage_bytes.decode('utf-8', 'ignore')
 +        except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
 +            self._downloader.trouble(u'ERROR: unable to download webpage: %s' % compat_str(err))
 +            return
 +
 +        m = re.search(r'<video[^>]*>\s*<source[^>]*>\s*<source src="(?P<url>[^"]+)"', webpage, re.DOTALL)
 +        if not m:
 +            self._downloader.trouble(u'ERROR: unable to find video information')
 +        video_url = unescapeHTML(m.group('url'))
 +        print(video_url)
 +
 +        m = re.search(r"class='player_page_h1'>\s+<a.*?>(?P<title>.*?)</a>", webpage)
 +        if not m:
 +            self._downloader.trouble(u'Cannot find video title')
 +        title = unescapeHTML(m.group('title'))
 +
 +        m = re.search(r'<meta property="og:description" content="(?P<desc>.*?)"', webpage)
 +        if m:
 +            desc = unescapeHTML(m.group('desc'))
 +        else:
 +            desc = None
 +
 +        info = {
 +            'id': video_id,
 +            'url': video_url,
 +            'ext': 'mp4',
 +            'title': title,
 +            'description': desc,
 +        }
 +        return [info]
diff --combined youtube_dl/__init__.py
index f94e0dcdb520fa247849772338e42f8e224325f5,1102b2fce44610d3611577dac9ca96883e33ba86..c7a0bb9594e835fe6325d5b4a0c89ad8d4b11ef2
@@@ -307,7 -307,7 +307,7 @@@ def parseOpts()
              action='store_true', dest='autonumber',
              help='number downloaded files starting from 00000', default=False)
      filesystem.add_option('-o', '--output',
-             dest='outtmpl', metavar='TEMPLATE', help='output filename template. Use %(title)s to get the title, %(uploader)s for the uploader name, %(autonumber)s to get an automatically incremented number, %(ext)s for the filename extension, %(upload_date)s for the upload date (YYYYMMDD), %(extractor)s for the provider (youtube, metacafe, etc), %(id)s for the video id and %% for a literal percent. Use - to output to stdout. Can also be used to download to a different directory, for example with -o \'/my/downloads/%(uploader)s/%(title)s-%(id)s.%(ext)s\' .')
+             dest='outtmpl', metavar='TEMPLATE', help='output filename template. Use %(title)s to get the title, %(uploader)s for the uploader name, %(uploader_id)s for the uploader nickname if different, %(autonumber)s to get an automatically incremented number, %(ext)s for the filename extension, %(upload_date)s for the upload date (YYYYMMDD), %(extractor)s for the provider (youtube, metacafe, etc), %(id)s for the video id and %% for a literal percent. Use - to output to stdout. Can also be used to download to a different directory, for example with -o \'/my/downloads/%(uploader)s/%(title)s-%(id)s.%(ext)s\' .')
      filesystem.add_option('--restrict-filenames',
              action='store_true', dest='restrictfilenames',
              help='Restrict filenames to only ASCII characters, and avoid "&" and spaces in filenames', default=False)
@@@ -400,7 -400,6 +400,7 @@@ def gen_extractors()
          ArteTvIE(),
          NBAIE(),
          JustinTVIE(),
 +        FunnyOrDieIE(),
          GenericIE()
      ]
  
@@@ -454,8 -453,8 +454,8 @@@ def _real_main()
      if opts.list_extractors:
          for ie in extractors:
              print(ie.IE_NAME + (' (CURRENTLY BROKEN)' if not ie._WORKING else ''))
-             matchedUrls = filter(lambda url: ie.suitable(url), all_urls)
-             all_urls = filter(lambda url: url not in matchedUrls, all_urls)
+             matchedUrls = [url for url in all_urls if ie.suitable(url)]
+             all_urls = [url for url in all_urls if url not in matchedUrls]
              for mu in matchedUrls:
                  print(u'  ' + mu)
          sys.exit(0)