ndr.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. int_or_none,
  7. )
  8. preferences = {'xl': 4, 'l': 3, 'm': 2, 's': 1, 'xs': 0,}
  9. class NDRBaseIE(InfoExtractor):
  10. def _real_extract(self, url):
  11. video_id = self._match_id(url)
  12. json_data = self._download_json('http://www.ndr.de/%s-ppjson.json' % video_id, video_id, 'Downloading page')
  13. formats = []
  14. objetType = json_data.get('config').get('objectType')
  15. if objetType == 'video':
  16. for key, f in json_data.get('playlist').items():
  17. if key != 'config':
  18. src = f['src']
  19. if '.f4m' in src:
  20. formats.extend(self._extract_f4m_formats(src, video_id))
  21. elif '.m3u8' in src:
  22. formats.extend(self._extract_m3u8_formats(src, video_id))
  23. else:
  24. quality = f.get('quality')
  25. formats.append({
  26. 'url': src,
  27. 'format_id': quality,
  28. 'preference': preferences.get(quality),
  29. })
  30. elif objetType == 'audio':
  31. for key, f in json_data.get('playlist').items():
  32. if key != 'config':
  33. formats.append({
  34. 'url': f['src'],
  35. 'format_id': 'mp3',
  36. })
  37. else:
  38. raise ExtractorError('No media links available for %s' % video_id)
  39. self._sort_formats(formats)
  40. config = json_data.get('playlist').get('config')
  41. title = config['title']
  42. duration = int_or_none(config.get('duration'))
  43. thumbnails = [{
  44. 'id': thumbnail.get('quality'),
  45. 'url': thumbnail.get('src'),
  46. 'preference': preferences.get(thumbnail.get('quality'))
  47. } for thumbnail in config.get('poster').values()]
  48. return {
  49. 'id': video_id,
  50. 'title': title,
  51. 'thumbnails': thumbnails,
  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>\w+)\.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': 'nordmagazin25866',
  66. 'ext': 'mp4',
  67. 'title': 'Kartoffeltage in der Lewitz',
  68. 'duration': 166,
  69. },
  70. 'skip': '404 Not found',
  71. },
  72. {
  73. 'url': 'http://www.ndr.de/fernsehen/Party-Poette-und-Parade,hafengeburtstag988.html',
  74. 'md5': 'dadc003c55ae12a5d2f6bd436cd73f59',
  75. 'info_dict': {
  76. 'id': 'hafengeburtstag988',
  77. 'ext': 'mp4',
  78. 'title': 'Party, Pötte und Parade',
  79. 'duration': 3498,
  80. },
  81. },
  82. {
  83. 'url': 'http://www.ndr.de/info/La-Valette-entgeht-der-Hinrichtung,audio51535.html',
  84. 'md5': 'bb3cd38e24fbcc866d13b50ca59307b8',
  85. 'note': 'Audio file',
  86. 'info_dict': {
  87. 'id': 'audio51535',
  88. 'ext': 'mp3',
  89. 'title': 'La Valette entgeht der Hinrichtung',
  90. 'duration': 884,
  91. }
  92. }
  93. ]
  94. class NJoyIE(NDRBaseIE):
  95. IE_NAME = 'N-JOY'
  96. _VALID_URL = r'https?://www\.n-joy\.de/.+?,(?P<id>\w+)\.html'
  97. _TEST = {
  98. 'url': 'http://www.n-joy.de/entertainment/comedy/comedy_contest/Benaissa-beim-NDR-Comedy-Contest,comedycontest2480.html',
  99. 'md5': 'cb63be60cd6f9dd75218803146d8dc67',
  100. 'info_dict': {
  101. 'id': '2480',
  102. 'ext': 'mp4',
  103. 'title': 'Benaissa beim NDR Comedy Contest',
  104. 'duration': 654,
  105. }
  106. }