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.

88 lines
3.0 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'http://(?: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. for link in asset['Links']:
  40. target = link['Target']
  41. uri = link['Uri']
  42. formats.append({
  43. 'url': uri + '?hdcore=3.3.0&plugin=aasp-3.3.0.99.43' if target == 'HDS' else uri,
  44. 'format_id': target,
  45. 'ext': link['FileFormat'],
  46. 'preference': -1 if target == 'HDS' else -2,
  47. })
  48. subtitles_list = asset.get('SubtitlesList')
  49. if isinstance(subtitles_list, list):
  50. LANGS = {
  51. 'Danish': 'dk',
  52. }
  53. for subs in subtitles_list:
  54. lang = subs['Language']
  55. subtitles[LANGS.get(lang, lang)] = subs['Uri']
  56. if not formats and restricted_to_denmark:
  57. raise ExtractorError(
  58. 'Unfortunately, DR is not allowed to show this program outside Denmark.', expected=True)
  59. self._sort_formats(formats)
  60. if self._downloader.params.get('listsubtitles', False):
  61. self._list_available_subtitles(video_id, subtitles)
  62. return
  63. return {
  64. 'id': video_id,
  65. 'title': title,
  66. 'description': description,
  67. 'thumbnail': thumbnail,
  68. 'timestamp': timestamp,
  69. 'duration': duration,
  70. 'formats': formats,
  71. 'subtitles': self.extract_subtitles(video_id, subtitles),
  72. }