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.

307 lines
10 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_str
  6. from ..utils import (
  7. int_or_none,
  8. orderedSet,
  9. parse_duration,
  10. str_or_none,
  11. unified_strdate,
  12. url_or_none,
  13. xpath_element,
  14. xpath_text,
  15. )
  16. class VideomoreIE(InfoExtractor):
  17. IE_NAME = 'videomore'
  18. _VALID_URL = r'''(?x)
  19. videomore:(?P<sid>\d+)$|
  20. https?://(?:player\.)?videomore\.ru/
  21. (?:
  22. (?:
  23. embed|
  24. [^/]+/[^/]+
  25. )/|
  26. [^/]*\?.*?\btrack_id=
  27. )
  28. (?P<id>\d+)
  29. (?:[/?#&]|\.(?:xml|json)|$)
  30. '''
  31. _TESTS = [{
  32. 'url': 'http://videomore.ru/kino_v_detalayah/5_sezon/367617',
  33. 'md5': '44455a346edc0d509ac5b5a5b531dc35',
  34. 'info_dict': {
  35. 'id': '367617',
  36. 'ext': 'flv',
  37. 'title': 'Кино в деталях 5 сезон В гостях Алексей Чумаков и Юлия Ковальчук',
  38. 'series': 'Кино в деталях',
  39. 'episode': 'В гостях Алексей Чумаков и Юлия Ковальчук',
  40. 'thumbnail': r're:^https?://.*\.jpg',
  41. 'duration': 2910,
  42. 'view_count': int,
  43. 'comment_count': int,
  44. 'age_limit': 16,
  45. },
  46. }, {
  47. 'url': 'http://videomore.ru/embed/259974',
  48. 'info_dict': {
  49. 'id': '259974',
  50. 'ext': 'flv',
  51. 'title': 'Молодежка 2 сезон 40 серия',
  52. 'series': 'Молодежка',
  53. 'episode': '40 серия',
  54. 'thumbnail': r're:^https?://.*\.jpg',
  55. 'duration': 2809,
  56. 'view_count': int,
  57. 'comment_count': int,
  58. 'age_limit': 16,
  59. },
  60. 'params': {
  61. 'skip_download': True,
  62. },
  63. }, {
  64. 'url': 'http://videomore.ru/molodezhka/sezon_promo/341073',
  65. 'info_dict': {
  66. 'id': '341073',
  67. 'ext': 'flv',
  68. 'title': 'Промо Команда проиграла из-за Бакина?',
  69. 'episode': 'Команда проиграла из-за Бакина?',
  70. 'thumbnail': r're:^https?://.*\.jpg',
  71. 'duration': 29,
  72. 'age_limit': 16,
  73. 'view_count': int,
  74. },
  75. 'params': {
  76. 'skip_download': True,
  77. },
  78. }, {
  79. 'url': 'http://videomore.ru/elki_3?track_id=364623',
  80. 'only_matching': True,
  81. }, {
  82. 'url': 'http://videomore.ru/embed/364623',
  83. 'only_matching': True,
  84. }, {
  85. 'url': 'http://videomore.ru/video/tracks/364623.xml',
  86. 'only_matching': True,
  87. }, {
  88. 'url': 'http://videomore.ru/video/tracks/364623.json',
  89. 'only_matching': True,
  90. }, {
  91. 'url': 'http://videomore.ru/video/tracks/158031/quotes/33248',
  92. 'only_matching': True,
  93. }, {
  94. 'url': 'videomore:367617',
  95. 'only_matching': True,
  96. }, {
  97. 'url': 'https://player.videomore.ru/?partner_id=97&track_id=736234&autoplay=0&userToken=',
  98. 'only_matching': True,
  99. }]
  100. @staticmethod
  101. def _extract_url(webpage):
  102. mobj = re.search(
  103. r'<object[^>]+data=(["\'])https?://videomore\.ru/player\.swf\?.*config=(?P<url>https?://videomore\.ru/(?:[^/]+/)+\d+\.xml).*\1',
  104. webpage)
  105. if not mobj:
  106. mobj = re.search(
  107. r'<iframe[^>]+src=([\'"])(?P<url>https?://videomore\.ru/embed/\d+)',
  108. webpage)
  109. if mobj:
  110. return mobj.group('url')
  111. def _real_extract(self, url):
  112. mobj = re.match(self._VALID_URL, url)
  113. video_id = mobj.group('sid') or mobj.group('id')
  114. video = self._download_xml(
  115. 'http://videomore.ru/video/tracks/%s.xml' % video_id,
  116. video_id, 'Downloading video XML')
  117. item = xpath_element(video, './/playlist/item', fatal=True)
  118. title = xpath_text(
  119. item, ('./title', './episode_name'), 'title', fatal=True)
  120. video_url = xpath_text(item, './video_url', 'video url', fatal=True)
  121. formats = self._extract_f4m_formats(video_url, video_id, f4m_id='hds')
  122. self._sort_formats(formats)
  123. thumbnail = xpath_text(item, './thumbnail_url')
  124. duration = int_or_none(xpath_text(item, './duration'))
  125. view_count = int_or_none(xpath_text(item, './views'))
  126. comment_count = int_or_none(xpath_text(item, './count_comments'))
  127. age_limit = int_or_none(xpath_text(item, './min_age'))
  128. series = xpath_text(item, './project_name')
  129. episode = xpath_text(item, './episode_name')
  130. return {
  131. 'id': video_id,
  132. 'title': title,
  133. 'series': series,
  134. 'episode': episode,
  135. 'thumbnail': thumbnail,
  136. 'duration': duration,
  137. 'view_count': view_count,
  138. 'comment_count': comment_count,
  139. 'age_limit': age_limit,
  140. 'formats': formats,
  141. }
  142. class VideomoreVideoIE(InfoExtractor):
  143. IE_NAME = 'videomore:video'
  144. _VALID_URL = r'https?://videomore\.ru/(?:(?:[^/]+/){2})?(?P<id>[^/?#&]+)(?:/*|[?#&].*?)$'
  145. _TESTS = [{
  146. # single video with og:video:iframe
  147. 'url': 'http://videomore.ru/elki_3',
  148. 'info_dict': {
  149. 'id': '364623',
  150. 'ext': 'flv',
  151. 'title': 'Ёлки 3',
  152. 'description': '',
  153. 'thumbnail': r're:^https?://.*\.jpg',
  154. 'duration': 5579,
  155. 'age_limit': 6,
  156. 'view_count': int,
  157. },
  158. 'params': {
  159. 'skip_download': True,
  160. },
  161. }, {
  162. # season single series with og:video:iframe
  163. 'url': 'http://videomore.ru/poslednii_ment/1_sezon/14_seriya',
  164. 'only_matching': True,
  165. }, {
  166. 'url': 'http://videomore.ru/sejchas_v_seti/serii_221-240/226_vypusk',
  167. 'only_matching': True,
  168. }, {
  169. # single video without og:video:iframe
  170. 'url': 'http://videomore.ru/marin_i_ego_druzya',
  171. 'info_dict': {
  172. 'id': '359073',
  173. 'ext': 'flv',
  174. 'title': '1 серия. Здравствуй, Аквавилль!',
  175. 'description': 'md5:c6003179538b5d353e7bcd5b1372b2d7',
  176. 'thumbnail': r're:^https?://.*\.jpg',
  177. 'duration': 754,
  178. 'age_limit': 6,
  179. 'view_count': int,
  180. },
  181. 'params': {
  182. 'skip_download': True,
  183. },
  184. }, {
  185. 'url': 'https://videomore.ru/molodezhka/6_sezon/29_seriya?utm_so',
  186. 'only_matching': True,
  187. }]
  188. @classmethod
  189. def suitable(cls, url):
  190. return False if VideomoreIE.suitable(url) else super(VideomoreVideoIE, cls).suitable(url)
  191. def _real_extract(self, url):
  192. display_id = self._match_id(url)
  193. webpage = self._download_webpage(url, display_id)
  194. video_url = self._og_search_property(
  195. 'video:iframe', webpage, 'video url', default=None)
  196. if not video_url:
  197. video_id = self._search_regex(
  198. (r'config\s*:\s*["\']https?://videomore\.ru/video/tracks/(\d+)\.xml',
  199. r'track-id=["\'](\d+)',
  200. r'xcnt_product_id\s*=\s*(\d+)'), webpage, 'video id')
  201. video_url = 'videomore:%s' % video_id
  202. else:
  203. video_id = None
  204. return self.url_result(
  205. video_url, ie=VideomoreIE.ie_key(), video_id=video_id)
  206. class VideomoreSeasonIE(InfoExtractor):
  207. IE_NAME = 'videomore:season'
  208. _VALID_URL = r'https?://videomore\.ru/(?!embed)(?P<id>[^/]+/[^/?#&]+)(?:/*|[?#&].*?)$'
  209. _TESTS = [{
  210. 'url': 'http://videomore.ru/molodezhka/sezon_promo',
  211. 'info_dict': {
  212. 'id': 'molodezhka/sezon_promo',
  213. 'title': 'Молодежка Промо',
  214. },
  215. 'playlist_mincount': 12,
  216. }, {
  217. 'url': 'http://videomore.ru/molodezhka/sezon_promo?utm_so',
  218. 'only_matching': True,
  219. }]
  220. @classmethod
  221. def suitable(cls, url):
  222. return (False if (VideomoreIE.suitable(url) or VideomoreVideoIE.suitable(url))
  223. else super(VideomoreSeasonIE, cls).suitable(url))
  224. def _real_extract(self, url):
  225. display_id = self._match_id(url)
  226. webpage = self._download_webpage(url, display_id)
  227. title = self._og_search_title(webpage)
  228. data = self._parse_json(
  229. self._html_search_regex(
  230. r'\bclass=["\']seasons-tracks["\'][^>]+\bdata-custom-data=(["\'])(?P<value>{.+?})\1',
  231. webpage, 'data', default='{}', group='value'),
  232. display_id, fatal=False)
  233. entries = []
  234. if data:
  235. episodes = data.get('episodes')
  236. if isinstance(episodes, list):
  237. for ep in episodes:
  238. if not isinstance(ep, dict):
  239. continue
  240. ep_id = int_or_none(ep.get('id'))
  241. ep_url = url_or_none(ep.get('url'))
  242. if ep_id:
  243. e = {
  244. 'url': 'videomore:%s' % ep_id,
  245. 'id': compat_str(ep_id),
  246. }
  247. elif ep_url:
  248. e = {'url': ep_url}
  249. else:
  250. continue
  251. e.update({
  252. '_type': 'url',
  253. 'ie_key': VideomoreIE.ie_key(),
  254. 'title': str_or_none(ep.get('title')),
  255. 'thumbnail': url_or_none(ep.get('image')),
  256. 'duration': parse_duration(ep.get('duration')),
  257. 'episode_number': int_or_none(ep.get('number')),
  258. 'upload_date': unified_strdate(ep.get('date')),
  259. })
  260. entries.append(e)
  261. if not entries:
  262. entries = [
  263. self.url_result(
  264. 'videomore:%s' % video_id, ie=VideomoreIE.ie_key(),
  265. video_id=video_id)
  266. for video_id in orderedSet(re.findall(
  267. r':(?:id|key)=["\'](\d+)["\']', webpage))]
  268. if not entries:
  269. entries = [
  270. self.url_result(item) for item in re.findall(
  271. r'<a[^>]+href="((?:https?:)?//videomore\.ru/%s/[^/]+)"[^>]+class="widget-item-desc"'
  272. % display_id, webpage)]
  273. return self.playlist_result(entries, display_id, title)