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.

224 lines
8.1 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. parse_iso8601,
  13. remove_start,
  14. strip_or_none,
  15. url_basename,
  16. )
  17. class OnetBaseIE(InfoExtractor):
  18. def _search_mvp_id(self, webpage):
  19. return self._search_regex(
  20. r'id=(["\'])mvp:(?P<id>.+?)\1', webpage, 'mvp id', group='id')
  21. def _extract_from_id(self, video_id, webpage=None):
  22. response = self._download_json(
  23. 'http://qi.ckm.onetapi.pl/', video_id,
  24. query={
  25. 'body[id]': video_id,
  26. 'body[jsonrpc]': '2.0',
  27. 'body[method]': 'get_asset_detail',
  28. 'body[params][ID_Publikacji]': video_id,
  29. 'body[params][Service]': 'www.onet.pl',
  30. 'content-type': 'application/jsonp',
  31. 'x-onet-app': 'player.front.onetapi.pl',
  32. })
  33. error = response.get('error')
  34. if error:
  35. raise ExtractorError(
  36. '%s said: %s' % (self.IE_NAME, error['message']), expected=True)
  37. video = response['result'].get('0')
  38. formats = []
  39. for _, formats_dict in video['formats'].items():
  40. if not isinstance(formats_dict, dict):
  41. continue
  42. for format_id, format_list in formats_dict.items():
  43. if not isinstance(format_list, list):
  44. continue
  45. for f in format_list:
  46. video_url = f.get('url')
  47. if not video_url:
  48. continue
  49. ext = determine_ext(video_url)
  50. if format_id == 'ism':
  51. formats.extend(self._extract_ism_formats(
  52. video_url, video_id, 'mss', fatal=False))
  53. elif ext == 'mpd':
  54. formats.extend(self._extract_mpd_formats(
  55. video_url, video_id, mpd_id='dash', fatal=False))
  56. else:
  57. formats.append({
  58. 'url': video_url,
  59. 'format_id': format_id,
  60. 'height': int_or_none(f.get('vertical_resolution')),
  61. 'width': int_or_none(f.get('horizontal_resolution')),
  62. 'abr': float_or_none(f.get('audio_bitrate')),
  63. 'vbr': float_or_none(f.get('video_bitrate')),
  64. })
  65. self._sort_formats(formats)
  66. meta = video.get('meta', {})
  67. title = (self._og_search_title(
  68. webpage, default=None) if webpage else None) or meta['title']
  69. description = (self._og_search_description(
  70. webpage, default=None) if webpage else None) or meta.get('description')
  71. duration = meta.get('length') or meta.get('lenght')
  72. timestamp = parse_iso8601(meta.get('addDate'), ' ')
  73. return {
  74. 'id': video_id,
  75. 'title': title,
  76. 'description': description,
  77. 'duration': duration,
  78. 'timestamp': timestamp,
  79. 'formats': formats,
  80. }
  81. class OnetMVPIE(OnetBaseIE):
  82. _VALID_URL = r'onetmvp:(?P<id>\d+\.\d+)'
  83. _TEST = {
  84. 'url': 'onetmvp:381027.1509591944',
  85. 'only_matching': True,
  86. }
  87. def _real_extract(self, url):
  88. return self._extract_from_id(self._match_id(url))
  89. class OnetIE(OnetBaseIE):
  90. _VALID_URL = r'https?://(?:www\.)?onet\.tv/[a-z]/[a-z]+/(?P<display_id>[0-9a-z-]+)/(?P<id>[0-9a-z]+)'
  91. IE_NAME = 'onet.tv'
  92. _TEST = {
  93. 'url': 'http://onet.tv/k/openerfestival/open-er-festival-2016-najdziwniejsze-wymagania-gwiazd/qbpyqc',
  94. 'md5': 'e3ffbf47590032ac3f27249204173d50',
  95. 'info_dict': {
  96. 'id': 'qbpyqc',
  97. 'display_id': 'open-er-festival-2016-najdziwniejsze-wymagania-gwiazd',
  98. 'ext': 'mp4',
  99. 'title': 'Open\'er Festival 2016: najdziwniejsze wymagania gwiazd',
  100. '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...',
  101. 'upload_date': '20160705',
  102. 'timestamp': 1467721580,
  103. },
  104. }
  105. def _real_extract(self, url):
  106. mobj = re.match(self._VALID_URL, url)
  107. display_id, video_id = mobj.group('display_id', 'id')
  108. webpage = self._download_webpage(url, display_id)
  109. mvp_id = self._search_mvp_id(webpage)
  110. info_dict = self._extract_from_id(mvp_id, webpage)
  111. info_dict.update({
  112. 'id': video_id,
  113. 'display_id': display_id,
  114. })
  115. return info_dict
  116. class OnetChannelIE(OnetBaseIE):
  117. _VALID_URL = r'https?://(?:www\.)?onet\.tv/[a-z]/(?P<id>[a-z]+)(?:[?#]|$)'
  118. IE_NAME = 'onet.tv:channel'
  119. _TEST = {
  120. 'url': 'http://onet.tv/k/openerfestival',
  121. 'info_dict': {
  122. 'id': 'openerfestival',
  123. 'title': 'Open\'er Festival Live',
  124. 'description': 'Dziękujemy, że oglądaliście transmisje. Zobaczcie nasze relacje i wywiady z artystami.',
  125. },
  126. 'playlist_mincount': 46,
  127. }
  128. def _real_extract(self, url):
  129. channel_id = self._match_id(url)
  130. webpage = self._download_webpage(url, channel_id)
  131. current_clip_info = self._parse_json(self._search_regex(
  132. r'var\s+currentClip\s*=\s*({[^}]+})', webpage, 'video info'), channel_id,
  133. transform_source=lambda s: js_to_json(re.sub(r'\'\s*\+\s*\'', '', s)))
  134. video_id = remove_start(current_clip_info['ckmId'], 'mvp:')
  135. video_name = url_basename(current_clip_info['url'])
  136. if self._downloader.params.get('noplaylist'):
  137. self.to_screen(
  138. 'Downloading just video %s because of --no-playlist' % video_name)
  139. return self._extract_from_id(video_id, webpage)
  140. self.to_screen(
  141. 'Downloading channel %s - add --no-playlist to just download video %s' % (
  142. channel_id, video_name))
  143. matches = re.findall(
  144. r'<a[^>]+href=[\'"](https?://(?:www\.)?onet\.tv/[a-z]/[a-z]+/[0-9a-z-]+/[0-9a-z]+)',
  145. webpage)
  146. entries = [
  147. self.url_result(video_link, OnetIE.ie_key())
  148. for video_link in matches]
  149. channel_title = strip_or_none(get_element_by_class('o_channelName', webpage))
  150. channel_description = strip_or_none(get_element_by_class('o_channelDesc', webpage))
  151. return self.playlist_result(entries, channel_id, channel_title, channel_description)
  152. class OnetPlIE(InfoExtractor):
  153. _VALID_URL = r'https?://(?:[^/]+\.)?(?:onet|businessinsider\.com|plejada)\.pl/(?:[^/]+/)+(?P<id>[0-9a-z]+)'
  154. IE_NAME = 'onet.pl'
  155. _TESTS = [{
  156. 'url': 'http://eurosport.onet.pl/zimowe/skoki-narciarskie/ziobro-wygral-kwalifikacje-w-pjongczangu/9ckrly',
  157. 'md5': 'b94021eb56214c3969380388b6e73cb0',
  158. 'info_dict': {
  159. 'id': '1561707.1685479',
  160. 'ext': 'mp4',
  161. 'title': 'Ziobro wygrał kwalifikacje w Pjongczangu',
  162. 'description': 'md5:61fb0740084d2d702ea96512a03585b4',
  163. 'upload_date': '20170214',
  164. 'timestamp': 1487078046,
  165. },
  166. }, {
  167. 'url': 'http://film.onet.pl/zwiastuny/ghost-in-the-shell-drugi-zwiastun-pl/5q6yl3',
  168. 'only_matching': True,
  169. }, {
  170. 'url': 'http://moto.onet.pl/jak-wybierane-sa-miejsca-na-fotoradary/6rs04e',
  171. 'only_matching': True,
  172. }, {
  173. 'url': 'http://businessinsider.com.pl/wideo/scenariusz-na-koniec-swiata-wedlug-nasa/dwnqptk',
  174. 'only_matching': True,
  175. }, {
  176. 'url': 'http://plejada.pl/weronika-rosati-o-swoim-domniemanym-slubie/n2bq89',
  177. 'only_matching': True,
  178. }]
  179. def _real_extract(self, url):
  180. video_id = self._match_id(url)
  181. webpage = self._download_webpage(url, video_id)
  182. mvp_id = self._search_regex(
  183. r'data-params-mvp=["\'](\d+\.\d+)', webpage, 'mvp id')
  184. return self.url_result(
  185. 'onetmvp:%s' % mvp_id, OnetMVPIE.ie_key(), video_id=mvp_id)