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.

117 lines
4.1 KiB

  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import parse_duration
  6. class SWRMediathekIE(InfoExtractor):
  7. _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})'
  8. _TESTS = [{
  9. 'url': 'http://swrmediathek.de/player.htm?show=849790d0-dab8-11e3-a953-0026b975f2e6',
  10. 'md5': '8c5f6f0172753368547ca8413a7768ac',
  11. 'info_dict': {
  12. 'id': '849790d0-dab8-11e3-a953-0026b975f2e6',
  13. 'ext': 'mp4',
  14. 'title': 'SWR odysso',
  15. 'description': 'md5:2012e31baad36162e97ce9eb3f157b8a',
  16. 'thumbnail': 're:^http:.*\.jpg$',
  17. 'duration': 2602,
  18. 'upload_date': '20140515',
  19. 'uploader': 'SWR Fernsehen',
  20. 'uploader_id': '990030',
  21. },
  22. }, {
  23. 'url': 'http://swrmediathek.de/player.htm?show=0e1a8510-ddf2-11e3-9be3-0026b975f2e6',
  24. 'md5': 'b10ab854f912eecc5a6b55cd6fc1f545',
  25. 'info_dict': {
  26. 'id': '0e1a8510-ddf2-11e3-9be3-0026b975f2e6',
  27. 'ext': 'mp4',
  28. 'title': 'Nachtcafé - Alltagsdroge Alkohol - zwischen Sektempfang und Komasaufen',
  29. 'description': 'md5:e0a3adc17e47db2c23aab9ebc36dbee2',
  30. 'thumbnail': 're:http://.*\.jpg',
  31. 'duration': 5305,
  32. 'upload_date': '20140516',
  33. 'uploader': 'SWR Fernsehen',
  34. 'uploader_id': '990030',
  35. },
  36. }, {
  37. 'url': 'http://swrmediathek.de/player.htm?show=bba23e10-cb93-11e3-bf7f-0026b975f2e6',
  38. 'md5': '4382e4ef2c9d7ce6852535fa867a0dd3',
  39. 'info_dict': {
  40. 'id': 'bba23e10-cb93-11e3-bf7f-0026b975f2e6',
  41. 'ext': 'mp3',
  42. 'title': 'Saša Stanišic: Vor dem Fest',
  43. 'description': 'md5:5b792387dc3fbb171eb709060654e8c9',
  44. 'thumbnail': 're:http://.*\.jpg',
  45. 'duration': 3366,
  46. 'upload_date': '20140520',
  47. 'uploader': 'SWR 2',
  48. 'uploader_id': '284670',
  49. }
  50. }, {
  51. 'url': 'http://swrmediathek.de/content/player.htm?show=52dc7e00-15c5-11e4-84bc-0026b975f2e6',
  52. 'md5': '881531487d0633080a8cc88d31ef896f',
  53. 'info_dict': {
  54. 'id': '52dc7e00-15c5-11e4-84bc-0026b975f2e6',
  55. 'ext': 'mp4',
  56. 'title': 'Familienspaß am Bodensee',
  57. 'description': 'md5:0b591225a32cfde7be1629ed49fe4315',
  58. 'thumbnail': 're:http://.*\.jpg',
  59. 'duration': 1784,
  60. 'upload_date': '20140727',
  61. 'uploader': 'SWR Fernsehen BW',
  62. 'uploader_id': '281130',
  63. }
  64. }]
  65. def _real_extract(self, url):
  66. mobj = re.match(self._VALID_URL, url)
  67. video_id = mobj.group('id')
  68. video = self._download_json(
  69. 'http://swrmediathek.de/AjaxEntry?ekey=%s' % video_id, video_id, 'Downloading video JSON')
  70. attr = video['attr']
  71. media_type = attr['entry_etype']
  72. formats = []
  73. for entry in video['sub']:
  74. if entry['name'] != 'entry_media':
  75. continue
  76. entry_attr = entry['attr']
  77. codec = entry_attr['val0']
  78. quality = int(entry_attr['val1'])
  79. fmt = {
  80. 'url': entry_attr['val2'],
  81. 'quality': quality,
  82. }
  83. if media_type == 'Video':
  84. fmt.update({
  85. 'format_note': ['144p', '288p', '544p'][quality-1],
  86. 'vcodec': codec,
  87. })
  88. elif media_type == 'Audio':
  89. fmt.update({
  90. 'acodec': codec,
  91. })
  92. formats.append(fmt)
  93. self._sort_formats(formats)
  94. return {
  95. 'id': video_id,
  96. 'title': attr['entry_title'],
  97. 'description': attr['entry_descl'],
  98. 'thumbnail': attr['entry_image_16_9'],
  99. 'duration': parse_duration(attr['entry_durat']),
  100. 'upload_date': attr['entry_pdatet'][:-4],
  101. 'uploader': attr['channel_title'],
  102. 'uploader_id': attr['channel_idkey'],
  103. 'formats': formats,
  104. }