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.

187 lines
6.3 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. int_or_none,
  7. parse_age_limit,
  8. parse_iso8601,
  9. xpath_text,
  10. )
  11. class VideomoreIE(InfoExtractor):
  12. IE_NAME = 'videomore'
  13. _VALID_URL = r'videomore:(?P<sid>\d+)$|https?://videomore\.ru/(?:(?:embed|[^/]+/[^/]+)/|[^/]+\?.*\btrack_id=)(?P<id>\d+)(?:[/?#&]|\.(?:xml|json)|$)'
  14. _TESTS = [{
  15. 'url': 'http://videomore.ru/kino_v_detalayah/5_sezon/367617',
  16. 'md5': '70875fbf57a1cd004709920381587185',
  17. 'info_dict': {
  18. 'id': '367617',
  19. 'ext': 'flv',
  20. 'title': 'В гостях Алексей Чумаков и Юлия Ковальчук',
  21. 'description': 'В гостях – лучшие романтические комедии года, «Выживший» Иньярриту и «Стив Джобс» Дэнни Бойла.',
  22. 'thumbnail': 're:^https?://.*\.jpg',
  23. 'duration': 2910,
  24. 'age_limit': 16,
  25. 'view_count': int,
  26. },
  27. }, {
  28. 'url': 'http://videomore.ru/elki_3?track_id=364623',
  29. 'only_matching': True,
  30. }, {
  31. 'url': 'http://videomore.ru/embed/364623',
  32. 'only_matching': True,
  33. }, {
  34. 'url': 'http://videomore.ru/video/tracks/364623.xml',
  35. 'only_matching': True,
  36. }, {
  37. 'url': 'http://videomore.ru/video/tracks/364623.json',
  38. 'only_matching': True,
  39. }, {
  40. 'url': 'http://videomore.ru/video/tracks/158031/quotes/33248',
  41. 'only_matching': True,
  42. }, {
  43. 'url': 'videomore:367617',
  44. 'only_matching': True,
  45. }]
  46. @staticmethod
  47. def _extract_url(webpage):
  48. mobj = re.search(
  49. r'<object[^>]+data=(["\'])https?://videomore.ru/player\.swf\?.*config=(?P<url>https?://videomore\.ru/(?:[^/]+/)+\d+\.xml).*\1',
  50. webpage)
  51. if mobj:
  52. return mobj.group('url')
  53. def _real_extract(self, url):
  54. mobj = re.match(self._VALID_URL, url)
  55. video_id = mobj.group('sid') or mobj.group('id')
  56. video = self._download_xml(
  57. 'http://videomore.ru/video/tracks/%s.xml' % video_id,
  58. video_id, 'Downloading video XML')
  59. video_url = xpath_text(video, './/video_url', 'video url', fatal=True)
  60. formats = self._extract_f4m_formats(video_url, video_id, f4m_id='hds')
  61. data = self._download_json(
  62. 'http://videomore.ru/video/tracks/%s.json' % video_id,
  63. video_id, 'Downloadinng video JSON')
  64. title = data.get('title') or data['project_title']
  65. description = data.get('description') or data.get('description_raw')
  66. timestamp = parse_iso8601(data.get('published_at'))
  67. duration = int_or_none(data.get('duration'))
  68. view_count = int_or_none(data.get('views'))
  69. age_limit = parse_age_limit(data.get('min_age'))
  70. thumbnails = [{
  71. 'url': thumbnail,
  72. } for thumbnail in data.get('big_thumbnail_urls', [])]
  73. return {
  74. 'id': video_id,
  75. 'title': title,
  76. 'description': description,
  77. 'thumbnails': thumbnails,
  78. 'timestamp': timestamp,
  79. 'duration': duration,
  80. 'view_count': view_count,
  81. 'age_limit': age_limit,
  82. 'formats': formats,
  83. }
  84. class VideomoreVideoIE(InfoExtractor):
  85. IE_NAME = 'videomore:video'
  86. _VALID_URL = r'https?://videomore\.ru/(?:(?:[^/]+/){2})?(?P<id>[^/?#&]+)[/?#&]*$'
  87. _TESTS = [{
  88. # single video with og:video:iframe
  89. 'url': 'http://videomore.ru/elki_3',
  90. 'info_dict': {
  91. 'id': '364623',
  92. 'ext': 'flv',
  93. 'title': 'Ёлки 3',
  94. 'description': '',
  95. 'thumbnail': 're:^https?://.*\.jpg',
  96. 'duration': 5579,
  97. 'age_limit': 6,
  98. 'view_count': int,
  99. },
  100. 'params': {
  101. 'skip_download': True,
  102. },
  103. }, {
  104. # season single serie with og:video:iframe
  105. 'url': 'http://videomore.ru/poslednii_ment/1_sezon/14_seriya',
  106. 'only_matching': True,
  107. }, {
  108. 'url': 'http://videomore.ru/sejchas_v_seti/serii_221-240/226_vypusk',
  109. 'only_matching': True,
  110. }, {
  111. # single video without og:video:iframe
  112. 'url': 'http://videomore.ru/marin_i_ego_druzya',
  113. 'info_dict': {
  114. 'id': '359073',
  115. 'ext': 'flv',
  116. 'title': '1 серия. Здравствуй, Аквавилль!',
  117. 'description': 'md5:c6003179538b5d353e7bcd5b1372b2d7',
  118. 'thumbnail': 're:^https?://.*\.jpg',
  119. 'duration': 754,
  120. 'age_limit': 6,
  121. 'view_count': int,
  122. },
  123. 'params': {
  124. 'skip_download': True,
  125. },
  126. }]
  127. @classmethod
  128. def suitable(cls, url):
  129. return False if VideomoreIE.suitable(url) else super(VideomoreVideoIE, cls).suitable(url)
  130. def _real_extract(self, url):
  131. display_id = self._match_id(url)
  132. webpage = self._download_webpage(url, display_id)
  133. video_url = self._og_search_property(
  134. 'video:iframe', webpage, 'video url', default=None)
  135. if not video_url:
  136. video_id = self._search_regex(
  137. (r'config\s*:\s*["\']https?://videomore\.ru/video/tracks/(\d+)\.xml',
  138. r'track-id=["\'](\d+)',
  139. r'xcnt_product_id\s*=\s*(\d+)'), webpage, 'video id')
  140. video_url = 'videomore:%s' % video_id
  141. return self.url_result(video_url, VideomoreIE.ie_key())
  142. class VideomoreSeasonIE(InfoExtractor):
  143. IE_NAME = 'videomore:season'
  144. _VALID_URL = r'https?://videomore\.ru/(?!embed)(?P<id>[^/]+/[^/?#&]+)[/?#&]*$'
  145. _TESTS = [{
  146. 'url': 'http://videomore.ru/molodezhka/sezon_promo',
  147. 'info_dict': {
  148. 'id': 'molodezhka/sezon_promo',
  149. 'title': 'Молодежка Промо',
  150. },
  151. 'playlist_mincount': 12,
  152. }]
  153. def _real_extract(self, url):
  154. display_id = self._match_id(url)
  155. webpage = self._download_webpage(url, display_id)
  156. title = self._og_search_title(webpage)
  157. entries = [
  158. self.url_result(item) for item in re.findall(
  159. r'<a[^>]+href="((?:https?:)?//videomore\.ru/%s/[^/]+)"[^>]+class="widget-item-desc"'
  160. % display_id, webpage)]
  161. return self.playlist_result(entries, display_id, title)