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.

88 lines
2.9 KiB

  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import ExtractorError
  6. class NDRIE(InfoExtractor):
  7. IE_NAME = 'ndr'
  8. IE_DESC = 'NDR.de - Mediathek'
  9. _VALID_URL = r'https?://www\.ndr\.de/.+?(?P<id>\d+)\.html'
  10. _TESTS = [
  11. {
  12. 'url': 'http://www.ndr.de/fernsehen/sendungen/markt/markt7959.html',
  13. 'md5': 'e7a6079ca39d3568f4996cb858dd6708',
  14. 'note': 'Video file',
  15. 'info_dict': {
  16. 'id': '7959',
  17. 'ext': 'mp4',
  18. 'title': 'Markt - die ganze Sendung',
  19. 'description': 'md5:af9179cf07f67c5c12dc6d9997e05725',
  20. 'duration': 2655,
  21. },
  22. },
  23. {
  24. 'url': 'http://www.ndr.de/903/audio191719.html',
  25. 'md5': '41ed601768534dd18a9ae34d84798129',
  26. 'note': 'Audio file',
  27. 'info_dict': {
  28. 'id': '191719',
  29. 'ext': 'mp3',
  30. 'title': '"Es war schockierend"',
  31. 'description': 'md5:ed7ff8364793545021a6355b97e95f10',
  32. 'duration': 112,
  33. }
  34. }
  35. ]
  36. def _real_extract(self, url):
  37. mobj = re.match(self._VALID_URL, url)
  38. video_id = mobj.group('id')
  39. page = self._download_webpage(url, video_id, 'Downloading page')
  40. title = self._og_search_title(page)
  41. description = self._og_search_description(page)
  42. mobj = re.search(
  43. r'<div class="duration"><span class="min">(?P<minutes>\d+)</span>:<span class="sec">(?P<seconds>\d+)</span></div>',
  44. page)
  45. duration = int(mobj.group('minutes')) * 60 + int(mobj.group('seconds')) if mobj else None
  46. formats = []
  47. mp3_url = re.search(r'''{src:'(?P<audio>[^']+)', type:"audio/mp3"},''', page)
  48. if mp3_url:
  49. formats.append({
  50. 'url': mp3_url.group('audio'),
  51. 'format_id': 'mp3',
  52. })
  53. thumbnail = None
  54. video_url = re.search(r'''3: {src:'(?P<video>.+?)\.hi\.mp4', type:"video/mp4"},''', page)
  55. if video_url:
  56. thumbnail = self._html_search_regex(r'(?m)title: "NDR PLAYER",\s*poster: "([^"]+)",',
  57. page, 'thumbnail', fatal=False)
  58. if thumbnail:
  59. thumbnail = 'http://www.ndr.de' + thumbnail
  60. for format_id in ['lo', 'hi', 'hq']:
  61. formats.append({
  62. 'url': '%s.%s.mp4' % (video_url.group('video'), format_id),
  63. 'format_id': format_id,
  64. })
  65. if not formats:
  66. raise ExtractorError('No media links available for %s' % video_id)
  67. return {
  68. 'id': video_id,
  69. 'title': title,
  70. 'description': description,
  71. 'thumbnail': thumbnail,
  72. 'duration': duration,
  73. 'formats': formats,
  74. }