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.

134 lines
5.1 KiB

10 years ago
  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import compat_xpath
  5. from ..utils import (
  6. int_or_none,
  7. qualities,
  8. unified_strdate,
  9. xpath_attr,
  10. xpath_element,
  11. xpath_text,
  12. xpath_with_ns,
  13. )
  14. class FirstTVIE(InfoExtractor):
  15. IE_NAME = '1tv'
  16. IE_DESC = 'Первый канал'
  17. _VALID_URL = r'https?://(?:www\.)?1tv\.ru/(?:[^/]+/)+p?(?P<id>\d+)'
  18. _TESTS = [{
  19. # single format via video_materials.json API
  20. 'url': 'http://www.1tv.ru/prj/inprivate/vypusk/35930',
  21. 'md5': '82a2777648acae812d58b3f5bd42882b',
  22. 'info_dict': {
  23. 'id': '35930',
  24. 'ext': 'mp4',
  25. 'title': 'Гость Людмила Сенчина. Наедине со всеми. Выпуск от 12.02.2015',
  26. 'description': 'md5:357933adeede13b202c7c21f91b871b2',
  27. 'thumbnail': 're:^https?://.*\.(?:jpg|JPG)$',
  28. 'upload_date': '20150212',
  29. 'duration': 2694,
  30. },
  31. }, {
  32. # multiple formats via video_materials.json API
  33. 'url': 'http://www.1tv.ru/video_archive/projects/dobroeutro/p113641',
  34. 'info_dict': {
  35. 'id': '113641',
  36. 'ext': 'mp4',
  37. 'title': 'Весенняя аллергия. Доброе утро. Фрагмент выпуска от 07.04.2016',
  38. 'description': 'md5:8dcebb3dded0ff20fade39087fd1fee2',
  39. 'thumbnail': 're:^https?://.*\.(?:jpg|JPG)$',
  40. 'upload_date': '20160407',
  41. 'duration': 179,
  42. 'formats': 'mincount:3',
  43. },
  44. 'params': {
  45. 'skip_download': True,
  46. },
  47. }, {
  48. # single format only available via ONE_ONLINE_VIDEOS.archive_single_xml API
  49. 'url': 'http://www.1tv.ru/video_archive/series/f7552/p47038',
  50. 'md5': '519d306c5b5669761fd8906c39dbee23',
  51. 'info_dict': {
  52. 'id': '47038',
  53. 'ext': 'mp4',
  54. 'title': '"Побег". Второй сезон. 3 серия',
  55. 'description': 'md5:3abf8f6b9bce88201c33e9a3d794a00b',
  56. 'thumbnail': 're:^https?://.*\.(?:jpg|JPG)$',
  57. 'upload_date': '20120516',
  58. 'duration': 3080,
  59. },
  60. }, {
  61. 'url': 'http://www.1tv.ru/videoarchive/9967',
  62. 'only_matching': True,
  63. }]
  64. def _real_extract(self, url):
  65. video_id = self._match_id(url)
  66. # Videos with multiple formats only available via this API
  67. video = self._download_json(
  68. 'http://www.1tv.ru/video_materials.json?legacy_id=%s' % video_id,
  69. video_id, fatal=False)
  70. description, thumbnail, upload_date, duration = [None] * 4
  71. if video:
  72. item = video[0]
  73. title = item['title']
  74. quality = qualities(('ld', 'sd', 'hd', ))
  75. formats = [{
  76. 'url': f['src'],
  77. 'format_id': f.get('name'),
  78. 'quality': quality(f.get('name')),
  79. } for f in item['mbr'] if f.get('src')]
  80. thumbnail = item.get('poster')
  81. else:
  82. # Some videos are not available via video_materials.json
  83. video = self._download_xml(
  84. 'http://www.1tv.ru/owa/win/ONE_ONLINE_VIDEOS.archive_single_xml?pid=%s' % video_id,
  85. video_id)
  86. NS_MAP = {
  87. 'media': 'http://search.yahoo.com/mrss/',
  88. }
  89. item = xpath_element(video, './channel/item', fatal=True)
  90. title = xpath_text(item, './title', fatal=True)
  91. formats = [{
  92. 'url': content.attrib['url'],
  93. } for content in item.findall(
  94. compat_xpath(xpath_with_ns('./media:content', NS_MAP))) if content.attrib.get('url')]
  95. thumbnail = xpath_attr(
  96. item, xpath_with_ns('./media:thumbnail', NS_MAP), 'url')
  97. self._sort_formats(formats)
  98. webpage = self._download_webpage(url, video_id, 'Downloading page', fatal=False)
  99. if webpage:
  100. title = self._html_search_regex(
  101. (r'<div class="tv_translation">\s*<h1><a href="[^"]+">([^<]*)</a>',
  102. r"'title'\s*:\s*'([^']+)'"),
  103. webpage, 'title', default=None) or title
  104. description = self._html_search_regex(
  105. r'<div class="descr">\s*<div>&nbsp;</div>\s*<p>([^<]*)</p></div>',
  106. webpage, 'description', default=None) or self._html_search_meta(
  107. 'description', webpage, 'description')
  108. thumbnail = thumbnail or self._og_search_thumbnail(webpage)
  109. duration = int_or_none(self._html_search_meta(
  110. 'video:duration', webpage, 'video duration', fatal=False))
  111. upload_date = unified_strdate(self._html_search_meta(
  112. 'ya:ovs:upload_date', webpage, 'upload date', fatal=False))
  113. return {
  114. 'id': video_id,
  115. 'thumbnail': thumbnail,
  116. 'title': title,
  117. 'description': description,
  118. 'upload_date': upload_date,
  119. 'duration': int_or_none(duration),
  120. 'formats': formats
  121. }