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.

91 lines
3.1 KiB

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