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.

94 lines
3.3 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. programcard = self._download_json(
  23. 'http://www.dr.dk/mu/programcard/expanded/%s' % video_id, video_id, 'Downloading video JSON')
  24. data = programcard['Data'][0]
  25. title = data['Title']
  26. description = data['Description']
  27. timestamp = parse_iso8601(data['CreatedTime'])
  28. thumbnail = None
  29. duration = None
  30. restricted_to_denmark = False
  31. formats = []
  32. subtitles = {}
  33. for asset in data['Assets']:
  34. if asset['Kind'] == 'Image':
  35. thumbnail = asset['Uri']
  36. elif asset['Kind'] == 'VideoResource':
  37. duration = asset['DurationInMilliseconds'] / 1000.0
  38. restricted_to_denmark = asset['RestrictedToDenmark']
  39. spoken_subtitles = asset['Target'] == 'SpokenSubtitles'
  40. for link in asset['Links']:
  41. target = link['Target']
  42. uri = link['Uri']
  43. format_id = target
  44. preference = -1 if target == 'HDS' else -2
  45. if spoken_subtitles:
  46. preference -= 2
  47. format_id += '-spoken-subtitles'
  48. formats.append({
  49. 'url': uri + '?hdcore=3.3.0&plugin=aasp-3.3.0.99.43' if target == 'HDS' else uri,
  50. 'format_id': format_id,
  51. 'ext': link['FileFormat'],
  52. 'preference': preference,
  53. })
  54. subtitles_list = asset.get('SubtitlesList')
  55. if isinstance(subtitles_list, list):
  56. LANGS = {
  57. 'Danish': 'dk',
  58. }
  59. for subs in subtitles_list:
  60. lang = subs['Language']
  61. subtitles[LANGS.get(lang, lang)] = subs['Uri']
  62. if not formats and restricted_to_denmark:
  63. raise ExtractorError(
  64. 'Unfortunately, DR is not allowed to show this program outside Denmark.', expected=True)
  65. self._sort_formats(formats)
  66. if self._downloader.params.get('listsubtitles', False):
  67. self._list_available_subtitles(video_id, subtitles)
  68. return
  69. return {
  70. 'id': video_id,
  71. 'title': title,
  72. 'description': description,
  73. 'thumbnail': thumbnail,
  74. 'timestamp': timestamp,
  75. 'duration': duration,
  76. 'formats': formats,
  77. 'subtitles': self.extract_subtitles(video_id, subtitles),
  78. }