]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/lifenews.py
7b7185f9adb69f37dee1e4c4b468de8a5a95a556
[youtubedl] / 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 (
8 int_or_none,
9 unified_strdate
10 )
11
12
13 class LifeNewsIE(InfoExtractor):
14 IE_NAME = 'lifenews'
15 IE_DESC = 'LIFE | NEWS'
16 _VALID_URL = r'http://lifenews\.ru/(?:mobile/)?news/(?P<id>\d+)'
17
18 _TEST = {
19 'url': 'http://lifenews.ru/news/126342',
20 'md5': 'e1b50a5c5fb98a6a544250f2e0db570a',
21 'info_dict': {
22 'id': '126342',
23 'ext': 'mp4',
24 'title': 'МВД разыскивает мужчин, оставивших в IKEA сумку с автоматом',
25 'description': 'Камеры наблюдения гипермаркета зафиксировали троих мужчин, спрятавших оружейный арсенал в камере хранения.',
26 'thumbnail': 'http://lifenews.ru/static/posts/2014/1/126342/.video.jpg',
27 'upload_date': '20140130',
28 }
29 }
30
31 def _real_extract(self, url):
32 mobj = re.match(self._VALID_URL, url)
33 video_id = mobj.group('id')
34
35 webpage = self._download_webpage('http://lifenews.ru/mobile/news/%s' % video_id, video_id, 'Downloading page')
36
37 video_url = self._html_search_regex(
38 r'<video.*?src="([^"]+)".*?></video>', webpage, 'video URL')
39
40 thumbnail = self._html_search_regex(
41 r'<video.*?poster="([^"]+)".*?"></video>', webpage, 'video thumbnail')
42
43 title = self._og_search_title(webpage)
44 TITLE_SUFFIX = ' - Первый по срочным новостям — LIFE | NEWS'
45 if title.endswith(TITLE_SUFFIX):
46 title = title[:-len(TITLE_SUFFIX)]
47
48 description = self._og_search_description(webpage)
49
50 view_count = self._html_search_regex(
51 r'<div class=\'views\'>(\d+)</div>', webpage, 'view count', fatal=False)
52 comment_count = self._html_search_regex(
53 r'<div class=\'comments\'>(\d+)</div>', webpage, 'comment count', fatal=False)
54
55 upload_date = self._html_search_regex(
56 r'<time datetime=\'([^\']+)\'>', webpage, 'upload date',fatal=False)
57 if upload_date is not None:
58 upload_date = unified_strdate(upload_date)
59
60 return {
61 'id': video_id,
62 'url': video_url,
63 'thumbnail': thumbnail,
64 'title': title,
65 'description': description,
66 'view_count': int_or_none(view_count),
67 'comment_count': int_or_none(comment_count),
68 'upload_date': upload_date,
69 }