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.

85 lines
3.2 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. unified_strdate,
  8. )
  9. class DreiSatIE(InfoExtractor):
  10. IE_NAME = '3sat'
  11. _VALID_URL = r'(?:http://)?(?:www\.)?3sat.de/mediathek/index.php\?(?:(?:mode|display)=[^&]+&)*obj=(?P<id>[0-9]+)$'
  12. _TEST = {
  13. u"url": u"http://www.3sat.de/mediathek/index.php?obj=36983",
  14. u'file': u'36983.webm',
  15. u'md5': u'57c97d0469d71cf874f6815aa2b7c944',
  16. u'info_dict': {
  17. u"title": u"Kaffeeland Schweiz",
  18. 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...",
  19. u"uploader": u"3sat",
  20. u"upload_date": u"20130622"
  21. }
  22. }
  23. def _real_extract(self, url):
  24. mobj = re.match(self._VALID_URL, url)
  25. video_id = mobj.group('id')
  26. details_url = 'http://www.3sat.de/mediathek/xmlservice/web/beitragsDetails?ak=web&id=%s' % video_id
  27. details_xml = self._download_webpage(details_url, video_id, note=u'Downloading video details')
  28. details_doc = xml.etree.ElementTree.fromstring(details_xml.encode('utf-8'))
  29. thumbnail_els = details_doc.findall('.//teaserimage')
  30. thumbnails = [{
  31. 'width': te.attrib['key'].partition('x')[0],
  32. 'height': te.attrib['key'].partition('x')[2],
  33. 'url': te.text,
  34. } for te in thumbnail_els]
  35. information_el = details_doc.find('.//information')
  36. video_title = information_el.find('./title').text
  37. video_description = information_el.find('./detail').text
  38. details_el = details_doc.find('.//details')
  39. video_uploader = details_el.find('./channel').text
  40. upload_date = unified_strdate(details_el.find('./airtime').text)
  41. format_els = details_doc.findall('.//formitaet')
  42. formats = [{
  43. 'format_id': fe.attrib['basetype'],
  44. 'width': int(fe.find('./width').text),
  45. 'height': int(fe.find('./height').text),
  46. 'url': fe.find('./url').text,
  47. 'ext': determine_ext(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. '_type': 'video',
  60. 'id': video_id,
  61. 'title': video_title,
  62. 'formats': formats,
  63. 'description': video_description,
  64. 'thumbnails': thumbnails,
  65. 'thumbnail': thumbnails[-1]['url'],
  66. 'uploader': video_uploader,
  67. 'upload_date': upload_date,
  68. }
  69. # TODO: Remove when #980 has been merged
  70. info.update(formats[-1])
  71. return info