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