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.

103 lines
3.6 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/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. def _real_extract(self, url):
  52. mobj = re.match(self._VALID_URL, url)
  53. video_id = mobj.group('id')
  54. video = self._download_json(
  55. 'http://swrmediathek.de/AjaxEntry?ekey=%s' % video_id, video_id, 'Downloading video JSON')
  56. attr = video['attr']
  57. media_type = attr['entry_etype']
  58. formats = []
  59. for entry in video['sub']:
  60. if entry['name'] != 'entry_media':
  61. continue
  62. entry_attr = entry['attr']
  63. codec = entry_attr['val0']
  64. quality = int(entry_attr['val1'])
  65. fmt = {
  66. 'url': entry_attr['val2'],
  67. 'quality': quality,
  68. }
  69. if media_type == 'Video':
  70. fmt.update({
  71. 'format_note': ['144p', '288p', '544p'][quality-1],
  72. 'vcodec': codec,
  73. })
  74. elif media_type == 'Audio':
  75. fmt.update({
  76. 'acodec': codec,
  77. })
  78. formats.append(fmt)
  79. self._sort_formats(formats)
  80. return {
  81. 'id': video_id,
  82. 'title': attr['entry_title'],
  83. 'description': attr['entry_descl'],
  84. 'thumbnail': attr['entry_image_16_9'],
  85. 'duration': parse_duration(attr['entry_durat']),
  86. 'upload_date': attr['entry_pdatet'][:-4],
  87. 'uploader': attr['channel_title'],
  88. 'uploader_id': attr['channel_idkey'],
  89. 'formats': formats,
  90. }