class FileDownloader(youtube_dl.FileDownloader):
def __init__(self, *args, **kwargs):
- self._to_stderr = self.to_stderr
self.to_stderr = self.to_screen
self.processed_info_dicts = []
return youtube_dl.FileDownloader.__init__(self, *args, **kwargs)
def report_warning(self, message):
- # let warnings pass to output
- if sys.stderr.isatty() and os.name != 'nt':
- _msg_header=u'\033[0;33mWARNING:\033[0m'
- else:
- _msg_header=u'WARNING:'
- warning_message=u'%s %s' % (_msg_header,message)
- self._to_stderr(warning_message)
+ # Don't accept warnings during tests
+ raise ExtractorError(message)
def process_info(self, info_dict):
self.processed_info_dicts.append(info_dict)
return youtube_dl.FileDownloader.process_info(self, info_dict)
}]
class NBAIE(InfoExtractor):
- _VALID_URL = r'^(?:https?://)?(?:watch\.|www\.)?nba\.com/(?:nba/)?video(/[^?]*)(\?.*)?$'
+ _VALID_URL = r'^(?:https?://)?(?:watch\.|www\.)?nba\.com/(?:nba/)?video(/[^?]*?)(?:/index\.html)?(?:\?.*)?$'
IE_NAME = u'nba'
def _real_extract(self, url):
raise ExtractorError(u'Invalid URL: %s' % url)
video_id = mobj.group(1)
- if video_id.endswith('/index.html'):
- video_id = video_id[:-len('/index.html')]
webpage = self._download_webpage(url, video_id)
title = self._search_regex(r'<meta property="og:title" content="(.*?)"',
webpage, 'title', default=shortened_video_id).replace('NBA.com: ', '')
- uploader_date = self._search_regex(r'<b>Date:</b> (.*?)</div>', webpage, 'upload_date', fatal=False)
+ # It isn't there in the HTML it returns to us
+ # uploader_date = self._search_regex(r'<b>Date:</b> (.*?)</div>', webpage, 'upload_date', fatal=False)
description = self._search_regex(r'<meta name="description" (?:content|value)="(.*?)" />', webpage, 'description', fatal=False)
'url': video_url,
'ext': 'mp4',
'title': title,
- 'uploader_date': uploader_date,
+ # 'uploader_date': uploader_date,
'description': description,
}
return [info]
req.add_header('Cookie', 'age_verified=1')
webpage = self._download_webpage(req, video_id)
- # Get the video title
- video_title = self._search_regex(r'<h1.*?>(?P<title>.*)</h1>',
- webpage, u'title').strip()
-
- # Get the video date
- upload_date = self._search_regex(r'Date:</label>(?P<date>.*) </li>',
- webpage, u'upload date', fatal=False)
- if upload_date: upload_date = unified_strdate(upload_date.strip())
+ # Get JSON parameters
+ json_params = self._search_regex(r'var currentVideo = new Video\((.*)\);', webpage, u'JSON parameters')
+ try:
+ params = json.loads(json_params)
+ except:
+ raise ExtractorError(u'Invalid JSON')
- # Get the video uploader
- video_uploader = self._search_regex(r'Submitted:</label>(?P<uploader>.*)</li>',
- webpage, u'uploader', fatal=False)
- if video_uploader: video_uploader = clean_html(video_uploader.strip())
+ self.report_extraction(video_id)
+ try:
+ video_title = params['title']
+ upload_date = unified_strdate(params['release_date_f'])
+ video_description = params['description']
+ video_uploader = params['submitted_by']
+ thumbnail = params['thumbnails'][0]['image']
+ except KeyError:
+ raise ExtractorError('Missing JSON parameter: ' + sys.exc_info()[1])
# Get all of the formats available
DOWNLOAD_LIST_RE = r'(?s)<ul class="downloadList">(?P<download_list>.*?)</ul>'
'title': title,
'ext': extension,
'format': format,
- 'thumbnail': None,
- 'description': None,
- 'player_url': None
+ 'thumbnail': thumbnail,
+ 'description': video_description
})
if self._downloader.params.get('listformats', None):