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.

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