]> jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/lifenews.py
[lifenews] Add support for lifenews.ru
[yt-dlp.git] / youtube_dl / extractor / lifenews.py
1 # encoding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import unified_strdate
8
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
15 _TEST = {
16 'url': 'http://lifenews.ru/news/126342',
17 'file': '126342.mp4',
18 'md5': 'e1b50a5c5fb98a6a544250f2e0db570a',
19 'info_dict': {
20 'title': 'МВД разыскивает троих мужчин, оставивших в IKEA сумку с автоматом',
21 'description': 'Камеры наблюдения гипермаркета зафиксировали троих мужчин, спрятавших оружейный арсенал в камере хранения.',
22 'thumbnail': 'http://lifenews.ru/static/posts/2014/1/126342/.video.jpg',
23 'upload_date': '20140130',
24 }
25 }
26
27 def _real_extract(self, url):
28 mobj = re.match(self._VALID_URL, url)
29 video_id = mobj.group('id')
30
31 webpage = self._download_webpage('http://lifenews.ru/mobile/news/%s' % video_id, video_id, 'Downloading page')
32
33 video_url = self._html_search_regex(
34 r'<video.*?src="([^"]+)"></video>', webpage, 'video URL')
35
36 thumbnail = self._html_search_regex(
37 r'<video.*?poster="([^"]+)".*?"></video>', webpage, 'video thumbnail')
38
39 title = self._og_search_title(webpage)
40 TITLE_SUFFIX = ' - Первый по срочным новостям — LIFE | NEWS'
41 if title.endswith(TITLE_SUFFIX):
42 title = title[:-len(TITLE_SUFFIX)]
43
44 description = self._og_search_description(webpage)
45
46 view_count = self._html_search_regex(
47 r'<div class=\'views\'>(\d+)</div>', webpage, 'view count')
48 comment_count = self._html_search_regex(
49 r'<div class=\'comments\'>(\d+)</div>', webpage, 'comment count')
50
51 upload_date = self._html_search_regex(
52 r'<time datetime=\'([^\']+)\'>', webpage, 'upload date')
53
54 return {
55 'id': video_id,
56 'url': video_url,
57 'thumbnail': thumbnail,
58 'title': title,
59 'description': description,
60 'view_count': view_count,
61 'comment_count': comment_count,
62 'upload_date': unified_strdate(upload_date),
63 }