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.

92 lines
3.0 KiB

  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. int_or_none,
  8. )
  9. class NDRIE(InfoExtractor):
  10. IE_NAME = 'ndr'
  11. IE_DESC = 'NDR.de - Mediathek'
  12. _VALID_URL = r'https?://www\.ndr\.de/.+?(?P<id>\d+)\.html'
  13. _TESTS = [
  14. {
  15. 'url': 'http://www.ndr.de/fernsehen/sendungen/markt/markt7959.html',
  16. 'md5': 'e7a6079ca39d3568f4996cb858dd6708',
  17. 'note': 'Video file',
  18. 'info_dict': {
  19. 'id': '7959',
  20. 'ext': 'mp4',
  21. 'title': 'Markt - die ganze Sendung',
  22. 'description': 'md5:af9179cf07f67c5c12dc6d9997e05725',
  23. 'duration': 2655,
  24. },
  25. },
  26. {
  27. 'url': 'http://www.ndr.de/info/audio51535.html',
  28. 'md5': 'bb3cd38e24fbcc866d13b50ca59307b8',
  29. 'note': 'Audio file',
  30. 'info_dict': {
  31. 'id': '51535',
  32. 'ext': 'mp3',
  33. 'title': 'La Valette entgeht der Hinrichtung',
  34. 'description': 'md5:22f9541913a40fe50091d5cdd7c9f536',
  35. 'duration': 884,
  36. }
  37. }
  38. ]
  39. def _real_extract(self, url):
  40. mobj = re.match(self._VALID_URL, url)
  41. video_id = mobj.group('id')
  42. page = self._download_webpage(url, video_id, 'Downloading page')
  43. title = self._og_search_title(page).strip()
  44. description = self._og_search_description(page)
  45. if description:
  46. description = description.strip()
  47. duration = int_or_none(self._html_search_regex(r'duration: (\d+),\n', page, 'duration', fatal=False))
  48. formats = []
  49. mp3_url = re.search(r'''{src:'(?P<audio>[^']+)', type:"audio/mp3"},''', page)
  50. if mp3_url:
  51. formats.append({
  52. 'url': mp3_url.group('audio'),
  53. 'format_id': 'mp3',
  54. })
  55. thumbnail = None
  56. video_url = re.search(r'''3: {src:'(?P<video>.+?)\.hi\.mp4', type:"video/mp4"},''', page)
  57. if video_url:
  58. thumbnails = re.findall(r'''\d+: {src: "([^"]+)"(?: \|\| '[^']+')?, quality: '([^']+)'}''', page)
  59. if thumbnails:
  60. QUALITIES = ['xs', 's', 'm', 'l', 'xl']
  61. thumbnails.sort(key=lambda thumb: QUALITIES.index(thumb[1]) if thumb[1] in QUALITIES else -1)
  62. thumbnail = 'http://www.ndr.de' + thumbnails[-1][0]
  63. for format_id in ['lo', 'hi', 'hq']:
  64. formats.append({
  65. 'url': '%s.%s.mp4' % (video_url.group('video'), format_id),
  66. 'format_id': format_id,
  67. })
  68. if not formats:
  69. raise ExtractorError('No media links available for %s' % video_id)
  70. return {
  71. 'id': video_id,
  72. 'title': title,
  73. 'description': description,
  74. 'thumbnail': thumbnail,
  75. 'duration': duration,
  76. 'formats': formats,
  77. }