1
0
mirror of https://github.com/l1ving/youtube-dl synced 2024-11-23 02:52:53 +08:00
youtube-dl/youtube_dl/extractor/mdr.py

65 lines
2.1 KiB
Python
Raw Normal View History

from __future__ import unicode_literals
2013-12-11 01:40:50 +08:00
import re
from .common import InfoExtractor
2013-12-16 12:44:34 +08:00
2013-12-11 01:40:50 +08:00
class MDRIE(InfoExtractor):
_VALID_URL = r'^(?P<domain>https?://(?:www\.)?mdr\.de)/(?:.*)/(?P<type>video|audio)(?P<video_id>[^/_]+)(?:_|\.html)'
2014-11-24 03:41:03 +08:00
# No tests, MDR regularily deletes its videos
_TEST = {
'url': 'http://www.mdr.de/fakt/video189002.html',
'only_matching': True,
}
2013-12-11 01:40:50 +08:00
def _real_extract(self, url):
m = re.match(self._VALID_URL, url)
video_id = m.group('video_id')
domain = m.group('domain')
# determine title and media streams from webpage
html = self._download_webpage(url, video_id)
title = self._html_search_regex(r'<h[12]>(.*?)</h[12]>', html, 'title')
2013-12-16 12:44:34 +08:00
xmlurl = self._search_regex(
r'dataURL:\'(/(?:.+)/(?:video|audio)[0-9]+-avCustom.xml)', html, 'XML URL')
2013-12-16 12:44:34 +08:00
doc = self._download_xml(domain + xmlurl, video_id)
formats = []
for a in doc.findall('./assets/asset'):
url_el = a.find('.//progressiveDownloadUrl')
if url_el is None:
continue
abr = int(a.find('bitrateAudio').text) // 1000
media_type = a.find('mediaType').text
format = {
'abr': abr,
'filesize': int(a.find('fileSize').text),
'url': url_el.text,
}
vbr_el = a.find('bitrateVideo')
if vbr_el is None:
format.update({
'vcodec': 'none',
'format_id': '%s-%d' % (media_type, abr),
2013-12-16 12:44:34 +08:00
})
else:
vbr = int(vbr_el.text) // 1000
format.update({
'vbr': vbr,
'width': int(a.find('frameWidth').text),
'height': int(a.find('frameHeight').text),
'format_id': '%s-%d' % (media_type, vbr),
2013-12-16 12:44:34 +08:00
})
formats.append(format)
2013-12-25 06:34:11 +08:00
self._sort_formats(formats)
2013-12-16 12:44:34 +08:00
return {
'id': video_id,
'title': title,
'formats': formats,
}