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.

100 lines
3.5 KiB

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