]>
Commit | Line | Data |
---|---|---|
659aa21b | 1 | # encoding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import re | |
5 | ||
6 | from .common import InfoExtractor | |
75427031 | 7 | from ..compat import compat_urlparse |
bcb891e8 | 8 | from ..utils import ( |
75427031 | 9 | determine_ext, |
bcb891e8 | 10 | int_or_none, |
062a3fdf | 11 | remove_end, |
fc26f3b4 S |
12 | unified_strdate, |
13 | ExtractorError, | |
bcb891e8 | 14 | ) |
659aa21b | 15 | |
16 | ||
17 | class LifeNewsIE(InfoExtractor): | |
18 | IE_NAME = 'lifenews' | |
19 | IE_DESC = 'LIFE | NEWS' | |
48006517 | 20 | _VALID_URL = r'http://lifenews\.ru/(?:mobile/)?(?P<section>news|video)/(?P<id>\d+)' |
bcb891e8 | 21 | |
848edeab | 22 | _TESTS = [{ |
659aa21b | 23 | 'url': 'http://lifenews.ru/news/126342', |
659aa21b | 24 | 'md5': 'e1b50a5c5fb98a6a544250f2e0db570a', |
25 | 'info_dict': { | |
bcb891e8 S |
26 | 'id': '126342', |
27 | 'ext': 'mp4', | |
6d845922 | 28 | 'title': 'МВД разыскивает мужчин, оставивших в IKEA сумку с автоматом', |
659aa21b | 29 | 'description': 'Камеры наблюдения гипермаркета зафиксировали троих мужчин, спрятавших оружейный арсенал в камере хранения.', |
896bf553 | 30 | 'thumbnail': 're:http://.*\.jpg', |
659aa21b | 31 | 'upload_date': '20140130', |
32 | } | |
848edeab YCH |
33 | }, { |
34 | # video in <iframe> | |
35 | 'url': 'http://lifenews.ru/news/152125', | |
36 | 'md5': '77d19a6f0886cd76bdbf44b4d971a273', | |
37 | 'info_dict': { | |
38 | 'id': '152125', | |
39 | 'ext': 'mp4', | |
40 | 'title': 'В Сети появилось видео захвата «Правым сектором» колхозных полей ', | |
41 | 'description': 'Жители двух поселков Днепропетровской области не простили радикалам угрозу лишения плодородных земель и пошли в лобовую. ', | |
42 | 'upload_date': '20150402', | |
848edeab | 43 | } |
07d2921c YCH |
44 | }, { |
45 | 'url': 'http://lifenews.ru/news/153461', | |
46 | 'md5': '9b6ef8bc0ffa25aebc8bdb40d89ab795', | |
47 | 'info_dict': { | |
48 | 'id': '153461', | |
49 | 'ext': 'mp4', | |
50 | 'title': 'В Москве спасли потерявшегося медвежонка, который спрятался на дереве', | |
51 | 'description': 'Маленький хищник не смог найти дорогу домой и обрел временное убежище на тополе недалеко от жилого массива, пока его не нашла соседская собака.', | |
52 | 'upload_date': '20150505', | |
07d2921c | 53 | } |
057ebeac S |
54 | }, { |
55 | 'url': 'http://lifenews.ru/video/13035', | |
56 | 'only_matching': True, | |
848edeab | 57 | }] |
659aa21b | 58 | |
59 | def _real_extract(self, url): | |
60 | mobj = re.match(self._VALID_URL, url) | |
61 | video_id = mobj.group('id') | |
48006517 | 62 | section = mobj.group('section') |
659aa21b | 63 | |
48006517 S |
64 | webpage = self._download_webpage( |
65 | 'http://lifenews.ru/%s/%s' % (section, video_id), | |
66 | video_id, 'Downloading page') | |
659aa21b | 67 | |
fc26f3b4 | 68 | videos = re.findall(r'<video.*?poster="(?P<poster>[^"]+)".*?src="(?P<video>[^"]+)".*?></video>', webpage) |
848edeab | 69 | iframe_link = self._html_search_regex( |
48006517 | 70 | '<iframe[^>]+src=["\']([^"\']+)["\']', webpage, 'iframe link', default=None) |
848edeab | 71 | if not videos and not iframe_link: |
fc26f3b4 | 72 | raise ExtractorError('No media links available for %s' % video_id) |
659aa21b | 73 | |
062a3fdf S |
74 | title = remove_end( |
75 | self._og_search_title(webpage), | |
76 | ' - Первый по срочным новостям — LIFE | NEWS') | |
659aa21b | 77 | |
78 | description = self._og_search_description(webpage) | |
79 | ||
80 | view_count = self._html_search_regex( | |
1748d67a | 81 | r'<div class=\'views\'>\s*(\d+)\s*</div>', webpage, 'view count', fatal=False) |
659aa21b | 82 | comment_count = self._html_search_regex( |
028a33d7 S |
83 | r'=\'commentCount\'[^>]*>\s*(\d+)\s*<', |
84 | webpage, 'comment count', fatal=False) | |
659aa21b | 85 | |
86 | upload_date = self._html_search_regex( | |
028a33d7 | 87 | r'<time[^>]*datetime=\'([^\']+)\'', webpage, 'upload date', fatal=False) |
bcb891e8 S |
88 | if upload_date is not None: |
89 | upload_date = unified_strdate(upload_date) | |
659aa21b | 90 | |
848edeab YCH |
91 | common_info = { |
92 | 'description': description, | |
93 | 'view_count': int_or_none(view_count), | |
94 | 'comment_count': int_or_none(comment_count), | |
95 | 'upload_date': upload_date, | |
96 | } | |
97 | ||
fc26f3b4 | 98 | def make_entry(video_id, media, video_number=None): |
848edeab YCH |
99 | cur_info = dict(common_info) |
100 | cur_info.update({ | |
fc26f3b4 S |
101 | 'id': video_id, |
102 | 'url': media[1], | |
103 | 'thumbnail': media[0], | |
104 | 'title': title if video_number is None else '%s-video%s' % (title, video_number), | |
848edeab YCH |
105 | }) |
106 | return cur_info | |
107 | ||
108 | if iframe_link: | |
b326b07a | 109 | iframe_link = self._proto_relative_url(iframe_link, 'http:') |
848edeab YCH |
110 | cur_info = dict(common_info) |
111 | cur_info.update({ | |
112 | '_type': 'url_transparent', | |
113 | 'id': video_id, | |
114 | 'title': title, | |
115 | 'url': iframe_link, | |
116 | }) | |
117 | return cur_info | |
fc26f3b4 S |
118 | |
119 | if len(videos) == 1: | |
120 | return make_entry(video_id, videos[0]) | |
121 | else: | |
2514d263 | 122 | return [make_entry(video_id, media, video_number + 1) for video_number, media in enumerate(videos)] |
75427031 S |
123 | |
124 | ||
125 | class LifeEmbedIE(InfoExtractor): | |
126 | IE_NAME = 'life:embed' | |
127 | _VALID_URL = r'http://embed\.life\.ru/embed/(?P<id>[\da-f]{32})' | |
128 | ||
129 | _TEST = { | |
130 | 'url': 'http://embed.life.ru/embed/e50c2dec2867350528e2574c899b8291', | |
131 | 'md5': 'b889715c9e49cb1981281d0e5458fbbe', | |
132 | 'info_dict': { | |
133 | 'id': 'e50c2dec2867350528e2574c899b8291', | |
134 | 'ext': 'mp4', | |
135 | 'title': 'e50c2dec2867350528e2574c899b8291', | |
136 | 'thumbnail': 're:http://.*\.jpg', | |
137 | } | |
138 | } | |
139 | ||
140 | def _real_extract(self, url): | |
141 | video_id = self._match_id(url) | |
142 | ||
143 | webpage = self._download_webpage(url, video_id) | |
144 | ||
145 | formats = [] | |
146 | for video_url in re.findall(r'"file"\s*:\s*"([^"]+)', webpage): | |
147 | video_url = compat_urlparse.urljoin(url, video_url) | |
148 | ext = determine_ext(video_url) | |
149 | if ext == 'm3u8': | |
150 | formats.extend(self._extract_m3u8_formats( | |
151 | video_url, video_id, 'mp4', m3u8_id='m3u8')) | |
152 | else: | |
153 | formats.append({ | |
154 | 'url': video_url, | |
155 | 'format_id': ext, | |
156 | 'preference': 1, | |
157 | }) | |
95eb1add | 158 | self._sort_formats(formats) |
75427031 S |
159 | |
160 | thumbnail = self._search_regex( | |
161 | r'"image"\s*:\s*"([^"]+)', webpage, 'thumbnail', default=None) | |
162 | ||
163 | return { | |
164 | 'id': video_id, | |
165 | 'title': video_id, | |
166 | 'thumbnail': thumbnail, | |
167 | 'formats': formats, | |
168 | } |