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.

153 lines
6.2 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. })
  95. # m3u8 URL format is reverse engineered from [1] (search for
  96. # master.m3u8). dashEdges (that is currently balancer-vod.1tv.ru)
  97. # is taken from [2].
  98. # 1. http://static.1tv.ru/player/eump1tv-current/eump-1tv.all.min.js?rnd=9097422834:formatted
  99. # 2. http://static.1tv.ru/player/eump1tv-config/config-main.js?rnd=9097422834
  100. if not path and len(formats) == 1:
  101. path = self._search_regex(
  102. r'//[^/]+/(.+?$)', formats[0]['url'],
  103. 'm3u8 path', default=None)
  104. if path:
  105. if len(formats) == 1:
  106. m3u8_path = ','
  107. else:
  108. tbrs = [compat_str(t) for t in sorted(f['tbr'] for f in formats)]
  109. m3u8_path = '_,%s,%s' % (','.join(tbrs), '.mp4')
  110. formats.extend(self._extract_m3u8_formats(
  111. 'http://balancer-vod.1tv.ru/%s%s.urlset/master.m3u8'
  112. % (path, m3u8_path),
  113. display_id, 'mp4',
  114. entry_protocol='m3u8_native', m3u8_id='hls', fatal=False))
  115. self._sort_formats(formats)
  116. thumbnail = item.get('poster') or self._og_search_thumbnail(webpage)
  117. duration = int_or_none(item.get('duration') or self._html_search_meta(
  118. 'video:duration', webpage, 'video duration', fatal=False))
  119. upload_date = unified_strdate(self._html_search_meta(
  120. 'ya:ovs:upload_date', webpage, 'upload date', default=None))
  121. entries.append({
  122. 'id': compat_str(item.get('id') or item['uid']),
  123. 'thumbnail': thumbnail,
  124. 'title': title,
  125. 'upload_date': upload_date,
  126. 'duration': int_or_none(duration),
  127. 'formats': formats
  128. })
  129. title = self._html_search_regex(
  130. (r'<div class="tv_translation">\s*<h1><a href="[^"]+">([^<]*)</a>',
  131. r"'title'\s*:\s*'([^']+)'"),
  132. webpage, 'title', default=None) or self._og_search_title(
  133. webpage, default=None)
  134. description = self._html_search_regex(
  135. r'<div class="descr">\s*<div>&nbsp;</div>\s*<p>([^<]*)</p></div>',
  136. webpage, 'description', default=None) or self._html_search_meta(
  137. 'description', webpage, 'description', default=None)
  138. return self.playlist_result(entries, display_id, title, description)