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.

146 lines
5.5 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. int_or_none,
  7. float_or_none,
  8. mimetype2ext,
  9. parse_iso8601,
  10. remove_end,
  11. )
  12. class DRTVIE(InfoExtractor):
  13. _VALID_URL = r'https?://(?:www\.)?dr\.dk/(?:tv/se|nyheder)/(?:[^/]+/)*(?P<id>[\da-z-]+)(?:[/#?]|$)'
  14. _TESTS = [{
  15. 'url': 'https://www.dr.dk/tv/se/boern/ultra/klassen-ultra/klassen-darlig-taber-10',
  16. 'md5': '25e659cccc9a2ed956110a299fdf5983',
  17. 'info_dict': {
  18. 'id': 'klassen-darlig-taber-10',
  19. 'ext': 'mp4',
  20. 'title': 'Klassen - Dårlig taber (10)',
  21. 'description': 'md5:815fe1b7fa656ed80580f31e8b3c79aa',
  22. 'timestamp': 1471991907,
  23. 'upload_date': '20160823',
  24. 'duration': 606.84,
  25. },
  26. 'params': {
  27. 'skip_download': True,
  28. },
  29. }, {
  30. 'url': 'https://www.dr.dk/nyheder/indland/live-christianias-rydning-af-pusher-street-er-i-gang',
  31. 'md5': '2c37175c718155930f939ef59952474a',
  32. 'info_dict': {
  33. 'id': 'christiania-pusher-street-ryddes-drdkrjpo',
  34. 'ext': 'mp4',
  35. 'title': 'LIVE Christianias rydning af Pusher Street er i gang',
  36. 'description': '- Det er det fedeste, der er sket i 20 år, fortæller christianit til DR Nyheder.',
  37. 'timestamp': 1472800279,
  38. 'upload_date': '20160902',
  39. 'duration': 131.4,
  40. },
  41. }]
  42. def _real_extract(self, url):
  43. video_id = self._match_id(url)
  44. webpage = self._download_webpage(url, video_id)
  45. if '>Programmet er ikke længere tilgængeligt' in webpage:
  46. raise ExtractorError(
  47. 'Video %s is not available' % video_id, expected=True)
  48. video_id = self._search_regex(
  49. (r'data-(?:material-identifier|episode-slug)="([^"]+)"',
  50. r'data-resource="[^>"]+mu/programcard/expanded/([^"]+)"'),
  51. webpage, 'video id')
  52. programcard = self._download_json(
  53. 'http://www.dr.dk/mu/programcard/expanded/%s' % video_id,
  54. video_id, 'Downloading video JSON')
  55. data = programcard['Data'][0]
  56. title = remove_end(self._og_search_title(
  57. webpage, default=None), ' | TV | DR') or data['Title']
  58. description = self._og_search_description(
  59. webpage, default=None) or data.get('Description')
  60. timestamp = parse_iso8601(data.get('CreatedTime'))
  61. thumbnail = None
  62. duration = None
  63. restricted_to_denmark = False
  64. formats = []
  65. subtitles = {}
  66. for asset in data['Assets']:
  67. if asset.get('Kind') == 'Image':
  68. thumbnail = asset.get('Uri')
  69. elif asset.get('Kind') == 'VideoResource':
  70. duration = float_or_none(asset.get('DurationInMilliseconds'), 1000)
  71. restricted_to_denmark = asset.get('RestrictedToDenmark')
  72. spoken_subtitles = asset.get('Target') == 'SpokenSubtitles'
  73. for link in asset.get('Links', []):
  74. uri = link.get('Uri')
  75. if not uri:
  76. continue
  77. target = link.get('Target')
  78. format_id = target or ''
  79. preference = None
  80. if spoken_subtitles:
  81. preference = -1
  82. format_id += '-spoken-subtitles'
  83. if target == 'HDS':
  84. formats.extend(self._extract_f4m_formats(
  85. uri + '?hdcore=3.3.0&plugin=aasp-3.3.0.99.43',
  86. video_id, preference, f4m_id=format_id))
  87. elif target == 'HLS':
  88. formats.extend(self._extract_m3u8_formats(
  89. uri, video_id, 'mp4', entry_protocol='m3u8_native',
  90. preference=preference, m3u8_id=format_id))
  91. else:
  92. bitrate = link.get('Bitrate')
  93. if bitrate:
  94. format_id += '-%s' % bitrate
  95. formats.append({
  96. 'url': uri,
  97. 'format_id': format_id,
  98. 'tbr': int_or_none(bitrate),
  99. 'ext': link.get('FileFormat'),
  100. })
  101. subtitles_list = asset.get('SubtitlesList')
  102. if isinstance(subtitles_list, list):
  103. LANGS = {
  104. 'Danish': 'da',
  105. }
  106. for subs in subtitles_list:
  107. if not subs.get('Uri'):
  108. continue
  109. lang = subs.get('Language') or 'da'
  110. subtitles.setdefault(LANGS.get(lang, lang), []).append({
  111. 'url': subs['Uri'],
  112. 'ext': mimetype2ext(subs.get('MimeType')) or 'vtt'
  113. })
  114. if not formats and restricted_to_denmark:
  115. self.raise_geo_restricted(
  116. 'Unfortunately, DR is not allowed to show this program outside Denmark.',
  117. expected=True)
  118. self._sort_formats(formats)
  119. return {
  120. 'id': video_id,
  121. 'title': title,
  122. 'description': description,
  123. 'thumbnail': thumbnail,
  124. 'timestamp': timestamp,
  125. 'duration': duration,
  126. 'formats': formats,
  127. 'subtitles': subtitles,
  128. }