ndr.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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/info/audio51535.html',
  25. 'md5': 'bb3cd38e24fbcc866d13b50ca59307b8',
  26. 'note': 'Audio file',
  27. 'info_dict': {
  28. 'id': '51535',
  29. 'ext': 'mp3',
  30. 'title': 'La Valette entgeht der Hinrichtung',
  31. 'description': 'md5:22f9541913a40fe50091d5cdd7c9f536',
  32. 'duration': 884,
  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. thumbnails = re.findall(r'''\d+: {src: "([^"]+)"(?: \|\| '[^']+')?, quality: '([^']+)'}''', page)
  57. if thumbnails:
  58. QUALITIES = ['xs', 's', 'm', 'l', 'xl']
  59. thumbnails.sort(key=lambda thumb: QUALITIES.index(thumb[1]))
  60. thumbnail = 'http://www.ndr.de' + thumbnails[-1][0]
  61. for format_id in ['lo', 'hi', 'hq']:
  62. formats.append({
  63. 'url': '%s.%s.mp4' % (video_url.group('video'), format_id),
  64. 'format_id': format_id,
  65. })
  66. if not formats:
  67. raise ExtractorError('No media links available for %s' % video_id)
  68. return {
  69. 'id': video_id,
  70. 'title': title,
  71. 'description': description,
  72. 'thumbnail': thumbnail,
  73. 'duration': duration,
  74. 'formats': formats,
  75. }