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.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. 'filesize': int(fe.find('./filesize').text),
  48. 'video_bitrate': int(fe.find('./videoBitrate').text),
  49. '3sat_qualityname': fe.find('./quality').text,
  50. } for fe in format_els
  51. if not fe.find('./url').text.startswith('http://www.metafilegenerator.de/')]
  52. def _sortkey(format):
  53. qidx = ['low', 'med', 'high', 'veryhigh'].index(format['3sat_qualityname'])
  54. prefer_http = 1 if 'rtmp' in format['url'] else 0
  55. return (qidx, prefer_http, format['video_bitrate'])
  56. formats.sort(key=_sortkey)
  57. info = {
  58. '_type': 'video',
  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 info