2 from __future__ 
import unicode_literals
 
   6 from .common 
import InfoExtractor
 
   7 from ..compat 
import compat_urlparse
 
  16 class LifeNewsIE(InfoExtractor
): 
  18     IE_DESC 
= 'LIFE | NEWS' 
  19     _VALID_URL 
= r
'http://lifenews\.ru/(?:mobile/)?(?P<section>news|video)/(?P<id>\d+)' 
  22         'url': 'http://lifenews.ru/news/126342', 
  23         'md5': 'e1b50a5c5fb98a6a544250f2e0db570a', 
  27             'title': 'МВД разыскивает мужчин, оставивших в IKEA сумку с автоматом', 
  28             'description': 'Камеры наблюдения гипермаркета зафиксировали троих мужчин, спрятавших оружейный арсенал в камере хранения.', 
  29             'thumbnail': 're:http://.*\.jpg', 
  30             'upload_date': '20140130', 
  34         'url': 'http://lifenews.ru/news/152125', 
  35         'md5': '77d19a6f0886cd76bdbf44b4d971a273', 
  39             'title': 'В Сети появилось видео захвата «Правым сектором» колхозных полей ', 
  40             'description': 'Жители двух поселков Днепропетровской области не простили радикалам угрозу лишения плодородных земель и пошли в лобовую. ', 
  41             'upload_date': '20150402', 
  42             'uploader': 'embed.life.ru', 
  45         'url': 'http://lifenews.ru/news/153461', 
  46         'md5': '9b6ef8bc0ffa25aebc8bdb40d89ab795', 
  50             'title': 'В Москве спасли потерявшегося медвежонка, который спрятался на дереве', 
  51             'description': 'Маленький хищник не смог найти дорогу домой и обрел временное убежище на тополе недалеко от жилого массива, пока его не нашла соседская собака.', 
  52             'upload_date': '20150505', 
  53             'uploader': 'embed.life.ru', 
  56         'url': 'http://lifenews.ru/video/13035', 
  57         'only_matching': True, 
  60     def _real_extract(self
, url
): 
  61         mobj 
= re
.match(self
._VALID
_URL
, url
) 
  62         video_id 
= mobj
.group('id') 
  63         section 
= mobj
.group('section') 
  65         webpage 
= self
._download
_webpage
( 
  66             'http://lifenews.ru/%s/%s' % (section
, video_id
), 
  67             video_id
, 'Downloading page') 
  69         videos 
= re
.findall(r
'<video.*?poster="(?P<poster>[^"]+)".*?src="(?P<video>[^"]+)".*?></video>', webpage
) 
  70         iframe_link 
= self
._html
_search
_regex
( 
  71             '<iframe[^>]+src=["\']([^"\']+)["\']', webpage
, 'iframe link', default
=None) 
  72         if not videos 
and not iframe_link
: 
  73             raise ExtractorError('No media links available for %s' % video_id
) 
  75         title 
= self
._og
_search
_title
(webpage
) 
  76         TITLE_SUFFIX 
= ' - Первый по срочным новостям — LIFE | NEWS' 
  77         if title
.endswith(TITLE_SUFFIX
): 
  78             title 
= title
[:-len(TITLE_SUFFIX
)] 
  80         description 
= self
._og
_search
_description
(webpage
) 
  82         view_count 
= self
._html
_search
_regex
( 
  83             r
'<div class=\'views
\'>\s
*(\d
+)\s
*</div
>', webpage, 'view count
', fatal=False) 
  84         comment_count = self._html_search_regex( 
  85             r'<div 
class=\'comments
\'>\s
*<span 
class=\'counter
\'>\s
*(\d
+)\s
*</span
>', webpage, 'comment count
', fatal=False) 
  87         upload_date = self._html_search_regex( 
  88             r'<time datetime
=\'([^
\']+)\'>', webpage, 'upload date
', fatal=False) 
  89         if upload_date is not None: 
  90             upload_date = unified_strdate(upload_date) 
  93             'description
': description, 
  94             'view_count
': int_or_none(view_count), 
  95             'comment_count
': int_or_none(comment_count), 
  96             'upload_date
': upload_date, 
  99         def make_entry(video_id, media, video_number=None): 
 100             cur_info = dict(common_info) 
 104                 'thumbnail
': media[0], 
 105                 'title
': title if video_number is None else '%s-video
%s' % (title, video_number), 
 110             iframe_link = self._proto_relative_url(iframe_link, 'http
:') 
 111             cur_info = dict(common_info) 
 113                 '_type
': 'url_transparent
', 
 121             return make_entry(video_id, videos[0]) 
 123             return [make_entry(video_id, media, video_number + 1) for video_number, media in enumerate(videos)] 
 126 class LifeEmbedIE(InfoExtractor): 
 127     IE_NAME = 'life
:embed
' 
 128     _VALID_URL = r'http
://embed\
.life\
.ru
/embed
/(?P
<id>[\da
-f
]{32}
)' 
 131         'url
': 'http
://embed
.life
.ru
/embed
/e50c2dec2867350528e2574c899b8291
', 
 132         'md5
': 'b889715c9e49cb1981281d0e5458fbbe
', 
 134             'id': 'e50c2dec2867350528e2574c899b8291
', 
 136             'title
': 'e50c2dec2867350528e2574c899b8291
', 
 137             'thumbnail
': 're
:http
://.*\
.jpg
', 
 141     def _real_extract(self, url): 
 142         video_id = self._match_id(url) 
 144         webpage = self._download_webpage(url, video_id) 
 147         for video_url in re.findall(r'"file"\s
*:\s
*"([^"]+)', webpage): 
 148             video_url = compat_urlparse.urljoin(url, video_url) 
 149             ext = determine_ext(video_url) 
 151                 formats.extend(self._extract_m3u8_formats( 
 152                     video_url, video_id, 'mp4
', m3u8_id='m3u8
')) 
 159         self._sort_formats(formats) 
 161         thumbnail = self._search_regex( 
 162             r'"image"\s
*:\s
*"([^"]+)', webpage, 'thumbnail
', default=None) 
 167             'thumbnail
': thumbnail,