videomore.py 6.3 KB

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