logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

swrmediathek.py (4375B)


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