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.

130 lines
4.5 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. parse_duration,
  10. )
  11. class NDRBaseIE(InfoExtractor):
  12. def _real_extract(self, url):
  13. mobj = re.match(self._VALID_URL, url)
  14. video_id = mobj.group('id')
  15. page = self._download_webpage(url, video_id, 'Downloading page')
  16. title = self._og_search_title(page).strip()
  17. description = self._og_search_description(page)
  18. if description:
  19. description = description.strip()
  20. duration = int_or_none(self._html_search_regex(r'duration: (\d+),\n', page, 'duration', default=None))
  21. if not duration:
  22. duration = parse_duration(self._html_search_regex(
  23. r'(<span class="min">\d+</span>:<span class="sec">\d+</span>)',
  24. page, 'duration', default=None))
  25. formats = []
  26. mp3_url = re.search(r'''\{src:'(?P<audio>[^']+)', type:"audio/mp3"},''', page)
  27. if mp3_url:
  28. formats.append({
  29. 'url': mp3_url.group('audio'),
  30. 'format_id': 'mp3',
  31. })
  32. thumbnail = None
  33. video_url = re.search(r'''3: \{src:'(?P<video>.+?)\.(lo|hi|hq)\.mp4', type:"video/mp4"},''', page)
  34. if video_url:
  35. thumbnails = re.findall(r'''\d+: \{src: "([^"]+)"(?: \|\| '[^']+')?, quality: '([^']+)'}''', page)
  36. if thumbnails:
  37. quality_key = qualities(['xs', 's', 'm', 'l', 'xl'])
  38. largest = max(thumbnails, key=lambda thumb: quality_key(thumb[1]))
  39. thumbnail = 'http://www.ndr.de' + largest[0]
  40. for format_id in 'lo', 'hi', 'hq':
  41. formats.append({
  42. 'url': '%s.%s.mp4' % (video_url.group('video'), format_id),
  43. 'format_id': format_id,
  44. })
  45. if not formats:
  46. raise ExtractorError('No media links available for %s' % video_id)
  47. return {
  48. 'id': video_id,
  49. 'title': title,
  50. 'description': description,
  51. 'thumbnail': thumbnail,
  52. 'duration': duration,
  53. 'formats': formats,
  54. }
  55. class NDRIE(NDRBaseIE):
  56. IE_NAME = 'ndr'
  57. IE_DESC = 'NDR.de - Mediathek'
  58. _VALID_URL = r'https?://www\.ndr\.de/.+?(?P<id>\d+)\.html'
  59. _TESTS = [
  60. {
  61. 'url': 'http://www.ndr.de/fernsehen/sendungen/nordmagazin/Kartoffeltage-in-der-Lewitz,nordmagazin25866.html',
  62. 'md5': '5bc5f5b92c82c0f8b26cddca34f8bb2c',
  63. 'note': 'Video file',
  64. 'info_dict': {
  65. 'id': '25866',
  66. 'ext': 'mp4',
  67. 'title': 'Kartoffeltage in der Lewitz',
  68. 'description': 'md5:48c4c04dde604c8a9971b3d4e3b9eaa8',
  69. 'duration': 166,
  70. },
  71. 'skip': '404 Not found',
  72. },
  73. {
  74. 'url': 'http://www.ndr.de/fernsehen/Party-Poette-und-Parade,hafengeburtstag988.html',
  75. 'md5': 'dadc003c55ae12a5d2f6bd436cd73f59',
  76. 'info_dict': {
  77. 'id': '988',
  78. 'ext': 'mp4',
  79. 'title': 'Party, Pötte und Parade',
  80. 'description': 'Hunderttausende feiern zwischen Speicherstadt und St. Pauli den 826. Hafengeburtstag. Die NDR Sondersendung zeigt die schönsten und spektakulärsten Bilder vom Auftakt.',
  81. 'duration': 3498,
  82. },
  83. },
  84. {
  85. 'url': 'http://www.ndr.de/info/audio51535.html',
  86. 'md5': 'bb3cd38e24fbcc866d13b50ca59307b8',
  87. 'note': 'Audio file',
  88. 'info_dict': {
  89. 'id': '51535',
  90. 'ext': 'mp3',
  91. 'title': 'La Valette entgeht der Hinrichtung',
  92. 'description': 'md5:22f9541913a40fe50091d5cdd7c9f536',
  93. 'duration': 884,
  94. }
  95. }
  96. ]
  97. class NJoyIE(NDRBaseIE):
  98. IE_NAME = 'N-JOY'
  99. _VALID_URL = r'https?://www\.n-joy\.de/.+?(?P<id>\d+)\.html'
  100. _TEST = {
  101. 'url': 'http://www.n-joy.de/entertainment/comedy/comedy_contest/Benaissa-beim-NDR-Comedy-Contest,comedycontest2480.html',
  102. 'md5': 'cb63be60cd6f9dd75218803146d8dc67',
  103. 'info_dict': {
  104. 'id': '2480',
  105. 'ext': 'mp4',
  106. 'title': 'Benaissa beim NDR Comedy Contest',
  107. 'description': 'Von seinem sehr "behaarten" Leben lässt sich Benaissa trotz aller Schwierigkeiten nicht unterkriegen.',
  108. 'duration': 654,
  109. }
  110. }