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.

103 lines
4.1 KiB

10 years ago
10 years ago
  1. # encoding: 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. unified_strdate,
  8. ExtractorError,
  9. )
  10. class LifeNewsIE(InfoExtractor):
  11. IE_NAME = 'lifenews'
  12. IE_DESC = 'LIFE | NEWS'
  13. _VALID_URL = r'http://lifenews\.ru/(?:mobile/)?news/(?P<id>\d+)'
  14. _TESTS = [{
  15. 'url': 'http://lifenews.ru/news/126342',
  16. 'md5': 'e1b50a5c5fb98a6a544250f2e0db570a',
  17. 'info_dict': {
  18. 'id': '126342',
  19. 'ext': 'mp4',
  20. 'title': 'МВД разыскивает мужчин, оставивших в IKEA сумку с автоматом',
  21. 'description': 'Камеры наблюдения гипермаркета зафиксировали троих мужчин, спрятавших оружейный арсенал в камере хранения.',
  22. 'thumbnail': 're:http://.*\.jpg',
  23. 'upload_date': '20140130',
  24. }
  25. }, {
  26. # video in <iframe>
  27. 'url': 'http://lifenews.ru/news/152125',
  28. 'md5': '77d19a6f0886cd76bdbf44b4d971a273',
  29. 'info_dict': {
  30. 'id': '152125',
  31. 'ext': 'mp4',
  32. 'title': 'В Сети появилось видео захвата «Правым сектором» колхозных полей ',
  33. 'description': 'Жители двух поселков Днепропетровской области не простили радикалам угрозу лишения плодородных земель и пошли в лобовую. ',
  34. 'upload_date': '20150402',
  35. 'uploader': 'embed.life.ru',
  36. }
  37. }]
  38. def _real_extract(self, url):
  39. mobj = re.match(self._VALID_URL, url)
  40. video_id = mobj.group('id')
  41. webpage = self._download_webpage('http://lifenews.ru/news/%s' % video_id, video_id, 'Downloading page')
  42. videos = re.findall(r'<video.*?poster="(?P<poster>[^"]+)".*?src="(?P<video>[^"]+)".*?></video>', webpage)
  43. iframe_link = self._html_search_regex(
  44. '<iframe[^>]+src="([^"]+)', webpage, 'iframe link', default=None)
  45. if not videos and not iframe_link:
  46. raise ExtractorError('No media links available for %s' % video_id)
  47. title = self._og_search_title(webpage)
  48. TITLE_SUFFIX = ' - Первый по срочным новостям — LIFE | NEWS'
  49. if title.endswith(TITLE_SUFFIX):
  50. title = title[:-len(TITLE_SUFFIX)]
  51. description = self._og_search_description(webpage)
  52. view_count = self._html_search_regex(
  53. r'<div class=\'views\'>\s*(\d+)\s*</div>', webpage, 'view count', fatal=False)
  54. comment_count = self._html_search_regex(
  55. r'<div class=\'comments\'>\s*<span class=\'counter\'>\s*(\d+)\s*</span>', webpage, 'comment count', fatal=False)
  56. upload_date = self._html_search_regex(
  57. r'<time datetime=\'([^\']+)\'>', webpage, 'upload date', fatal=False)
  58. if upload_date is not None:
  59. upload_date = unified_strdate(upload_date)
  60. common_info = {
  61. 'description': description,
  62. 'view_count': int_or_none(view_count),
  63. 'comment_count': int_or_none(comment_count),
  64. 'upload_date': upload_date,
  65. }
  66. def make_entry(video_id, media, video_number=None):
  67. cur_info = dict(common_info)
  68. cur_info.update({
  69. 'id': video_id,
  70. 'url': media[1],
  71. 'thumbnail': media[0],
  72. 'title': title if video_number is None else '%s-video%s' % (title, video_number),
  73. })
  74. return cur_info
  75. if iframe_link:
  76. cur_info = dict(common_info)
  77. cur_info.update({
  78. '_type': 'url_transparent',
  79. 'id': video_id,
  80. 'title': title,
  81. 'url': iframe_link,
  82. })
  83. return cur_info
  84. if len(videos) == 1:
  85. return make_entry(video_id, videos[0])
  86. else:
  87. return [make_entry(video_id, media, video_number + 1) for video_number, media in enumerate(videos)]