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.

81 lines
3.0 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  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. 'url': 'http://www.3sat.de/mediathek/index.php?mode=play&obj=45918',
  13. 'md5': 'be37228896d30a88f315b638900a026e',
  14. 'info_dict': {
  15. 'id': '45918',
  16. 'ext': 'mp4',
  17. 'title': 'Waidmannsheil',
  18. 'description': 'md5:cce00ca1d70e21425e72c86a98a56817',
  19. 'uploader': '3sat',
  20. 'upload_date': '20140913'
  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_doc = self._download_xml(details_url, video_id, 'Downloading video details')
  28. status_code = details_doc.find('./status/statuscode')
  29. if status_code is not None and status_code.text != 'ok':
  30. code = status_code.text
  31. if code == 'notVisibleAnymore':
  32. message = 'Video %s is not available' % video_id
  33. else:
  34. message = '%s returned error: %s' % (self.IE_NAME, code)
  35. raise ExtractorError(message, expected=True)
  36. thumbnail_els = details_doc.findall('.//teaserimage')
  37. thumbnails = [{
  38. 'width': int(te.attrib['key'].partition('x')[0]),
  39. 'height': int(te.attrib['key'].partition('x')[2]),
  40. 'url': te.text,
  41. } for te in thumbnail_els]
  42. information_el = details_doc.find('.//information')
  43. video_title = information_el.find('./title').text
  44. video_description = information_el.find('./detail').text
  45. details_el = details_doc.find('.//details')
  46. video_uploader = details_el.find('./channel').text
  47. upload_date = unified_strdate(details_el.find('./airtime').text)
  48. format_els = details_doc.findall('.//formitaet')
  49. formats = [{
  50. 'format_id': fe.attrib['basetype'],
  51. 'width': int(fe.find('./width').text),
  52. 'height': int(fe.find('./height').text),
  53. 'url': fe.find('./url').text,
  54. 'filesize': int(fe.find('./filesize').text),
  55. 'video_bitrate': int(fe.find('./videoBitrate').text),
  56. } for fe in format_els
  57. if not fe.find('./url').text.startswith('http://www.metafilegenerator.de/')]
  58. self._sort_formats(formats)
  59. return {
  60. '_type': 'video',
  61. 'id': video_id,
  62. 'title': video_title,
  63. 'formats': formats,
  64. 'description': video_description,
  65. 'thumbnails': thumbnails,
  66. 'thumbnail': thumbnails[-1]['url'],
  67. 'uploader': video_uploader,
  68. 'upload_date': upload_date,
  69. }