]> git.bitcoin.ninja Git - youtube-dl/commitdiff
Merge remote-tracking branch 'origin/master'
authorPhilipp Hagemeister <phihag@phihag.de>
Mon, 3 Feb 2014 04:19:28 +0000 (05:19 +0100)
committerPhilipp Hagemeister <phihag@phihag.de>
Mon, 3 Feb 2014 04:19:28 +0000 (05:19 +0100)
Conflicts:
youtube_dl/extractor/bliptv.py

1  2 
youtube_dl/extractor/bliptv.py

index c8234ac31adbe923bf1e92423d461eefaf1ce7e8,9ca9f65253ad38d780fe7e4890f7452544f75568..9c120051c2ac15ed87468d7805da123fd981fd60
@@@ -66,67 -71,56 +66,68 @@@ class BlipTVIE(SubtitlesInfoExtractor)
          json_url = url + cchar + 'skin=json&version=2&no_wrap=1'
          request = compat_urllib_request.Request(json_url)
          request.add_header('User-Agent', 'iTunes/10.6.1')
 -        self.report_extraction(mobj.group(1))
 -        urlh = self._request_webpage(request, None, False,
 -            'unable to download video info webpage')
 -
 -        try:
 -            json_code_bytes = urlh.read()
 -            json_code = json_code_bytes.decode('utf-8')
 -        except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
 -            raise ExtractorError('Unable to read video info webpage: %s' % compat_str(err))
 -
 -        try:
 -            json_data = json.loads(json_code)
 -            if 'Post' in json_data:
 -                data = json_data['Post']
 -            else:
 -                data = json_data
 -
 -            upload_date = datetime.datetime.strptime(data['datestamp'], '%m-%d-%y %H:%M%p').strftime('%Y%m%d')
 -            formats = []
 -            if 'additionalMedia' in data:
 -                for f in sorted(data['additionalMedia'], key=lambda f: int(0 if f['media_height'] is None else f['media_height'])):
 -                    if not int(0 if f['media_height'] is None else f['media_height']): # filter out m3u8 and srt files
 -                        continue
 -                    formats.append({
 -                        'url': f['url'],
 -                        'format_id': f['role'],
 -                        'width': int(f['media_width']),
 -                        'height': int(f['media_height']),
 -                    })
 -            else:
++
 +        json_data = self._download_json(request, video_id=presumptive_id)
 +
 +        if 'Post' in json_data:
 +            data = json_data['Post']
 +        else:
 +            data = json_data
 +
 +        video_id = compat_str(data['item_id'])
 +        upload_date = datetime.datetime.strptime(data['datestamp'], '%m-%d-%y %H:%M%p').strftime('%Y%m%d')
 +        subtitles = {}
 +        formats = []
 +        if 'additionalMedia' in data:
 +            for f in data['additionalMedia']:
 +                if f.get('file_type_srt') == 1:
 +                    LANGS = {
 +                        'english': 'en',
 +                    }
 +                    lang = f['role'].rpartition('-')[-1].strip().lower()
 +                    langcode = LANGS.get(lang, lang)
 +                    subtitles[langcode] = f['url']
 +                    continue
 +                if not int(f['media_width']):  # filter m3u8
 +                    continue
                  formats.append({
 -                    'url': data['media']['url'],
 -                    'width': int(data['media']['width']),
 -                    'height': int(data['media']['height']),
 +                    'url': f['url'],
 +                    'format_id': f['role'],
 +                    'width': int(f['media_width']),
 +                    'height': int(f['media_height']),
                  })
 +        else:
 +            formats.append({
 +                'url': data['media']['url'],
 +                'width': int(data['media']['width']),
 +                'height': int(data['media']['height']),
 +            })
 +        self._sort_formats(formats)
 +
 +        # subtitles
 +        video_subtitles = self.extract_subtitles(video_id, subtitles)
 +        if self._downloader.params.get('listsubtitles', False):
 +            self._list_available_subtitles(video_id, subtitles)
 +            return
 +
 +        return {
 +            'id': video_id,
 +            'uploader': data['display_name'],
 +            'upload_date': upload_date,
 +            'title': data['title'],
 +            'thumbnail': data['thumbnailUrl'],
 +            'description': data['description'],
 +            'user_agent': 'iTunes/10.6.1',
 +            'formats': formats,
 +            'subtitles': video_subtitles,
 +        }
  
 -            self._sort_formats(formats)
 -
 -            return {
 -                'id': compat_str(data['item_id']),
 -                'uploader': data['display_name'],
 -                'upload_date': upload_date,
 -                'title': data['title'],
 -                'thumbnail': data['thumbnailUrl'],
 -                'description': data['description'],
 -                'user_agent': 'iTunes/10.6.1',
 -                'formats': formats,
 -            }
 -        except (ValueError, KeyError) as err:
 -            raise ExtractorError('Unable to parse video information: %s' % repr(err))
 +    def _download_subtitle_url(self, sub_lang, url):
 +        # For some weird reason, blip.tv serves a video instead of subtitles
 +        # when we request with a common UA
 +        req = compat_urllib_request.Request(url)
 +        req.add_header('Youtubedl-user-agent', 'youtube-dl')
 +        return self._download_webpage(req, None, note=False)
  
  
  class BlipTVUserIE(InfoExtractor):