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.

268 lines
9.9 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. determine_ext,
  7. ExtractorError,
  8. float_or_none,
  9. get_element_by_class,
  10. int_or_none,
  11. js_to_json,
  12. NO_DEFAULT,
  13. parse_iso8601,
  14. remove_start,
  15. strip_or_none,
  16. url_basename,
  17. )
  18. class OnetBaseIE(InfoExtractor):
  19. _URL_BASE_RE = r'https?://(?:(?:www\.)?onet\.tv|onet100\.vod\.pl)/[a-z]/'
  20. def _search_mvp_id(self, webpage):
  21. return self._search_regex(
  22. r'id=(["\'])mvp:(?P<id>.+?)\1', webpage, 'mvp id', group='id')
  23. def _extract_from_id(self, video_id, webpage=None):
  24. response = self._download_json(
  25. 'http://qi.ckm.onetapi.pl/', video_id,
  26. query={
  27. 'body[id]': video_id,
  28. 'body[jsonrpc]': '2.0',
  29. 'body[method]': 'get_asset_detail',
  30. 'body[params][ID_Publikacji]': video_id,
  31. 'body[params][Service]': 'www.onet.pl',
  32. 'content-type': 'application/jsonp',
  33. 'x-onet-app': 'player.front.onetapi.pl',
  34. })
  35. error = response.get('error')
  36. if error:
  37. raise ExtractorError(
  38. '%s said: %s' % (self.IE_NAME, error['message']), expected=True)
  39. video = response['result'].get('0')
  40. formats = []
  41. for format_type, formats_dict in video['formats'].items():
  42. if not isinstance(formats_dict, dict):
  43. continue
  44. for format_id, format_list in formats_dict.items():
  45. if not isinstance(format_list, list):
  46. continue
  47. for f in format_list:
  48. video_url = f.get('url')
  49. if not video_url:
  50. continue
  51. ext = determine_ext(video_url)
  52. if format_id.startswith('ism'):
  53. formats.extend(self._extract_ism_formats(
  54. video_url, video_id, 'mss', fatal=False))
  55. elif ext == 'mpd':
  56. formats.extend(self._extract_mpd_formats(
  57. video_url, video_id, mpd_id='dash', fatal=False))
  58. elif format_id.startswith('hls'):
  59. formats.extend(self._extract_m3u8_formats(
  60. video_url, video_id, 'mp4', 'm3u8_native',
  61. m3u8_id='hls', fatal=False))
  62. else:
  63. http_f = {
  64. 'url': video_url,
  65. 'format_id': format_id,
  66. 'abr': float_or_none(f.get('audio_bitrate')),
  67. }
  68. if format_type == 'audio':
  69. http_f['vcodec'] = 'none'
  70. else:
  71. http_f.update({
  72. 'height': int_or_none(f.get('vertical_resolution')),
  73. 'width': int_or_none(f.get('horizontal_resolution')),
  74. 'vbr': float_or_none(f.get('video_bitrate')),
  75. })
  76. formats.append(http_f)
  77. self._sort_formats(formats)
  78. meta = video.get('meta', {})
  79. title = (self._og_search_title(
  80. webpage, default=None) if webpage else None) or meta['title']
  81. description = (self._og_search_description(
  82. webpage, default=None) if webpage else None) or meta.get('description')
  83. duration = meta.get('length') or meta.get('lenght')
  84. timestamp = parse_iso8601(meta.get('addDate'), ' ')
  85. return {
  86. 'id': video_id,
  87. 'title': title,
  88. 'description': description,
  89. 'duration': duration,
  90. 'timestamp': timestamp,
  91. 'formats': formats,
  92. }
  93. class OnetMVPIE(OnetBaseIE):
  94. _VALID_URL = r'onetmvp:(?P<id>\d+\.\d+)'
  95. _TEST = {
  96. 'url': 'onetmvp:381027.1509591944',
  97. 'only_matching': True,
  98. }
  99. def _real_extract(self, url):
  100. return self._extract_from_id(self._match_id(url))
  101. class OnetIE(OnetBaseIE):
  102. _VALID_URL = OnetBaseIE._URL_BASE_RE + r'[a-z]+/(?P<display_id>[0-9a-z-]+)/(?P<id>[0-9a-z]+)'
  103. IE_NAME = 'onet.tv'
  104. _TESTS = [{
  105. 'url': 'http://onet.tv/k/openerfestival/open-er-festival-2016-najdziwniejsze-wymagania-gwiazd/qbpyqc',
  106. 'md5': '436102770fb095c75b8bb0392d3da9ff',
  107. 'info_dict': {
  108. 'id': 'qbpyqc',
  109. 'display_id': 'open-er-festival-2016-najdziwniejsze-wymagania-gwiazd',
  110. 'ext': 'mp4',
  111. 'title': 'Open\'er Festival 2016: najdziwniejsze wymagania gwiazd',
  112. 'description': 'Trzy samochody, których nigdy nie użyto, prywatne spa, hotel dekorowany czarnym suknem czy nielegalne używki. Organizatorzy koncertów i festiwali muszą stawać przed nie lada wyzwaniem zapraszając gwia...',
  113. 'upload_date': '20160705',
  114. 'timestamp': 1467721580,
  115. },
  116. }, {
  117. 'url': 'https://onet100.vod.pl/k/openerfestival/open-er-festival-2016-najdziwniejsze-wymagania-gwiazd/qbpyqc',
  118. 'only_matching': True,
  119. }]
  120. def _real_extract(self, url):
  121. mobj = re.match(self._VALID_URL, url)
  122. display_id, video_id = mobj.group('display_id', 'id')
  123. webpage = self._download_webpage(url, display_id)
  124. mvp_id = self._search_mvp_id(webpage)
  125. info_dict = self._extract_from_id(mvp_id, webpage)
  126. info_dict.update({
  127. 'id': video_id,
  128. 'display_id': display_id,
  129. })
  130. return info_dict
  131. class OnetChannelIE(OnetBaseIE):
  132. _VALID_URL = OnetBaseIE._URL_BASE_RE + r'(?P<id>[a-z]+)(?:[?#]|$)'
  133. IE_NAME = 'onet.tv:channel'
  134. _TESTS = [{
  135. 'url': 'http://onet.tv/k/openerfestival',
  136. 'info_dict': {
  137. 'id': 'openerfestival',
  138. 'title': "Open'er Festival",
  139. 'description': "Tak było na Open'er Festival 2016! Oglądaj nasze reportaże i wywiady z artystami.",
  140. },
  141. 'playlist_mincount': 35,
  142. }, {
  143. 'url': 'https://onet100.vod.pl/k/openerfestival',
  144. 'only_matching': True,
  145. }]
  146. def _real_extract(self, url):
  147. channel_id = self._match_id(url)
  148. webpage = self._download_webpage(url, channel_id)
  149. current_clip_info = self._parse_json(self._search_regex(
  150. r'var\s+currentClip\s*=\s*({[^}]+})', webpage, 'video info'), channel_id,
  151. transform_source=lambda s: js_to_json(re.sub(r'\'\s*\+\s*\'', '', s)))
  152. video_id = remove_start(current_clip_info['ckmId'], 'mvp:')
  153. video_name = url_basename(current_clip_info['url'])
  154. if self._downloader.params.get('noplaylist'):
  155. self.to_screen(
  156. 'Downloading just video %s because of --no-playlist' % video_name)
  157. return self._extract_from_id(video_id, webpage)
  158. self.to_screen(
  159. 'Downloading channel %s - add --no-playlist to just download video %s' % (
  160. channel_id, video_name))
  161. matches = re.findall(
  162. r'<a[^>]+href=[\'"](%s[a-z]+/[0-9a-z-]+/[0-9a-z]+)' % self._URL_BASE_RE,
  163. webpage)
  164. entries = [
  165. self.url_result(video_link, OnetIE.ie_key())
  166. for video_link in matches]
  167. channel_title = strip_or_none(get_element_by_class('o_channelName', webpage))
  168. channel_description = strip_or_none(get_element_by_class('o_channelDesc', webpage))
  169. return self.playlist_result(entries, channel_id, channel_title, channel_description)
  170. class OnetPlIE(InfoExtractor):
  171. _VALID_URL = r'https?://(?:[^/]+\.)?(?:onet|businessinsider\.com|plejada)\.pl/(?:[^/]+/)+(?P<id>[0-9a-z]+)'
  172. IE_NAME = 'onet.pl'
  173. _TESTS = [{
  174. 'url': 'http://eurosport.onet.pl/zimowe/skoki-narciarskie/ziobro-wygral-kwalifikacje-w-pjongczangu/9ckrly',
  175. 'md5': 'b94021eb56214c3969380388b6e73cb0',
  176. 'info_dict': {
  177. 'id': '1561707.1685479',
  178. 'ext': 'mp4',
  179. 'title': 'Ziobro wygrał kwalifikacje w Pjongczangu',
  180. 'description': 'md5:61fb0740084d2d702ea96512a03585b4',
  181. 'upload_date': '20170214',
  182. 'timestamp': 1487078046,
  183. },
  184. }, {
  185. # embedded via pulsembed
  186. 'url': 'http://film.onet.pl/pensjonat-nad-rozlewiskiem-relacja-z-planu-serialu/y428n0',
  187. 'info_dict': {
  188. 'id': '501235.965429946',
  189. 'ext': 'mp4',
  190. 'title': '"Pensjonat nad rozlewiskiem": relacja z planu serialu',
  191. 'upload_date': '20170622',
  192. 'timestamp': 1498159955,
  193. },
  194. 'params': {
  195. 'skip_download': True,
  196. },
  197. }, {
  198. 'url': 'http://film.onet.pl/zwiastuny/ghost-in-the-shell-drugi-zwiastun-pl/5q6yl3',
  199. 'only_matching': True,
  200. }, {
  201. 'url': 'http://moto.onet.pl/jak-wybierane-sa-miejsca-na-fotoradary/6rs04e',
  202. 'only_matching': True,
  203. }, {
  204. 'url': 'http://businessinsider.com.pl/wideo/scenariusz-na-koniec-swiata-wedlug-nasa/dwnqptk',
  205. 'only_matching': True,
  206. }, {
  207. 'url': 'http://plejada.pl/weronika-rosati-o-swoim-domniemanym-slubie/n2bq89',
  208. 'only_matching': True,
  209. }]
  210. def _search_mvp_id(self, webpage, default=NO_DEFAULT):
  211. return self._search_regex(
  212. r'data-(?:params-)?mvp=["\'](\d+\.\d+)', webpage, 'mvp id',
  213. default=default)
  214. def _real_extract(self, url):
  215. video_id = self._match_id(url)
  216. webpage = self._download_webpage(url, video_id)
  217. mvp_id = self._search_mvp_id(webpage, default=None)
  218. if not mvp_id:
  219. pulsembed_url = self._search_regex(
  220. r'data-src=(["\'])(?P<url>(?:https?:)?//pulsembed\.eu/.+?)\1',
  221. webpage, 'pulsembed url', group='url')
  222. webpage = self._download_webpage(
  223. pulsembed_url, video_id, 'Downloading pulsembed webpage')
  224. mvp_id = self._search_mvp_id(webpage)
  225. return self.url_result(
  226. 'onetmvp:%s' % mvp_id, OnetMVPIE.ie_key(), video_id=mvp_id)