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.

115 lines
4.1 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. parse_iso8601,
  7. )
  8. class DRTVIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:www\.)?dr\.dk/tv/se/(?:[^/]+/)*(?P<id>[\da-z-]+)(?:[/#?]|$)'
  10. _TEST = {
  11. 'url': 'https://www.dr.dk/tv/se/boern/ultra/panisk-paske/panisk-paske-5',
  12. 'md5': 'dc515a9ab50577fa14cc4e4b0265168f',
  13. 'info_dict': {
  14. 'id': 'panisk-paske-5',
  15. 'ext': 'mp4',
  16. 'title': 'Panisk Påske (5)',
  17. 'description': 'md5:ca14173c5ab24cd26b0fcc074dff391c',
  18. 'timestamp': 1426984612,
  19. 'upload_date': '20150322',
  20. 'duration': 1455,
  21. },
  22. }
  23. def _real_extract(self, url):
  24. video_id = self._match_id(url)
  25. webpage = self._download_webpage(url, video_id)
  26. if '>Programmet er ikke længere tilgængeligt' in webpage:
  27. raise ExtractorError(
  28. 'Video %s is not available' % video_id, expected=True)
  29. video_id = self._search_regex(
  30. r'data-(?:material-identifier|episode-slug)="([^"]+)"',
  31. webpage, 'video id')
  32. programcard = self._download_json(
  33. 'http://www.dr.dk/mu/programcard/expanded/%s' % video_id,
  34. video_id, 'Downloading video JSON')
  35. data = programcard['Data'][0]
  36. title = data['Title']
  37. description = data['Description']
  38. timestamp = parse_iso8601(data['CreatedTime'])
  39. thumbnail = None
  40. duration = None
  41. restricted_to_denmark = False
  42. formats = []
  43. subtitles = {}
  44. for asset in data['Assets']:
  45. if asset['Kind'] == 'Image':
  46. thumbnail = asset['Uri']
  47. elif asset['Kind'] == 'VideoResource':
  48. duration = asset['DurationInMilliseconds'] / 1000.0
  49. restricted_to_denmark = asset['RestrictedToDenmark']
  50. spoken_subtitles = asset['Target'] == 'SpokenSubtitles'
  51. for link in asset['Links']:
  52. uri = link['Uri']
  53. target = link['Target']
  54. format_id = target
  55. preference = None
  56. if spoken_subtitles:
  57. preference = -1
  58. format_id += '-spoken-subtitles'
  59. if target == 'HDS':
  60. formats.extend(self._extract_f4m_formats(
  61. uri + '?hdcore=3.3.0&plugin=aasp-3.3.0.99.43',
  62. video_id, preference, f4m_id=format_id))
  63. elif target == 'HLS':
  64. formats.extend(self._extract_m3u8_formats(
  65. uri, video_id, 'mp4', preference=preference,
  66. m3u8_id=format_id))
  67. else:
  68. bitrate = link.get('Bitrate')
  69. if bitrate:
  70. format_id += '-%s' % bitrate
  71. formats.append({
  72. 'url': uri,
  73. 'format_id': format_id,
  74. 'tbr': bitrate,
  75. 'ext': link.get('FileFormat'),
  76. })
  77. subtitles_list = asset.get('SubtitlesList')
  78. if isinstance(subtitles_list, list):
  79. LANGS = {
  80. 'Danish': 'dk',
  81. }
  82. for subs in subtitles_list:
  83. lang = subs['Language']
  84. subtitles[LANGS.get(lang, lang)] = [{'url': subs['Uri'], 'ext': 'vtt'}]
  85. if not formats and restricted_to_denmark:
  86. raise ExtractorError(
  87. 'Unfortunately, DR is not allowed to show this program outside Denmark.', expected=True)
  88. self._sort_formats(formats)
  89. return {
  90. 'id': video_id,
  91. 'title': title,
  92. 'description': description,
  93. 'thumbnail': thumbnail,
  94. 'timestamp': timestamp,
  95. 'duration': duration,
  96. 'formats': formats,
  97. 'subtitles': subtitles,
  98. }