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.

155 lines
6.3 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_str,
  6. compat_urlparse,
  7. )
  8. from ..utils import (
  9. int_or_none,
  10. qualities,
  11. unified_strdate,
  12. )
  13. class FirstTVIE(InfoExtractor):
  14. IE_NAME = '1tv'
  15. IE_DESC = 'Первый канал'
  16. _VALID_URL = r'https?://(?:www\.)?1tv\.ru/(?:[^/]+/)+(?P<id>[^/?#]+)'
  17. _TESTS = [{
  18. # single format
  19. 'url': 'http://www.1tv.ru/shows/naedine-so-vsemi/vypuski/gost-lyudmila-senchina-naedine-so-vsemi-vypusk-ot-12-02-2015',
  20. 'md5': 'a1b6b60d530ebcf8daacf4565762bbaf',
  21. 'info_dict': {
  22. 'id': '40049',
  23. 'ext': 'mp4',
  24. 'title': 'Гость Людмила Сенчина. Наедине со всеми. Выпуск от 12.02.2015',
  25. 'thumbnail': r're:^https?://.*\.(?:jpg|JPG)$',
  26. 'upload_date': '20150212',
  27. 'duration': 2694,
  28. },
  29. }, {
  30. # multiple formats
  31. 'url': 'http://www.1tv.ru/shows/dobroe-utro/pro-zdorove/vesennyaya-allergiya-dobroe-utro-fragment-vypuska-ot-07042016',
  32. 'info_dict': {
  33. 'id': '364746',
  34. 'ext': 'mp4',
  35. 'title': 'Весенняя аллергия. Доброе утро. Фрагмент выпуска от 07.04.2016',
  36. 'thumbnail': r're:^https?://.*\.(?:jpg|JPG)$',
  37. 'upload_date': '20160407',
  38. 'duration': 179,
  39. 'formats': 'mincount:3',
  40. },
  41. 'params': {
  42. 'skip_download': True,
  43. },
  44. }, {
  45. 'url': 'http://www.1tv.ru/news/issue/2016-12-01/14:00',
  46. 'info_dict': {
  47. 'id': '14:00',
  48. 'title': 'Выпуск новостей в 14:00 1 декабря 2016 года. Новости. Первый канал',
  49. 'description': 'md5:2e921b948f8c1ff93901da78ebdb1dfd',
  50. },
  51. 'playlist_count': 13,
  52. }, {
  53. 'url': 'http://www.1tv.ru/shows/tochvtoch-supersezon/vystupleniya/evgeniy-dyatlov-vladimir-vysockiy-koni-priveredlivye-toch-v-toch-supersezon-fragment-vypuska-ot-06-11-2016',
  54. 'only_matching': True,
  55. }]
  56. def _real_extract(self, url):
  57. display_id = self._match_id(url)
  58. webpage = self._download_webpage(url, display_id)
  59. playlist_url = compat_urlparse.urljoin(url, self._search_regex(
  60. r'data-playlist-url=(["\'])(?P<url>(?:(?!\1).)+)\1',
  61. webpage, 'playlist url', group='url'))
  62. parsed_url = compat_urlparse.urlparse(playlist_url)
  63. qs = compat_urlparse.parse_qs(parsed_url.query)
  64. item_ids = qs.get('videos_ids[]') or qs.get('news_ids[]')
  65. items = self._download_json(playlist_url, display_id)
  66. if item_ids:
  67. items = [
  68. item for item in items
  69. if item.get('uid') and compat_str(item['uid']) in item_ids]
  70. else:
  71. items = [items[0]]
  72. entries = []
  73. QUALITIES = ('ld', 'sd', 'hd', )
  74. for item in items:
  75. title = item['title']
  76. quality = qualities(QUALITIES)
  77. formats = []
  78. path = None
  79. for f in item.get('mbr', []):
  80. src = f.get('src')
  81. if not src or not isinstance(src, compat_str):
  82. continue
  83. tbr = int_or_none(self._search_regex(
  84. r'_(\d{3,})\.mp4', src, 'tbr', default=None))
  85. if not path:
  86. path = self._search_regex(
  87. r'//[^/]+/(.+?)_\d+\.mp4', src,
  88. 'm3u8 path', default=None)
  89. formats.append({
  90. 'url': src,
  91. 'format_id': f.get('name'),
  92. 'tbr': tbr,
  93. 'source_preference': quality(f.get('name')),
  94. # quality metadata of http formats may be incorrect
  95. 'preference': -1,
  96. })
  97. # m3u8 URL format is reverse engineered from [1] (search for
  98. # master.m3u8). dashEdges (that is currently balancer-vod.1tv.ru)
  99. # is taken from [2].
  100. # 1. http://static.1tv.ru/player/eump1tv-current/eump-1tv.all.min.js?rnd=9097422834:formatted
  101. # 2. http://static.1tv.ru/player/eump1tv-config/config-main.js?rnd=9097422834
  102. if not path and len(formats) == 1:
  103. path = self._search_regex(
  104. r'//[^/]+/(.+?$)', formats[0]['url'],
  105. 'm3u8 path', default=None)
  106. if path:
  107. if len(formats) == 1:
  108. m3u8_path = ','
  109. else:
  110. tbrs = [compat_str(t) for t in sorted(f['tbr'] for f in formats)]
  111. m3u8_path = '_,%s,%s' % (','.join(tbrs), '.mp4')
  112. formats.extend(self._extract_m3u8_formats(
  113. 'http://balancer-vod.1tv.ru/%s%s.urlset/master.m3u8'
  114. % (path, m3u8_path),
  115. display_id, 'mp4',
  116. entry_protocol='m3u8_native', m3u8_id='hls', fatal=False))
  117. self._sort_formats(formats)
  118. thumbnail = item.get('poster') or self._og_search_thumbnail(webpage)
  119. duration = int_or_none(item.get('duration') or self._html_search_meta(
  120. 'video:duration', webpage, 'video duration', fatal=False))
  121. upload_date = unified_strdate(self._html_search_meta(
  122. 'ya:ovs:upload_date', webpage, 'upload date', default=None))
  123. entries.append({
  124. 'id': compat_str(item.get('id') or item['uid']),
  125. 'thumbnail': thumbnail,
  126. 'title': title,
  127. 'upload_date': upload_date,
  128. 'duration': int_or_none(duration),
  129. 'formats': formats
  130. })
  131. title = self._html_search_regex(
  132. (r'<div class="tv_translation">\s*<h1><a href="[^"]+">([^<]*)</a>',
  133. r"'title'\s*:\s*'([^']+)'"),
  134. webpage, 'title', default=None) or self._og_search_title(
  135. webpage, default=None)
  136. description = self._html_search_regex(
  137. r'<div class="descr">\s*<div>&nbsp;</div>\s*<p>([^<]*)</p></div>',
  138. webpage, 'description', default=None) or self._html_search_meta(
  139. 'description', webpage, 'description', default=None)
  140. return self.playlist_result(entries, display_id, title, description)