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.

128 lines
4.9 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': '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': '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. for f in item.get('mbr', []):
  79. src = f.get('src')
  80. if not src or not isinstance(src, compat_str):
  81. continue
  82. tbr = int_or_none(self._search_regex(
  83. r'_(\d{3,})\.mp4', src, 'tbr', default=None))
  84. formats.append({
  85. 'url': src,
  86. 'format_id': f.get('name'),
  87. 'tbr': tbr,
  88. 'quality': quality(f.get('name')),
  89. })
  90. self._sort_formats(formats)
  91. thumbnail = item.get('poster') or self._og_search_thumbnail(webpage)
  92. duration = int_or_none(item.get('duration') or self._html_search_meta(
  93. 'video:duration', webpage, 'video duration', fatal=False))
  94. upload_date = unified_strdate(self._html_search_meta(
  95. 'ya:ovs:upload_date', webpage, 'upload date', default=None))
  96. entries.append({
  97. 'id': compat_str(item.get('id') or item['uid']),
  98. 'thumbnail': thumbnail,
  99. 'title': title,
  100. 'upload_date': upload_date,
  101. 'duration': int_or_none(duration),
  102. 'formats': formats
  103. })
  104. title = self._html_search_regex(
  105. (r'<div class="tv_translation">\s*<h1><a href="[^"]+">([^<]*)</a>',
  106. r"'title'\s*:\s*'([^']+)'"),
  107. webpage, 'title', default=None) or self._og_search_title(
  108. webpage, default=None)
  109. description = self._html_search_regex(
  110. r'<div class="descr">\s*<div>&nbsp;</div>\s*<p>([^<]*)</p></div>',
  111. webpage, 'description', default=None) or self._html_search_meta(
  112. 'description', webpage, 'description', default=None)
  113. return self.playlist_result(entries, display_id, title, description)