logo

youtube-dl

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

skyit.py (8937B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_str,
  6. compat_parse_qs,
  7. compat_urllib_parse_urlparse,
  8. )
  9. from ..utils import (
  10. dict_get,
  11. int_or_none,
  12. parse_duration,
  13. unified_timestamp,
  14. )
  15. class SkyItPlayerIE(InfoExtractor):
  16. IE_NAME = 'player.sky.it'
  17. _VALID_URL = r'https?://player\.sky\.it/player/(?:external|social)\.html\?.*?\bid=(?P<id>\d+)'
  18. _GEO_BYPASS = False
  19. _DOMAIN = 'sky'
  20. _PLAYER_TMPL = 'https://player.sky.it/player/external.html?id=%s&domain=%s'
  21. # http://static.sky.it/static/skyplayer/conf.json
  22. _TOKEN_MAP = {
  23. 'cielo': 'Hh9O7M8ks5yi6nSROL7bKYz933rdf3GhwZlTLMgvy4Q',
  24. 'hotclub': 'kW020K2jq2lk2eKRJD2vWEg832ncx2EivZlTLQput2C',
  25. 'mtv8': 'A5Nn9GGb326CI7vP5e27d7E4PIaQjota',
  26. 'salesforce': 'C6D585FD1615272C98DE38235F38BD86',
  27. 'sitocommerciale': 'VJwfFuSGnLKnd9Phe9y96WkXgYDCguPMJ2dLhGMb2RE',
  28. 'sky': 'F96WlOd8yoFmLQgiqv6fNQRvHZcsWk5jDaYnDvhbiJk',
  29. 'skyacademy': 'A6LAn7EkO2Q26FRy0IAMBekX6jzDXYL3',
  30. 'skyarte': 'LWk29hfiU39NNdq87ePeRach3nzTSV20o0lTv2001Cd',
  31. 'theupfront': 'PRSGmDMsg6QMGc04Obpoy7Vsbn7i2Whp',
  32. }
  33. def _player_url_result(self, video_id):
  34. return self.url_result(
  35. self._PLAYER_TMPL % (video_id, self._DOMAIN),
  36. SkyItPlayerIE.ie_key(), video_id)
  37. def _parse_video(self, video, video_id):
  38. title = video['title']
  39. is_live = video.get('type') == 'live'
  40. hls_url = video.get(('streaming' if is_live else 'hls') + '_url')
  41. if not hls_url and video.get('geoblock' if is_live else 'geob'):
  42. self.raise_geo_restricted(countries=['IT'])
  43. if is_live:
  44. formats = self._extract_m3u8_formats(hls_url, video_id, 'mp4')
  45. else:
  46. formats = self._extract_akamai_formats(
  47. hls_url, video_id, {'http': 'videoplatform.sky.it'})
  48. self._sort_formats(formats)
  49. return {
  50. 'id': video_id,
  51. 'title': self._live_title(title) if is_live else title,
  52. 'formats': formats,
  53. 'thumbnail': dict_get(video, ('video_still', 'video_still_medium', 'thumb')),
  54. 'description': video.get('short_desc') or None,
  55. 'timestamp': unified_timestamp(video.get('create_date')),
  56. 'duration': int_or_none(video.get('duration_sec')) or parse_duration(video.get('duration')),
  57. 'is_live': is_live,
  58. }
  59. def _real_extract(self, url):
  60. video_id = self._match_id(url)
  61. domain = compat_parse_qs(compat_urllib_parse_urlparse(
  62. url).query).get('domain', [None])[0]
  63. token = dict_get(self._TOKEN_MAP, (domain, 'sky'))
  64. video = self._download_json(
  65. 'https://apid.sky.it/vdp/v1/getVideoData',
  66. video_id, query={
  67. 'caller': 'sky',
  68. 'id': video_id,
  69. 'token': token
  70. }, headers=self.geo_verification_headers())
  71. return self._parse_video(video, video_id)
  72. class SkyItVideoIE(SkyItPlayerIE):
  73. IE_NAME = 'video.sky.it'
  74. _VALID_URL = r'https?://(?:masterchef|video|xfactor)\.sky\.it(?:/[^/]+)*/video/[0-9a-z-]+-(?P<id>\d+)'
  75. _TESTS = [{
  76. 'url': 'https://video.sky.it/news/mondo/video/uomo-ucciso-da-uno-squalo-in-australia-631227',
  77. 'md5': 'fe5c91e59a84a3437eaa0bca6e134ccd',
  78. 'info_dict': {
  79. 'id': '631227',
  80. 'ext': 'mp4',
  81. 'title': 'Uomo ucciso da uno squalo in Australia',
  82. 'timestamp': 1606036192,
  83. 'upload_date': '20201122',
  84. }
  85. }, {
  86. 'url': 'https://xfactor.sky.it/video/x-factor-2020-replay-audizioni-1-615820',
  87. 'only_matching': True,
  88. }, {
  89. 'url': 'https://masterchef.sky.it/video/masterchef-9-cosa-e-successo-nella-prima-puntata-562831',
  90. 'only_matching': True,
  91. }]
  92. def _real_extract(self, url):
  93. video_id = self._match_id(url)
  94. return self._player_url_result(video_id)
  95. class SkyItVideoLiveIE(SkyItPlayerIE):
  96. IE_NAME = 'video.sky.it:live'
  97. _VALID_URL = r'https?://video\.sky\.it/diretta/(?P<id>[^/?&#]+)'
  98. _TEST = {
  99. 'url': 'https://video.sky.it/diretta/tg24',
  100. 'info_dict': {
  101. 'id': '1',
  102. 'ext': 'mp4',
  103. 'title': r're:Diretta TG24 \d{4}-\d{2}-\d{2} \d{2}:\d{2}',
  104. 'description': 'Guarda la diretta streaming di SkyTg24, segui con Sky tutti gli appuntamenti e gli speciali di Tg24.',
  105. },
  106. 'params': {
  107. # m3u8 download
  108. 'skip_download': True,
  109. },
  110. }
  111. def _real_extract(self, url):
  112. display_id = self._match_id(url)
  113. webpage = self._download_webpage(url, display_id)
  114. asset_id = compat_str(self._parse_json(self._search_regex(
  115. r'<script[^>]+id="__NEXT_DATA__"[^>]*>({.+?})</script>',
  116. webpage, 'next data'), display_id)['props']['initialState']['livePage']['content']['asset_id'])
  117. livestream = self._download_json(
  118. 'https://apid.sky.it/vdp/v1/getLivestream',
  119. asset_id, query={'id': asset_id})
  120. return self._parse_video(livestream, asset_id)
  121. class SkyItIE(SkyItPlayerIE):
  122. IE_NAME = 'sky.it'
  123. _VALID_URL = r'https?://(?:sport|tg24)\.sky\.it(?:/[^/]+)*/\d{4}/\d{2}/\d{2}/(?P<id>[^/?&#]+)'
  124. _TESTS = [{
  125. 'url': 'https://sport.sky.it/calcio/serie-a/2020/11/21/juventus-cagliari-risultato-gol',
  126. 'info_dict': {
  127. 'id': '631201',
  128. 'ext': 'mp4',
  129. 'title': 'Un rosso alla violenza: in campo per i diritti delle donne',
  130. 'upload_date': '20201121',
  131. 'timestamp': 1605995753,
  132. },
  133. 'expected_warnings': ['Unable to download f4m manifest'],
  134. }, {
  135. 'url': 'https://tg24.sky.it/mondo/2020/11/22/australia-squalo-uccide-uomo',
  136. 'md5': 'fe5c91e59a84a3437eaa0bca6e134ccd',
  137. 'info_dict': {
  138. 'id': '631227',
  139. 'ext': 'mp4',
  140. 'title': 'Uomo ucciso da uno squalo in Australia',
  141. 'timestamp': 1606036192,
  142. 'upload_date': '20201122',
  143. },
  144. }]
  145. _VIDEO_ID_REGEX = r'data-videoid="(\d+)"'
  146. def _real_extract(self, url):
  147. display_id = self._match_id(url)
  148. webpage = self._download_webpage(url, display_id)
  149. video_id = self._search_regex(
  150. self._VIDEO_ID_REGEX, webpage, 'video id')
  151. return self._player_url_result(video_id)
  152. class SkyItAcademyIE(SkyItIE):
  153. IE_NAME = 'skyacademy.it'
  154. _VALID_URL = r'https?://(?:www\.)?skyacademy\.it(?:/[^/]+)*/\d{4}/\d{2}/\d{2}/(?P<id>[^/?&#]+)'
  155. _TESTS = [{
  156. 'url': 'https://www.skyacademy.it/eventi-speciali/2019/07/05/a-lezione-di-cinema-con-sky-academy-/',
  157. 'md5': 'ced5c26638b7863190cbc44dd6f6ba08',
  158. 'info_dict': {
  159. 'id': '523458',
  160. 'ext': 'mp4',
  161. 'title': 'Sky Academy "The Best CineCamp 2019"',
  162. 'timestamp': 1562843784,
  163. 'upload_date': '20190711',
  164. }
  165. }]
  166. _DOMAIN = 'skyacademy'
  167. _VIDEO_ID_REGEX = r'id="news-videoId_(\d+)"'
  168. class SkyItArteIE(SkyItIE):
  169. IE_NAME = 'arte.sky.it'
  170. _VALID_URL = r'https?://arte\.sky\.it/video/(?P<id>[^/?&#]+)'
  171. _TESTS = [{
  172. 'url': 'https://arte.sky.it/video/serie-musei-venezia-collezionismo-12-novembre/',
  173. 'md5': '515aee97b87d7a018b6c80727d3e7e17',
  174. 'info_dict': {
  175. 'id': '627926',
  176. 'ext': 'mp4',
  177. 'title': "Musei Galleria Franchetti alla Ca' d'Oro Palazzo Grimani",
  178. 'upload_date': '20201106',
  179. 'timestamp': 1604664493,
  180. }
  181. }]
  182. _DOMAIN = 'skyarte'
  183. _VIDEO_ID_REGEX = r'(?s)<iframe[^>]+src="(?:https:)?//player\.sky\.it/player/external\.html\?[^"]*\bid=(\d+)'
  184. class CieloTVItIE(SkyItIE):
  185. IE_NAME = 'cielotv.it'
  186. _VALID_URL = r'https?://(?:www\.)?cielotv\.it/video/(?P<id>[^.]+)\.html'
  187. _TESTS = [{
  188. 'url': 'https://www.cielotv.it/video/Il-lunedi-e-sempre-un-dramma.html',
  189. 'md5': 'c4deed77552ba901c2a0d9258320304b',
  190. 'info_dict': {
  191. 'id': '499240',
  192. 'ext': 'mp4',
  193. 'title': 'Il lunedì è sempre un dramma',
  194. 'upload_date': '20190329',
  195. 'timestamp': 1553862178,
  196. }
  197. }]
  198. _DOMAIN = 'cielo'
  199. _VIDEO_ID_REGEX = r'videoId\s*=\s*"(\d+)"'
  200. class TV8ItIE(SkyItVideoIE):
  201. IE_NAME = 'tv8.it'
  202. _VALID_URL = r'https?://tv8\.it/showvideo/(?P<id>\d+)'
  203. _TESTS = [{
  204. 'url': 'https://tv8.it/showvideo/630529/ogni-mattina-ucciso-asino-di-andrea-lo-cicero/18-11-2020/',
  205. 'md5': '9ab906a3f75ea342ed928442f9dabd21',
  206. 'info_dict': {
  207. 'id': '630529',
  208. 'ext': 'mp4',
  209. 'title': 'Ogni mattina - Ucciso asino di Andrea Lo Cicero',
  210. 'timestamp': 1605721374,
  211. 'upload_date': '20201118',
  212. }
  213. }]
  214. _DOMAIN = 'mtv8'