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. # video
  12. {
  13. 'url': 'http://www.ndr.de/fernsehen/sendungen/hallo_niedersachsen/media/hallonds19925.html',
  14. 'md5': '20eba151ff165f386643dad9c1da08f7',
  15. 'info_dict': {
  16. 'id': '19925',
  17. 'ext': 'mp4',
  18. 'title': 'Hallo Niedersachsen ',
  19. 'description': 'Bei Hallo Niedersachsen um 19:30 Uhr erfahren Sie alles, was am Tag in Niedersachsen los war.',
  20. 'duration': 1722,
  21. },
  22. },
  23. # audio
  24. {
  25. 'url': 'http://www.ndr.de/903/audio191719.html',
  26. 'md5': '41ed601768534dd18a9ae34d84798129',
  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. }