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.

94 lines
3.0 KiB

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