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.

256 lines
9.2 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. clean_html,
  7. int_or_none,
  8. js_to_json,
  9. qualities,
  10. unified_strdate,
  11. url_or_none,
  12. )
  13. class NovaEmbedIE(InfoExtractor):
  14. _VALID_URL = r'https?://media\.cms\.nova\.cz/embed/(?P<id>[^/?#&]+)'
  15. _TEST = {
  16. 'url': 'https://media.cms.nova.cz/embed/8o0n0r?autoplay=1',
  17. 'md5': 'b3834f6de5401baabf31ed57456463f7',
  18. 'info_dict': {
  19. 'id': '8o0n0r',
  20. 'ext': 'mp4',
  21. 'title': '2180. díl',
  22. 'thumbnail': r're:^https?://.*\.jpg',
  23. 'duration': 2578,
  24. },
  25. }
  26. def _real_extract(self, url):
  27. video_id = self._match_id(url)
  28. webpage = self._download_webpage(url, video_id)
  29. bitrates = self._parse_json(
  30. self._search_regex(
  31. r'(?s)(?:src|bitrates)\s*=\s*({.+?})\s*;', webpage, 'formats'),
  32. video_id, transform_source=js_to_json)
  33. QUALITIES = ('lq', 'mq', 'hq', 'hd')
  34. quality_key = qualities(QUALITIES)
  35. formats = []
  36. for format_id, format_list in bitrates.items():
  37. if not isinstance(format_list, list):
  38. continue
  39. for format_url in format_list:
  40. format_url = url_or_none(format_url)
  41. if not format_url:
  42. continue
  43. f = {
  44. 'url': format_url,
  45. }
  46. f_id = format_id
  47. for quality in QUALITIES:
  48. if '%s.mp4' % quality in format_url:
  49. f_id += '-%s' % quality
  50. f.update({
  51. 'quality': quality_key(quality),
  52. 'format_note': quality.upper(),
  53. })
  54. break
  55. f['format_id'] = f_id
  56. formats.append(f)
  57. self._sort_formats(formats)
  58. title = self._og_search_title(
  59. webpage, default=None) or self._search_regex(
  60. (r'<value>(?P<title>[^<]+)',
  61. r'videoTitle\s*:\s*(["\'])(?P<value>(?:(?!\1).)+)\1'), webpage,
  62. 'title', group='value')
  63. thumbnail = self._og_search_thumbnail(
  64. webpage, default=None) or self._search_regex(
  65. r'poster\s*:\s*(["\'])(?P<value>(?:(?!\1).)+)\1', webpage,
  66. 'thumbnail', fatal=False, group='value')
  67. duration = int_or_none(self._search_regex(
  68. r'videoDuration\s*:\s*(\d+)', webpage, 'duration', fatal=False))
  69. return {
  70. 'id': video_id,
  71. 'title': title,
  72. 'thumbnail': thumbnail,
  73. 'duration': duration,
  74. 'formats': formats,
  75. }
  76. class NovaIE(InfoExtractor):
  77. IE_DESC = 'TN.cz, Prásk.tv, Nova.cz, Novaplus.cz, FANDA.tv, Krásná.cz and Doma.cz'
  78. _VALID_URL = r'https?://(?:[^.]+\.)?(?P<site>tv(?:noviny)?|tn|novaplus|vymena|fanda|krasna|doma|prask)\.nova\.cz/(?:[^/]+/)+(?P<id>[^/]+?)(?:\.html|/|$)'
  79. _TESTS = [{
  80. 'url': 'http://tn.nova.cz/clanek/tajemstvi-ukryte-v-podzemi-specialni-nemocnice-v-prazske-krci.html#player_13260',
  81. 'md5': '1dd7b9d5ea27bc361f110cd855a19bd3',
  82. 'info_dict': {
  83. 'id': '1757139',
  84. 'display_id': 'tajemstvi-ukryte-v-podzemi-specialni-nemocnice-v-prazske-krci',
  85. 'ext': 'mp4',
  86. 'title': 'Podzemní nemocnice v pražské Krči',
  87. 'description': 'md5:f0a42dd239c26f61c28f19e62d20ef53',
  88. 'thumbnail': r're:^https?://.*\.(?:jpg)',
  89. }
  90. }, {
  91. 'url': 'http://fanda.nova.cz/clanek/fun-and-games/krvavy-epos-zaklinac-3-divoky-hon-vychazi-vyhrajte-ho-pro-sebe.html',
  92. 'info_dict': {
  93. 'id': '1753621',
  94. 'ext': 'mp4',
  95. 'title': 'Zaklínač 3: Divoký hon',
  96. 'description': 're:.*Pokud se stejně jako my nemůžete.*',
  97. 'thumbnail': r're:https?://.*\.jpg(\?.*)?',
  98. 'upload_date': '20150521',
  99. },
  100. 'params': {
  101. # rtmp download
  102. 'skip_download': True,
  103. }
  104. }, {
  105. # media.cms.nova.cz embed
  106. 'url': 'https://novaplus.nova.cz/porad/ulice/epizoda/18760-2180-dil',
  107. 'info_dict': {
  108. 'id': '8o0n0r',
  109. 'ext': 'mp4',
  110. 'title': '2180. díl',
  111. 'thumbnail': r're:^https?://.*\.jpg',
  112. 'duration': 2578,
  113. },
  114. 'params': {
  115. 'skip_download': True,
  116. },
  117. 'add_ie': [NovaEmbedIE.ie_key()],
  118. }, {
  119. 'url': 'http://sport.tn.nova.cz/clanek/sport/hokej/nhl/zivot-jde-dal-hodnotil-po-vyrazeni-z-playoff-jiri-sekac.html',
  120. 'only_matching': True,
  121. }, {
  122. 'url': 'http://fanda.nova.cz/clanek/fun-and-games/krvavy-epos-zaklinac-3-divoky-hon-vychazi-vyhrajte-ho-pro-sebe.html',
  123. 'only_matching': True,
  124. }, {
  125. 'url': 'http://doma.nova.cz/clanek/zdravi/prijdte-se-zapsat-do-registru-kostni-drene-jiz-ve-stredu-3-cervna.html',
  126. 'only_matching': True,
  127. }, {
  128. 'url': 'http://prask.nova.cz/clanek/novinky/co-si-na-sobe-nase-hvezdy-nechaly-pojistit.html',
  129. 'only_matching': True,
  130. }, {
  131. 'url': 'http://tv.nova.cz/clanek/novinky/zivot-je-zivot-bondovsky-trailer.html',
  132. 'only_matching': True,
  133. }]
  134. def _real_extract(self, url):
  135. mobj = re.match(self._VALID_URL, url)
  136. display_id = mobj.group('id')
  137. site = mobj.group('site')
  138. webpage = self._download_webpage(url, display_id)
  139. # novaplus
  140. embed_id = self._search_regex(
  141. r'<iframe[^>]+\bsrc=["\'](?:https?:)?//media\.cms\.nova\.cz/embed/([^/?#&]+)',
  142. webpage, 'embed url', default=None)
  143. if embed_id:
  144. return self.url_result(
  145. 'https://media.cms.nova.cz/embed/%s' % embed_id,
  146. ie=NovaEmbedIE.ie_key(), video_id=embed_id)
  147. video_id = self._search_regex(
  148. [r"(?:media|video_id)\s*:\s*'(\d+)'",
  149. r'media=(\d+)',
  150. r'id="article_video_(\d+)"',
  151. r'id="player_(\d+)"'],
  152. webpage, 'video id')
  153. config_url = self._search_regex(
  154. r'src="(https?://(?:tn|api)\.nova\.cz/bin/player/videojs/config\.php\?[^"]+)"',
  155. webpage, 'config url', default=None)
  156. config_params = {}
  157. if not config_url:
  158. player = self._parse_json(
  159. self._search_regex(
  160. r'(?s)Player\s*\(.+?\s*,\s*({.+?\bmedia\b["\']?\s*:\s*["\']?\d+.+?})\s*\)', webpage,
  161. 'player', default='{}'),
  162. video_id, transform_source=js_to_json, fatal=False)
  163. if player:
  164. config_url = url_or_none(player.get('configUrl'))
  165. params = player.get('configParams')
  166. if isinstance(params, dict):
  167. config_params = params
  168. if not config_url:
  169. DEFAULT_SITE_ID = '23000'
  170. SITES = {
  171. 'tvnoviny': DEFAULT_SITE_ID,
  172. 'novaplus': DEFAULT_SITE_ID,
  173. 'vymena': DEFAULT_SITE_ID,
  174. 'krasna': DEFAULT_SITE_ID,
  175. 'fanda': '30',
  176. 'tn': '30',
  177. 'doma': '30',
  178. }
  179. site_id = self._search_regex(
  180. r'site=(\d+)', webpage, 'site id', default=None) or SITES.get(
  181. site, DEFAULT_SITE_ID)
  182. config_url = 'https://api.nova.cz/bin/player/videojs/config.php'
  183. config_params = {
  184. 'site': site_id,
  185. 'media': video_id,
  186. 'quality': 3,
  187. 'version': 1,
  188. }
  189. config = self._download_json(
  190. config_url, display_id,
  191. 'Downloading config JSON', query=config_params,
  192. transform_source=lambda s: s[s.index('{'):s.rindex('}') + 1])
  193. mediafile = config['mediafile']
  194. video_url = mediafile['src']
  195. m = re.search(r'^(?P<url>rtmpe?://[^/]+/(?P<app>[^/]+?))/&*(?P<playpath>.+)$', video_url)
  196. if m:
  197. formats = [{
  198. 'url': m.group('url'),
  199. 'app': m.group('app'),
  200. 'play_path': m.group('playpath'),
  201. 'player_path': 'http://tvnoviny.nova.cz/static/shared/app/videojs/video-js.swf',
  202. 'ext': 'flv',
  203. }]
  204. else:
  205. formats = [{
  206. 'url': video_url,
  207. }]
  208. self._sort_formats(formats)
  209. title = mediafile.get('meta', {}).get('title') or self._og_search_title(webpage)
  210. description = clean_html(self._og_search_description(webpage, default=None))
  211. thumbnail = config.get('poster')
  212. if site == 'novaplus':
  213. upload_date = unified_strdate(self._search_regex(
  214. r'(\d{1,2}-\d{1,2}-\d{4})$', display_id, 'upload date', default=None))
  215. elif site == 'fanda':
  216. upload_date = unified_strdate(self._search_regex(
  217. r'<span class="date_time">(\d{1,2}\.\d{1,2}\.\d{4})', webpage, 'upload date', default=None))
  218. else:
  219. upload_date = None
  220. return {
  221. 'id': video_id,
  222. 'display_id': display_id,
  223. 'title': title,
  224. 'description': description,
  225. 'upload_date': upload_date,
  226. 'thumbnail': thumbnail,
  227. 'formats': formats,
  228. }