# coding: utf-8
from __future__ import unicode_literals
-import re
-
from .common import InfoExtractor
from ..utils import (
- ExtractorError,
- compat_urllib_parse,
- get_meta_content,
+ determine_ext,
+ int_or_none,
parse_iso8601,
)
class HeiseIE(InfoExtractor):
- _VALID_URL = (
- r'^https?://(?:www\.)?heise\.de/video/artikel/' +
- r'.+?(?P<id>[0-9]+)\.html$'
- )
+ _VALID_URL = r'''(?x)
+ https?://(?:www\.)?heise\.de/video/artikel/
+ .+?(?P<id>[0-9]+)\.html(?:$|[?#])
+ '''
_TEST = {
'url': (
- 'http://www.heise.de/video/artikel/Podcast-c-t-uplink-3-3-' +
- 'Owncloud-Tastaturen-Peilsender-Smartphone-2404147.html'
+ 'http://www.heise.de/video/artikel/Podcast-c-t-uplink-3-3-Owncloud-Tastaturen-Peilsender-Smartphone-2404147.html'
),
'md5': 'ffed432483e922e88545ad9f2f15d30e',
'info_dict': {
'id': '2404147',
'ext': 'mp4',
'title': (
- "Podcast: c't uplink 3.3 – Owncloud / Tastaturen / " +
- "Peilsender Smartphone"
+ "Podcast: c't uplink 3.3 – Owncloud / Tastaturen / Peilsender Smartphone"
),
- 'format_id': 'mp4_720',
+ 'format_id': 'mp4_720p',
'timestamp': 1411812600,
'upload_date': '20140927',
+ 'description': 'In uplink-Episode 3.3 geht es darum, wie man sich von Cloud-Anbietern emanzipieren kann, worauf man beim Kauf einer Tastatur achten sollte und was Smartphones über uns verraten.',
+ 'thumbnail': 're:^https?://.*\.jpe?g$',
}
}
- _CONFIG = (
- r'".+?\?sequenz=(?P<sequenz>.+?)&container=(?P<container>.+?)' +
- r'(?:&hd=(?P<hd>.+?))?(?:&signature=(?P<signature>.+?))?&callback=\?"'
- )
- _PREFIX = 'http://www.heise.de/videout/info?'
-
- def _warn(self, fmt, *args):
- self.report_warning(fmt.format(*args), self._id)
-
- def _parse_config_url(self, html):
- m = re.search(self._CONFIG, html)
- if not m:
- raise ExtractorError('No config found')
-
- qs = compat_urllib_parse.urlencode(dict((k, v) for k, v
- in m.groupdict().items()
- if v is not None))
- return self._PREFIX + qs
-
def _real_extract(self, url):
- mobj = re.match(self._VALID_URL, url)
- self._id = mobj.group('id')
-
- html = self._download_webpage(url, self._id)
- config = self._download_json(self._parse_config_url(html), self._id)
+ video_id = self._match_id(url)
+ webpage = self._download_webpage(url, video_id)
+
+ container_id = self._search_regex(
+ r'<div class="videoplayerjw".*?data-container="([0-9]+)"',
+ webpage, 'container ID')
+ sequenz_id = self._search_regex(
+ r'<div class="videoplayerjw".*?data-sequenz="([0-9]+)"',
+ webpage, 'sequenz ID')
+ data_url = 'http://www.heise.de/videout/feed?container=%s&sequenz=%s' % (container_id, sequenz_id)
+ doc = self._download_xml(data_url, video_id)
info = {
- 'id': self._id
+ 'id': video_id,
+ 'thumbnail': self._og_search_thumbnail(webpage),
+ 'timestamp': parse_iso8601(
+ self._html_search_meta('date', webpage)),
+ 'description': self._og_search_description(webpage),
}
- title = get_meta_content('fulltitle', html)
+ title = self._html_search_meta('fulltitle', webpage)
if title:
info['title'] = title
- elif config.get('title'):
- info['title'] = config['title']
else:
- self._warn('title: not found')
- info['title'] = 'heise'
-
- if (not config.get('formats') or
- not hasattr(config['formats'], 'items')):
- raise ExtractorError('No formats found')
+ info['title'] = self._og_search_title(webpage)
formats = []
- for t, rs in config['formats'].items():
- if not rs or not hasattr(rs, 'items'):
- self._warn('formats: {0}: no resolutions', t)
- continue
-
- for res, obj in rs.items():
- format_id = '{0}_{1}'.format(t, res)
-
- if (not obj or not obj.get('url') or
- not isinstance(obj['url'], str)):
- self._warn('formats: {0}: no url', format_id)
- continue
-
- fmt = {
- 'url': obj['url'],
- 'format_id': format_id
- }
- try:
- fmt['height'] = int(res)
- except ValueError as e:
- self._warn('formats: {0}: height: {1}', t, e)
-
- formats.append(fmt)
-
+ for source_node in doc.findall('.//{http://rss.jwpcdn.com/}source'):
+ label = source_node.attrib['label']
+ height = int_or_none(self._search_regex(
+ r'^(.*?_)?([0-9]+)p$', label, 'height', default=None))
+ video_url = source_node.attrib['file']
+ ext = determine_ext(video_url, '')
+ formats.append({
+ 'url': video_url,
+ 'format_note': label,
+ 'format_id': '%s_%s' % (ext, label),
+ 'height': height,
+ })
self._sort_formats(formats)
info['formats'] = formats
- if config.get('poster') and isinstance(config['poster'], str):
- info['thumbnail'] = config['poster']
-
- date = get_meta_content('date', html)
- if date and isinstance(date, str):
- try:
- info['timestamp'] = parse_iso8601(date)
- except ValueError as e:
- self._warn('timestamp: {0}', e)
-
return info