- def _add_format(name, cfgurl):
- configJSON = self._download_webpage(
- cfgurl, videoId,
- u'Downloading ' + name + ' configuration',
- u'Unable to download ' + name + ' configuration')
-
- # Technically, it's JavaScript, not JSON
- configJSON = configJSON.replace("'", '"')
-
- try:
- config = json.loads(configJSON)
- except (ValueError,) as err:
- raise ExtractorError(u'Invalid JSON in configuration file: ' + compat_str(err))
- playlist = config['playlist']
- formats.append({
- 'url': playlist[1]['url'],
- 'format_id': name,
- })
-
- _add_format(u'normal', configUrl)
- hq_url = (configUrl +
- ('&hq=1' if '?' in configUrl else configUrl + '?hq=1'))
- try:
- _add_format(u'hq', hq_url)
- except ExtractorError:
- pass # That's fine, we'll just use normal quality