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.

87 lines
3.2 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|mediathek\.php)?\?(?:(?:mode|display)=[^&]+&)*obj=(?P<id>[0-9]+)$'
  11. _TESTS = [
  12. {
  13. 'url': 'http://www.3sat.de/mediathek/index.php?mode=play&obj=45918',
  14. 'md5': 'be37228896d30a88f315b638900a026e',
  15. 'info_dict': {
  16. 'id': '45918',
  17. 'ext': 'mp4',
  18. 'title': 'Waidmannsheil',
  19. 'description': 'md5:cce00ca1d70e21425e72c86a98a56817',
  20. 'uploader': '3sat',
  21. 'upload_date': '20140913'
  22. }
  23. },
  24. {
  25. 'url': 'http://www.3sat.de/mediathek/mediathek.php?mode=play&obj=51066',
  26. 'only_matching': True,
  27. },
  28. ]
  29. def _real_extract(self, url):
  30. mobj = re.match(self._VALID_URL, url)
  31. video_id = mobj.group('id')
  32. details_url = 'http://www.3sat.de/mediathek/xmlservice/web/beitragsDetails?ak=web&id=%s' % video_id
  33. details_doc = self._download_xml(details_url, video_id, 'Downloading video details')
  34. status_code = details_doc.find('./status/statuscode')
  35. if status_code is not None and status_code.text != 'ok':
  36. code = status_code.text
  37. if code == 'notVisibleAnymore':
  38. message = 'Video %s is not available' % video_id
  39. else:
  40. message = '%s returned error: %s' % (self.IE_NAME, code)
  41. raise ExtractorError(message, expected=True)
  42. thumbnail_els = details_doc.findall('.//teaserimage')
  43. thumbnails = [{
  44. 'width': int(te.attrib['key'].partition('x')[0]),
  45. 'height': int(te.attrib['key'].partition('x')[2]),
  46. 'url': te.text,
  47. } for te in thumbnail_els]
  48. information_el = details_doc.find('.//information')
  49. video_title = information_el.find('./title').text
  50. video_description = information_el.find('./detail').text
  51. details_el = details_doc.find('.//details')
  52. video_uploader = details_el.find('./channel').text
  53. upload_date = unified_strdate(details_el.find('./airtime').text)
  54. format_els = details_doc.findall('.//formitaet')
  55. formats = [{
  56. 'format_id': fe.attrib['basetype'],
  57. 'width': int(fe.find('./width').text),
  58. 'height': int(fe.find('./height').text),
  59. 'url': fe.find('./url').text,
  60. 'filesize': int(fe.find('./filesize').text),
  61. 'video_bitrate': int(fe.find('./videoBitrate').text),
  62. } for fe in format_els
  63. if not fe.find('./url').text.startswith('http://www.metafilegenerator.de/')]
  64. self._sort_formats(formats)
  65. return {
  66. '_type': 'video',
  67. 'id': video_id,
  68. 'title': video_title,
  69. 'formats': formats,
  70. 'description': video_description,
  71. 'thumbnails': thumbnails,
  72. 'thumbnail': thumbnails[-1]['url'],
  73. 'uploader': video_uploader,
  74. 'upload_date': upload_date,
  75. }