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.

95 lines
3.3 KiB

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