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.

136 lines
5.0 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import json
  4. import re
  5. import time
  6. from .common import InfoExtractor
  7. from ..utils import int_or_none
  8. class DPlayIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?P<domain>it\.dplay\.com|www\.dplay\.(?:dk|se|no))/[^/]+/(?P<id>[^/?#]+)'
  10. _TESTS = [{
  11. 'url': 'http://it.dplay.com/take-me-out/stagione-1-episodio-25/',
  12. 'info_dict': {
  13. 'id': '1255600',
  14. 'display_id': 'stagione-1-episodio-25',
  15. 'ext': 'mp4',
  16. 'title': 'Episodio 25',
  17. 'description': 'md5:cae5f40ad988811b197d2d27a53227eb',
  18. 'duration': 2761,
  19. 'timestamp': 1454701800,
  20. 'upload_date': '20160205',
  21. 'creator': 'RTIT',
  22. 'series': 'Take me out',
  23. 'season_number': 1,
  24. 'episode_number': 25,
  25. 'age_limit': 0,
  26. },
  27. 'expected_warnings': ['Unable to download f4m manifest'],
  28. }, {
  29. 'url': 'http://www.dplay.se/nugammalt-77-handelser-som-format-sverige/season-1-svensken-lar-sig-njuta-av-livet/',
  30. 'info_dict': {
  31. 'id': '3172',
  32. 'display_id': 'season-1-svensken-lar-sig-njuta-av-livet',
  33. 'ext': 'flv',
  34. 'title': 'Svensken lär sig njuta av livet',
  35. 'description': 'md5:d3819c9bccffd0fe458ca42451dd50d8',
  36. 'duration': 2650,
  37. 'timestamp': 1365454320,
  38. 'upload_date': '20130408',
  39. 'creator': 'Kanal 5 (Home)',
  40. 'series': 'Nugammalt - 77 händelser som format Sverige',
  41. 'season_number': 1,
  42. 'episode_number': 1,
  43. 'age_limit': 0,
  44. },
  45. }, {
  46. 'url': 'http://www.dplay.dk/mig-og-min-mor/season-6-episode-12/',
  47. 'info_dict': {
  48. 'id': '70816',
  49. 'display_id': 'season-6-episode-12',
  50. 'ext': 'flv',
  51. 'title': 'Episode 12',
  52. 'description': 'md5:9c86e51a93f8a4401fc9641ef9894c90',
  53. 'duration': 2563,
  54. 'timestamp': 1429696800,
  55. 'upload_date': '20150422',
  56. 'creator': 'Kanal 4',
  57. 'series': 'Mig og min mor',
  58. 'season_number': 6,
  59. 'episode_number': 12,
  60. 'age_limit': 0,
  61. },
  62. }, {
  63. 'url': 'http://www.dplay.no/pga-tour/season-1-hoydepunkter-18-21-februar/',
  64. 'only_matching': True,
  65. }]
  66. def _real_extract(self, url):
  67. mobj = re.match(self._VALID_URL, url)
  68. display_id = mobj.group('id')
  69. domain = mobj.group('domain')
  70. webpage = self._download_webpage(url, display_id)
  71. video_id = self._search_regex(
  72. r'data-video-id=["\'](\d+)', webpage, 'video id')
  73. info = self._download_json(
  74. 'http://%s/api/v2/ajax/videos?video_id=%s' % (domain, video_id),
  75. video_id)['data'][0]
  76. title = info['title']
  77. PROTOCOLS = ('hls', 'hds')
  78. formats = []
  79. def extract_formats(protocol, manifest_url):
  80. if protocol == 'hls':
  81. formats.extend(self._extract_m3u8_formats(
  82. manifest_url, video_id, ext='mp4',
  83. entry_protocol='m3u8_native', m3u8_id=protocol, fatal=False))
  84. elif protocol == 'hds':
  85. formats.extend(self._extract_f4m_formats(
  86. manifest_url + '&hdcore=3.8.0&plugin=flowplayer-3.8.0.0',
  87. video_id, f4m_id=protocol, fatal=False))
  88. domain_tld = domain.split('.')[-1]
  89. if domain_tld in ('se', 'dk'):
  90. for protocol in PROTOCOLS:
  91. self._set_cookie(
  92. 'secure.dplay.%s' % domain_tld, 'dsc-geo',
  93. json.dumps({
  94. 'countryCode': domain_tld.upper(),
  95. 'expiry': (time.time() + 20 * 60) * 1000,
  96. }))
  97. stream = self._download_json(
  98. 'https://secure.dplay.%s/secure/api/v2/user/authorization/stream/%s?stream_type=%s'
  99. % (domain_tld, video_id, protocol), video_id,
  100. 'Downloading %s stream JSON' % protocol, fatal=False)
  101. if stream and stream.get(protocol):
  102. extract_formats(protocol, stream[protocol])
  103. else:
  104. for protocol in PROTOCOLS:
  105. if info.get(protocol):
  106. extract_formats(protocol, info[protocol])
  107. self._sort_formats(formats)
  108. return {
  109. 'id': video_id,
  110. 'display_id': display_id,
  111. 'title': title,
  112. 'description': info.get('video_metadata_longDescription'),
  113. 'duration': int_or_none(info.get('video_metadata_length'), scale=1000),
  114. 'timestamp': int_or_none(info.get('video_publish_date')),
  115. 'creator': info.get('video_metadata_homeChannel'),
  116. 'series': info.get('video_metadata_show'),
  117. 'season_number': int_or_none(info.get('season')),
  118. 'episode_number': int_or_none(info.get('episode')),
  119. 'age_limit': int_or_none(info.get('minimum_age')),
  120. 'formats': formats,
  121. }