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.

180 lines
7.5 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. }, {
  62. # clip
  63. 'url': 'https://www.mediasetplay.mediaset.it/video/gogglebox/un-grande-classico-della-commedia-sexy_FAFU000000661680',
  64. 'only_matching': True,
  65. }, {
  66. # iframe simple
  67. 'url': 'https://static3.mediasetplay.mediaset.it/player/index.html?appKey=5ad3966b1de1c4000d5cec48&programGuid=FAFU000000665924&id=665924',
  68. 'only_matching': True,
  69. }, {
  70. # iframe twitter (from http://www.wittytv.it/se-prima-mi-fidavo-zero/)
  71. 'url': 'https://static3.mediasetplay.mediaset.it/player/index.html?appKey=5ad3966b1de1c4000d5cec48&programGuid=FAFU000000665104&id=665104',
  72. 'only_matching': True,
  73. }, {
  74. 'url': 'mediaset:FAFU000000665924',
  75. 'only_matching': True,
  76. }, {
  77. 'url': 'https://www.mediasetplay.mediaset.it/video/mediasethaacuoreilfuturo/palmieri-alicudi-lisola-dei-tre-bambini-felici--un-decreto-per-alicudi-e-tutte-le-microscuole_FD00000000102295',
  78. 'only_matching': True,
  79. }, {
  80. 'url': 'https://www.mediasetplay.mediaset.it/video/cherryseason/anticipazioni-degli-episodi-del-23-ottobre_F306837101005C02',
  81. 'only_matching': True,
  82. }, {
  83. 'url': 'https://www.mediasetplay.mediaset.it/video/tg5/ambiente-onda-umana-per-salvare-il-pianeta_F309453601079D01',
  84. 'only_matching': True,
  85. }, {
  86. 'url': 'https://www.mediasetplay.mediaset.it/video/grandefratellovip/benedetta-una-doccia-gelata_F309344401044C135',
  87. 'only_matching': True,
  88. }]
  89. @staticmethod
  90. def _extract_urls(ie, webpage):
  91. def _qs(url):
  92. return compat_parse_qs(compat_urllib_parse_urlparse(url).query)
  93. def _program_guid(qs):
  94. return qs.get('programGuid', [None])[0]
  95. entries = []
  96. for mobj in re.finditer(
  97. r'<iframe\b[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?//(?:www\.)?video\.mediaset\.it/player/playerIFrame(?:Twitter)?\.shtml.*?)\1',
  98. webpage):
  99. embed_url = mobj.group('url')
  100. embed_qs = _qs(embed_url)
  101. program_guid = _program_guid(embed_qs)
  102. if program_guid:
  103. entries.append(embed_url)
  104. continue
  105. video_id = embed_qs.get('id', [None])[0]
  106. if not video_id:
  107. continue
  108. urlh = ie._request_webpage(
  109. embed_url, video_id, note='Following embed URL redirect')
  110. embed_url = compat_str(urlh.geturl())
  111. program_guid = _program_guid(_qs(embed_url))
  112. if program_guid:
  113. entries.append(embed_url)
  114. return entries
  115. def _parse_smil_formats(self, smil, smil_url, video_id, namespace=None, f4m_params=None, transform_rtmp_url=None):
  116. for video in smil.findall(self._xpath_ns('.//video', namespace)):
  117. video.attrib['src'] = re.sub(r'(https?://vod05)t(-mediaset-it\.akamaized\.net/.+?.mpd)\?.+', r'\1\2', video.attrib['src'])
  118. return super(MediasetIE, self)._parse_smil_formats(smil, smil_url, video_id, namespace, f4m_params, transform_rtmp_url)
  119. def _real_extract(self, url):
  120. guid = self._match_id(url)
  121. tp_path = 'PR1GhC/media/guid/2702976343/' + guid
  122. info = self._extract_theplatform_metadata(tp_path, guid)
  123. formats = []
  124. subtitles = {}
  125. first_e = None
  126. for asset_type in ('SD', 'HD'):
  127. # TODO: fixup ISM+none manifest URLs
  128. for f in ('MPEG4', 'MPEG-DASH+none', 'M3U+none'):
  129. try:
  130. tp_formats, tp_subtitles = self._extract_theplatform_smil(
  131. update_url_query('http://link.theplatform.%s/s/%s' % (self._TP_TLD, tp_path), {
  132. 'mbr': 'true',
  133. 'formats': f,
  134. 'assetTypes': asset_type,
  135. }), guid, 'Downloading %s %s SMIL data' % (f.split('+')[0], asset_type))
  136. except ExtractorError as e:
  137. if not first_e:
  138. first_e = e
  139. break
  140. for tp_f in tp_formats:
  141. tp_f['quality'] = 1 if asset_type == 'HD' else 0
  142. formats.extend(tp_formats)
  143. subtitles = self._merge_subtitles(subtitles, tp_subtitles)
  144. if first_e and not formats:
  145. raise first_e
  146. self._sort_formats(formats)
  147. fields = []
  148. for templ, repls in (('tvSeason%sNumber', ('', 'Episode')), ('mediasetprogram$%s', ('brandTitle', 'numberOfViews', 'publishInfo'))):
  149. fields.extend(templ % repl for repl in repls)
  150. feed_data = self._download_json(
  151. 'https://feed.entertainment.tv.theplatform.eu/f/PR1GhC/mediaset-prod-all-programs/guid/-/' + guid,
  152. guid, fatal=False, query={'fields': ','.join(fields)})
  153. if feed_data:
  154. publish_info = feed_data.get('mediasetprogram$publishInfo') or {}
  155. info.update({
  156. 'episode_number': int_or_none(feed_data.get('tvSeasonEpisodeNumber')),
  157. 'season_number': int_or_none(feed_data.get('tvSeasonNumber')),
  158. 'series': feed_data.get('mediasetprogram$brandTitle'),
  159. 'uploader': publish_info.get('description'),
  160. 'uploader_id': publish_info.get('channel'),
  161. 'view_count': int_or_none(feed_data.get('mediasetprogram$numberOfViews')),
  162. })
  163. info.update({
  164. 'id': guid,
  165. 'formats': formats,
  166. 'subtitles': subtitles,
  167. })
  168. return info