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.

78 lines
3.0 KiB

  1. # coding: utf-8
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. determine_ext,
  6. unified_strdate,
  7. )
  8. class DreiSatIE(InfoExtractor):
  9. IE_NAME = '3sat'
  10. _VALID_URL = r'(?:http://)?(?:www\.)?3sat\.de/mediathek/index\.php\?(?:(?:mode|display)=[^&]+&)*obj=(?P<id>[0-9]+)$'
  11. _TEST = {
  12. u"url": u"http://www.3sat.de/mediathek/index.php?obj=36983",
  13. u'file': u'36983.webm',
  14. u'md5': u'57c97d0469d71cf874f6815aa2b7c944',
  15. u'info_dict': {
  16. u"title": u"Kaffeeland Schweiz",
  17. 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...",
  18. u"uploader": u"3sat",
  19. u"upload_date": u"20130622"
  20. }
  21. }
  22. def _real_extract(self, url):
  23. mobj = re.match(self._VALID_URL, url)
  24. video_id = mobj.group('id')
  25. details_url = 'http://www.3sat.de/mediathek/xmlservice/web/beitragsDetails?ak=web&id=%s' % video_id
  26. details_doc = self._download_xml(details_url, video_id, note=u'Downloading video details')
  27. thumbnail_els = details_doc.findall('.//teaserimage')
  28. thumbnails = [{
  29. 'width': te.attrib['key'].partition('x')[0],
  30. 'height': te.attrib['key'].partition('x')[2],
  31. 'url': te.text,
  32. } for te in thumbnail_els]
  33. information_el = details_doc.find('.//information')
  34. video_title = information_el.find('./title').text
  35. video_description = information_el.find('./detail').text
  36. details_el = details_doc.find('.//details')
  37. video_uploader = details_el.find('./channel').text
  38. upload_date = unified_strdate(details_el.find('./airtime').text)
  39. format_els = details_doc.findall('.//formitaet')
  40. formats = [{
  41. 'format_id': fe.attrib['basetype'],
  42. 'width': int(fe.find('./width').text),
  43. 'height': int(fe.find('./height').text),
  44. 'url': fe.find('./url').text,
  45. 'ext': determine_ext(fe.find('./url').text),
  46. 'filesize': int(fe.find('./filesize').text),
  47. 'video_bitrate': int(fe.find('./videoBitrate').text),
  48. '3sat_qualityname': fe.find('./quality').text,
  49. } for fe in format_els
  50. if not fe.find('./url').text.startswith('http://www.metafilegenerator.de/')]
  51. def _sortkey(format):
  52. qidx = ['low', 'med', 'high', 'veryhigh'].index(format['3sat_qualityname'])
  53. prefer_http = 1 if 'rtmp' in format['url'] else 0
  54. return (qidx, prefer_http, format['video_bitrate'])
  55. formats.sort(key=_sortkey)
  56. return {
  57. '_type': 'video',
  58. 'id': video_id,
  59. 'title': video_title,
  60. 'formats': formats,
  61. 'description': video_description,
  62. 'thumbnails': thumbnails,
  63. 'thumbnail': thumbnails[-1]['url'],
  64. 'uploader': video_uploader,
  65. 'upload_date': upload_date,
  66. }