swrmediathek.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. parse_duration,
  4. int_or_none,
  5. determine_protocol,
  6. )
  7. class SWRMediathekIE(InfoExtractor):
  8. _VALID_URL = r'https?://(?:www\.)?swrmediathek\.de/(?:content/)?player\.htm\?show=(?P<id>[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})'
  9. _TESTS = [{
  10. 'url': 'http://swrmediathek.de/player.htm?show=849790d0-dab8-11e3-a953-0026b975f2e6',
  11. 'md5': '8c5f6f0172753368547ca8413a7768ac',
  12. 'info_dict': {
  13. 'id': '849790d0-dab8-11e3-a953-0026b975f2e6',
  14. 'ext': 'mp4',
  15. 'title': 'SWR odysso',
  16. 'description': 'md5:2012e31baad36162e97ce9eb3f157b8a',
  17. 'thumbnail': r're:^http:.*\.jpg$',
  18. 'duration': 2602,
  19. 'upload_date': '20140515',
  20. 'uploader': 'SWR Fernsehen',
  21. 'uploader_id': '990030',
  22. },
  23. }, {
  24. 'url': 'http://swrmediathek.de/player.htm?show=0e1a8510-ddf2-11e3-9be3-0026b975f2e6',
  25. 'md5': 'b10ab854f912eecc5a6b55cd6fc1f545',
  26. 'info_dict': {
  27. 'id': '0e1a8510-ddf2-11e3-9be3-0026b975f2e6',
  28. 'ext': 'mp4',
  29. 'title': 'Nachtcafé - Alltagsdroge Alkohol - zwischen Sektempfang und Komasaufen',
  30. 'description': 'md5:e0a3adc17e47db2c23aab9ebc36dbee2',
  31. 'thumbnail': r're:http://.*\.jpg',
  32. 'duration': 5305,
  33. 'upload_date': '20140516',
  34. 'uploader': 'SWR Fernsehen',
  35. 'uploader_id': '990030',
  36. },
  37. 'skip': 'redirect to http://swrmediathek.de/index.htm?hinweis=swrlink',
  38. }, {
  39. 'url': 'http://swrmediathek.de/player.htm?show=bba23e10-cb93-11e3-bf7f-0026b975f2e6',
  40. 'md5': '4382e4ef2c9d7ce6852535fa867a0dd3',
  41. 'info_dict': {
  42. 'id': 'bba23e10-cb93-11e3-bf7f-0026b975f2e6',
  43. 'ext': 'mp3',
  44. 'title': 'Saša Stanišic: Vor dem Fest',
  45. 'description': 'md5:5b792387dc3fbb171eb709060654e8c9',
  46. 'thumbnail': r're:http://.*\.jpg',
  47. 'duration': 3366,
  48. 'upload_date': '20140520',
  49. 'uploader': 'SWR 2',
  50. 'uploader_id': '284670',
  51. },
  52. 'skip': 'redirect to http://swrmediathek.de/index.htm?hinweis=swrlink',
  53. }]
  54. def _real_extract(self, url):
  55. video_id = self._match_id(url)
  56. video = self._download_json(
  57. 'http://swrmediathek.de/AjaxEntry?ekey=%s' % video_id,
  58. video_id, 'Downloading video JSON')
  59. attr = video['attr']
  60. title = attr['entry_title']
  61. media_type = attr.get('entry_etype')
  62. formats = []
  63. for entry in video.get('sub', []):
  64. if entry.get('name') != 'entry_media':
  65. continue
  66. entry_attr = entry.get('attr', {})
  67. f_url = entry_attr.get('val2')
  68. if not f_url:
  69. continue
  70. codec = entry_attr.get('val0')
  71. if codec == 'm3u8':
  72. formats.extend(self._extract_m3u8_formats(
  73. f_url, video_id, 'mp4', 'm3u8_native',
  74. m3u8_id='hls', fatal=False))
  75. elif codec == 'f4m':
  76. formats.extend(self._extract_f4m_formats(
  77. f_url + '?hdcore=3.7.0', video_id,
  78. f4m_id='hds', fatal=False))
  79. else:
  80. formats.append({
  81. 'format_id': determine_protocol({'url': f_url}),
  82. 'url': f_url,
  83. 'quality': int_or_none(entry_attr.get('val1')),
  84. 'vcodec': codec if media_type == 'Video' else 'none',
  85. 'acodec': codec if media_type == 'Audio' else None,
  86. })
  87. upload_date = None
  88. entry_pdatet = attr.get('entry_pdatet')
  89. if entry_pdatet:
  90. upload_date = entry_pdatet[:-4]
  91. return {
  92. 'id': video_id,
  93. 'title': title,
  94. 'description': attr.get('entry_descl'),
  95. 'thumbnail': attr.get('entry_image_16_9'),
  96. 'duration': parse_duration(attr.get('entry_durat')),
  97. 'upload_date': upload_date,
  98. 'uploader': attr.get('channel_title'),
  99. 'uploader_id': attr.get('channel_idkey'),
  100. 'formats': formats,
  101. }