logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

mediaset.py (8214B)


  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_urllib_parse_urlparse,
  8. )
  9. from ..utils import (
  10. ExtractorError,
  11. int_or_none,
  12. update_url_query,
  13. )
  14. class MediasetIE(ThePlatformBaseIE):
  15. _TP_TLD = 'eu'
  16. _VALID_URL = r'''(?x)
  17. (?:
  18. mediaset:|
  19. https?://
  20. (?:(?:www|static3)\.)?mediasetplay\.mediaset\.it/
  21. (?:
  22. (?:video|on-demand|movie)/(?:[^/]+/)+[^/]+_|
  23. player(?:/v\d+)?/index\.html\?.*?\bprogramGuid=
  24. )
  25. )(?P<id>[0-9A-Z]{16,})
  26. '''
  27. _TESTS = [{
  28. # full episode
  29. 'url': 'https://www.mediasetplay.mediaset.it/video/hellogoodbye/quarta-puntata_FAFU000000661824',
  30. 'md5': '9b75534d42c44ecef7bf1ffeacb7f85d',
  31. 'info_dict': {
  32. 'id': 'FAFU000000661824',
  33. 'ext': 'mp4',
  34. 'title': 'Quarta puntata',
  35. 'description': 'md5:d41d8cd98f00b204e9800998ecf8427e',
  36. 'thumbnail': r're:^https?://.*\.jpg$',
  37. 'duration': 1414.26,
  38. 'upload_date': '20161107',
  39. 'series': 'Hello Goodbye',
  40. 'timestamp': 1478532900,
  41. 'uploader': 'Rete 4',
  42. 'uploader_id': 'R4',
  43. },
  44. }, {
  45. 'url': 'https://www.mediasetplay.mediaset.it/video/matrix/puntata-del-25-maggio_F309013801000501',
  46. 'md5': '288532f0ad18307705b01e581304cd7b',
  47. 'info_dict': {
  48. 'id': 'F309013801000501',
  49. 'ext': 'mp4',
  50. 'title': 'Puntata del 25 maggio',
  51. 'description': 'md5:d41d8cd98f00b204e9800998ecf8427e',
  52. 'thumbnail': r're:^https?://.*\.jpg$',
  53. 'duration': 6565.007,
  54. 'upload_date': '20180526',
  55. 'series': 'Matrix',
  56. 'timestamp': 1527326245,
  57. 'uploader': 'Canale 5',
  58. 'uploader_id': 'C5',
  59. },
  60. }, {
  61. # clip
  62. 'url': 'https://www.mediasetplay.mediaset.it/video/gogglebox/un-grande-classico-della-commedia-sexy_FAFU000000661680',
  63. 'only_matching': True,
  64. }, {
  65. # iframe simple
  66. 'url': 'https://static3.mediasetplay.mediaset.it/player/index.html?appKey=5ad3966b1de1c4000d5cec48&programGuid=FAFU000000665924&id=665924',
  67. 'only_matching': True,
  68. }, {
  69. # iframe twitter (from http://www.wittytv.it/se-prima-mi-fidavo-zero/)
  70. 'url': 'https://static3.mediasetplay.mediaset.it/player/index.html?appKey=5ad3966b1de1c4000d5cec48&programGuid=FAFU000000665104&id=665104',
  71. 'only_matching': True,
  72. }, {
  73. # embedUrl (from https://www.wittytv.it/amici/est-ce-que-tu-maimes-gabriele-5-dicembre-copia/)
  74. 'url': 'https://static3.mediasetplay.mediaset.it/player/v2/index.html?partnerId=wittytv&configId=&programGuid=FD00000000153323&autoplay=true&purl=http://www.wittytv.it/amici/est-ce-que-tu-maimes-gabriele-5-dicembre-copia/',
  75. 'only_matching': True,
  76. }, {
  77. 'url': 'mediaset:FAFU000000665924',
  78. 'only_matching': True,
  79. }, {
  80. 'url': 'https://www.mediasetplay.mediaset.it/video/mediasethaacuoreilfuturo/palmieri-alicudi-lisola-dei-tre-bambini-felici--un-decreto-per-alicudi-e-tutte-le-microscuole_FD00000000102295',
  81. 'only_matching': True,
  82. }, {
  83. 'url': 'https://www.mediasetplay.mediaset.it/video/cherryseason/anticipazioni-degli-episodi-del-23-ottobre_F306837101005C02',
  84. 'only_matching': True,
  85. }, {
  86. 'url': 'https://www.mediasetplay.mediaset.it/video/tg5/ambiente-onda-umana-per-salvare-il-pianeta_F309453601079D01',
  87. 'only_matching': True,
  88. }, {
  89. 'url': 'https://www.mediasetplay.mediaset.it/video/grandefratellovip/benedetta-una-doccia-gelata_F309344401044C135',
  90. 'only_matching': True,
  91. }, {
  92. 'url': 'https://www.mediasetplay.mediaset.it/movie/herculeslaleggendahainizio/hercules-la-leggenda-ha-inizio_F305927501000102',
  93. 'only_matching': True,
  94. }]
  95. @staticmethod
  96. def _extract_urls(ie, webpage):
  97. def _qs(url):
  98. return compat_parse_qs(compat_urllib_parse_urlparse(url).query)
  99. def _program_guid(qs):
  100. return qs.get('programGuid', [None])[0]
  101. entries = []
  102. for mobj in re.finditer(
  103. r'<iframe\b[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?//(?:www\.)?video\.mediaset\.it/player/playerIFrame(?:Twitter)?\.shtml.*?)\1',
  104. webpage):
  105. embed_url = mobj.group('url')
  106. embed_qs = _qs(embed_url)
  107. program_guid = _program_guid(embed_qs)
  108. if program_guid:
  109. entries.append(embed_url)
  110. continue
  111. video_id = embed_qs.get('id', [None])[0]
  112. if not video_id:
  113. continue
  114. urlh = ie._request_webpage(
  115. embed_url, video_id, note='Following embed URL redirect')
  116. embed_url = urlh.geturl()
  117. program_guid = _program_guid(_qs(embed_url))
  118. if program_guid:
  119. entries.append(embed_url)
  120. return entries
  121. def _parse_smil_formats(self, smil, smil_url, video_id, namespace=None, f4m_params=None, transform_rtmp_url=None):
  122. for video in smil.findall(self._xpath_ns('.//video', namespace)):
  123. video.attrib['src'] = re.sub(r'(https?://vod05)t(-mediaset-it\.akamaized\.net/.+?.mpd)\?.+', r'\1\2', video.attrib['src'])
  124. return super(MediasetIE, self)._parse_smil_formats(smil, smil_url, video_id, namespace, f4m_params, transform_rtmp_url)
  125. def _real_extract(self, url):
  126. guid = self._match_id(url)
  127. tp_path = 'PR1GhC/media/guid/2702976343/' + guid
  128. info = self._extract_theplatform_metadata(tp_path, guid)
  129. formats = []
  130. subtitles = {}
  131. first_e = None
  132. for asset_type in ('SD', 'HD'):
  133. # TODO: fixup ISM+none manifest URLs
  134. for f in ('MPEG4', 'MPEG-DASH+none', 'M3U+none'):
  135. try:
  136. tp_formats, tp_subtitles = self._extract_theplatform_smil(
  137. update_url_query('http://link.theplatform.%s/s/%s' % (self._TP_TLD, tp_path), {
  138. 'mbr': 'true',
  139. 'formats': f,
  140. 'assetTypes': asset_type,
  141. }), guid, 'Downloading %s %s SMIL data' % (f.split('+')[0], asset_type))
  142. except ExtractorError as e:
  143. if not first_e:
  144. first_e = e
  145. break
  146. for tp_f in tp_formats:
  147. tp_f['quality'] = 1 if asset_type == 'HD' else 0
  148. formats.extend(tp_formats)
  149. subtitles = self._merge_subtitles(subtitles, tp_subtitles)
  150. if first_e and not formats:
  151. raise first_e
  152. self._sort_formats(formats)
  153. fields = []
  154. for templ, repls in (('tvSeason%sNumber', ('', 'Episode')), ('mediasetprogram$%s', ('brandTitle', 'numberOfViews', 'publishInfo'))):
  155. fields.extend(templ % repl for repl in repls)
  156. feed_data = self._download_json(
  157. 'https://feed.entertainment.tv.theplatform.eu/f/PR1GhC/mediaset-prod-all-programs/guid/-/' + guid,
  158. guid, fatal=False, query={'fields': ','.join(fields)})
  159. if feed_data:
  160. publish_info = feed_data.get('mediasetprogram$publishInfo') or {}
  161. info.update({
  162. 'episode_number': int_or_none(feed_data.get('tvSeasonEpisodeNumber')),
  163. 'season_number': int_or_none(feed_data.get('tvSeasonNumber')),
  164. 'series': feed_data.get('mediasetprogram$brandTitle'),
  165. 'uploader': publish_info.get('description'),
  166. 'uploader_id': publish_info.get('channel'),
  167. 'view_count': int_or_none(feed_data.get('mediasetprogram$numberOfViews')),
  168. })
  169. info.update({
  170. 'id': guid,
  171. 'formats': formats,
  172. 'subtitles': subtitles,
  173. })
  174. return info