mediaset.py 5.4 KB

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