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.

163 lines
6.3 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .theplatform import ThePlatformBaseIE
  5. from ..compat import (
  6. compat_parse_qs,
  7. compat_str,
  8. compat_urllib_parse_urlparse,
  9. )
  10. from ..utils import (
  11. ExtractorError,
  12. int_or_none,
  13. update_url_query,
  14. )
  15. class MediasetIE(ThePlatformBaseIE):
  16. _TP_TLD = 'eu'
  17. _VALID_URL = r'''(?x)
  18. (?:
  19. mediaset:|
  20. https?://
  21. (?:(?:www|static3)\.)?mediasetplay\.mediaset\.it/
  22. (?:
  23. (?:video|on-demand)/(?:[^/]+/)+[^/]+_|
  24. player/index\.html\?.*?\bprogramGuid=
  25. )
  26. )(?P<id>[0-9A-Z]{16})
  27. '''
  28. _TESTS = [{
  29. # full episode
  30. 'url': 'https://www.mediasetplay.mediaset.it/video/hellogoodbye/quarta-puntata_FAFU000000661824',
  31. 'md5': '9b75534d42c44ecef7bf1ffeacb7f85d',
  32. 'info_dict': {
  33. 'id': 'FAFU000000661824',
  34. 'ext': 'mp4',
  35. 'title': 'Quarta puntata',
  36. 'description': 'md5:d41d8cd98f00b204e9800998ecf8427e',
  37. 'thumbnail': r're:^https?://.*\.jpg$',
  38. 'duration': 1414.26,
  39. 'upload_date': '20161107',
  40. 'series': 'Hello Goodbye',
  41. 'timestamp': 1478532900,
  42. 'uploader': 'Rete 4',
  43. 'uploader_id': 'R4',
  44. },
  45. }, {
  46. 'url': 'https://www.mediasetplay.mediaset.it/video/matrix/puntata-del-25-maggio_F309013801000501',
  47. 'md5': '288532f0ad18307705b01e581304cd7b',
  48. 'info_dict': {
  49. 'id': 'F309013801000501',
  50. 'ext': 'mp4',
  51. 'title': 'Puntata del 25 maggio',
  52. 'description': 'md5:d41d8cd98f00b204e9800998ecf8427e',
  53. 'thumbnail': r're:^https?://.*\.jpg$',
  54. 'duration': 6565.007,
  55. 'upload_date': '20180526',
  56. 'series': 'Matrix',
  57. 'timestamp': 1527326245,
  58. 'uploader': 'Canale 5',
  59. 'uploader_id': 'C5',
  60. },
  61. 'expected_warnings': ['HTTP Error 403: Forbidden'],
  62. }, {
  63. # clip
  64. 'url': 'https://www.mediasetplay.mediaset.it/video/gogglebox/un-grande-classico-della-commedia-sexy_FAFU000000661680',
  65. 'only_matching': True,
  66. }, {
  67. # iframe simple
  68. 'url': 'https://static3.mediasetplay.mediaset.it/player/index.html?appKey=5ad3966b1de1c4000d5cec48&programGuid=FAFU000000665924&id=665924',
  69. 'only_matching': True,
  70. }, {
  71. # iframe twitter (from http://www.wittytv.it/se-prima-mi-fidavo-zero/)
  72. 'url': 'https://static3.mediasetplay.mediaset.it/player/index.html?appKey=5ad3966b1de1c4000d5cec48&programGuid=FAFU000000665104&id=665104',
  73. 'only_matching': True,
  74. }, {
  75. 'url': 'mediaset:FAFU000000665924',
  76. 'only_matching': True,
  77. }]
  78. @staticmethod
  79. def _extract_urls(ie, webpage):
  80. def _qs(url):
  81. return compat_parse_qs(compat_urllib_parse_urlparse(url).query)
  82. def _program_guid(qs):
  83. return qs.get('programGuid', [None])[0]
  84. entries = []
  85. for mobj in re.finditer(
  86. r'<iframe\b[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?//(?:www\.)?video\.mediaset\.it/player/playerIFrame(?:Twitter)?\.shtml.*?)\1',
  87. webpage):
  88. embed_url = mobj.group('url')
  89. embed_qs = _qs(embed_url)
  90. program_guid = _program_guid(embed_qs)
  91. if program_guid:
  92. entries.append(embed_url)
  93. continue
  94. video_id = embed_qs.get('id', [None])[0]
  95. if not video_id:
  96. continue
  97. urlh = ie._request_webpage(
  98. embed_url, video_id, note='Following embed URL redirect')
  99. embed_url = compat_str(urlh.geturl())
  100. program_guid = _program_guid(_qs(embed_url))
  101. if program_guid:
  102. entries.append(embed_url)
  103. return entries
  104. def _real_extract(self, url):
  105. guid = self._match_id(url)
  106. tp_path = 'PR1GhC/media/guid/2702976343/' + guid
  107. info = self._extract_theplatform_metadata(tp_path, guid)
  108. formats = []
  109. subtitles = {}
  110. first_e = None
  111. for asset_type in ('SD', 'HD'):
  112. for f in ('MPEG4', 'MPEG-DASH', 'M3U', 'ISM'):
  113. try:
  114. tp_formats, tp_subtitles = self._extract_theplatform_smil(
  115. update_url_query('http://link.theplatform.%s/s/%s' % (self._TP_TLD, tp_path), {
  116. 'mbr': 'true',
  117. 'formats': f,
  118. 'assetTypes': asset_type,
  119. }), guid, 'Downloading %s %s SMIL data' % (f, asset_type))
  120. except ExtractorError as e:
  121. if not first_e:
  122. first_e = e
  123. break
  124. for tp_f in tp_formats:
  125. tp_f['quality'] = 1 if asset_type == 'HD' else 0
  126. formats.extend(tp_formats)
  127. subtitles = self._merge_subtitles(subtitles, tp_subtitles)
  128. if first_e and not formats:
  129. raise first_e
  130. self._sort_formats(formats)
  131. fields = []
  132. for templ, repls in (('tvSeason%sNumber', ('', 'Episode')), ('mediasetprogram$%s', ('brandTitle', 'numberOfViews', 'publishInfo'))):
  133. fields.extend(templ % repl for repl in repls)
  134. feed_data = self._download_json(
  135. 'https://feed.entertainment.tv.theplatform.eu/f/PR1GhC/mediaset-prod-all-programs/guid/-/' + guid,
  136. guid, fatal=False, query={'fields': ','.join(fields)})
  137. if feed_data:
  138. publish_info = feed_data.get('mediasetprogram$publishInfo') or {}
  139. info.update({
  140. 'episode_number': int_or_none(feed_data.get('tvSeasonEpisodeNumber')),
  141. 'season_number': int_or_none(feed_data.get('tvSeasonNumber')),
  142. 'series': feed_data.get('mediasetprogram$brandTitle'),
  143. 'uploader': publish_info.get('description'),
  144. 'uploader_id': publish_info.get('channel'),
  145. 'view_count': int_or_none(feed_data.get('mediasetprogram$numberOfViews')),
  146. })
  147. info.update({
  148. 'id': guid,
  149. 'formats': formats,
  150. 'subtitles': subtitles,
  151. })
  152. return info