You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
3.3 KiB

  1. # coding: utf-8
  2. import re
  3. import xml.etree.ElementTree
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. determine_ext,
  7. ExtractorError,
  8. unified_strdate,
  9. )
  10. class DreiSatIE(InfoExtractor):
  11. IE_NAME = '3sat'
  12. _VALID_URL = r'(?:http://)?(?:www\.)?3sat.de/mediathek/index.php\?(?:(?:mode|display)=[^&]+&)*obj=(?P<id>[0-9]+)$'
  13. _TEST = {
  14. u"url": u"http://www.3sat.de/mediathek/index.php?obj=36983",
  15. u'file': u'36983.webm',
  16. u'md5': u'57c97d0469d71cf874f6815aa2b7c944',
  17. u'info_dict': {
  18. u"title": u"Kaffeeland Schweiz",
  19. u"description": u"Über 80 Kaffeeröstereien liefern in der Schweiz das Getränk, in das das Land so vernarrt ist: Mehr als 1000 Tassen trinkt ein Schweizer pro Jahr. SCHWEIZWEIT nimmt die Kaffeekultur unter die...",
  20. u"uploader": u"3sat",
  21. u"upload_date": u"20130622"
  22. }
  23. }
  24. def _real_extract(self, url):
  25. mobj = re.match(self._VALID_URL, url)
  26. video_id = mobj.group('id')
  27. details_url = 'http://www.3sat.de/mediathek/xmlservice/web/beitragsDetails?ak=web&id=%s' % video_id
  28. details_xml = self._download_webpage(details_url, video_id, note=u'Downloading video details')
  29. details_doc = xml.etree.ElementTree.fromstring(details_xml.encode('utf-8'))
  30. thumbnail_els = details_doc.findall('.//teaserimage')
  31. thumbnails = [{
  32. 'width': te.attrib['key'].partition('x')[0],
  33. 'height': te.attrib['key'].partition('x')[2],
  34. 'url': te.text,
  35. } for te in thumbnail_els]
  36. information_el = details_doc.find('.//information')
  37. video_title = information_el.find('./title').text
  38. video_description = information_el.find('./detail').text
  39. details_el = details_doc.find('.//details')
  40. video_uploader = details_el.find('./channel').text
  41. upload_date = unified_strdate(details_el.find('./airtime').text)
  42. format_els = details_doc.findall('.//formitaet')
  43. formats = [{
  44. 'format_id': fe.attrib['basetype'],
  45. 'width': int(fe.find('./width').text),
  46. 'height': int(fe.find('./height').text),
  47. 'url': fe.find('./url').text,
  48. 'filesize': int(fe.find('./filesize').text),
  49. 'video_bitrate': int(fe.find('./videoBitrate').text),
  50. '3sat_qualityname': fe.find('./quality').text,
  51. } for fe in format_els
  52. if not fe.find('./url').text.startswith('http://www.metafilegenerator.de/')]
  53. def _sortkey(format):
  54. qidx = ['low', 'med', 'high', 'veryhigh'].index(format['3sat_qualityname'])
  55. prefer_http = 1 if 'rtmp' in format['url'] else 0
  56. return (qidx, prefer_http, format['video_bitrate'])
  57. formats.sort(key=_sortkey)
  58. info = {
  59. 'id': video_id,
  60. 'title': video_title,
  61. 'formats': formats,
  62. 'description': video_description,
  63. 'thumbnails': thumbnails,
  64. 'thumbnail': thumbnails[-1]['url'],
  65. 'uploader': video_uploader,
  66. 'upload_date': upload_date,
  67. }
  68. # TODO: Remove when #980 has been merged
  69. info['url'] = formats[-1]['url']
  70. info['ext'] = determine_ext(formats[-1]['url'])
  71. return self.video_result(info)