]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/lifenews.py
[dailymotion] Use https urls
[yt-dlp.git] / youtube_dl / extractor / lifenews.py
CommitLineData
659aa21b 1# encoding: utf-8
2from __future__ import unicode_literals
3
4import re
5
6from .common import InfoExtractor
bcb891e8
S
7from ..utils import (
8 int_or_none,
fc26f3b4
S
9 unified_strdate,
10 ExtractorError,
bcb891e8 11)
659aa21b 12
13
14class LifeNewsIE(InfoExtractor):
15 IE_NAME = 'lifenews'
16 IE_DESC = 'LIFE | NEWS'
17 _VALID_URL = r'http://lifenews\.ru/(?:mobile/)?news/(?P<id>\d+)'
bcb891e8 18
659aa21b 19 _TEST = {
20 'url': 'http://lifenews.ru/news/126342',
659aa21b 21 'md5': 'e1b50a5c5fb98a6a544250f2e0db570a',
22 'info_dict': {
bcb891e8
S
23 'id': '126342',
24 'ext': 'mp4',
6d845922 25 'title': 'МВД разыскивает мужчин, оставивших в IKEA сумку с автоматом',
659aa21b 26 'description': 'Камеры наблюдения гипермаркета зафиксировали троих мужчин, спрятавших оружейный арсенал в камере хранения.',
896bf553 27 'thumbnail': 're:http://.*\.jpg',
659aa21b 28 'upload_date': '20140130',
29 }
30 }
31
32 def _real_extract(self, url):
33 mobj = re.match(self._VALID_URL, url)
34 video_id = mobj.group('id')
35
1877a140 36 webpage = self._download_webpage('http://lifenews.ru/news/%s' % video_id, video_id, 'Downloading page')
659aa21b 37
fc26f3b4
S
38 videos = re.findall(r'<video.*?poster="(?P<poster>[^"]+)".*?src="(?P<video>[^"]+)".*?></video>', webpage)
39 if not videos:
40 raise ExtractorError('No media links available for %s' % video_id)
659aa21b 41
42 title = self._og_search_title(webpage)
43 TITLE_SUFFIX = ' - Первый по срочным новостям — LIFE | NEWS'
44 if title.endswith(TITLE_SUFFIX):
45 title = title[:-len(TITLE_SUFFIX)]
46
47 description = self._og_search_description(webpage)
48
49 view_count = self._html_search_regex(
bcb891e8 50 r'<div class=\'views\'>(\d+)</div>', webpage, 'view count', fatal=False)
659aa21b 51 comment_count = self._html_search_regex(
1877a140 52 r'<div class=\'comments\'>\s*<span class=\'counter\'>(\d+)</span>', webpage, 'comment count', fatal=False)
659aa21b 53
54 upload_date = self._html_search_regex(
5f6a1245 55 r'<time datetime=\'([^\']+)\'>', webpage, 'upload date', fatal=False)
bcb891e8
S
56 if upload_date is not None:
57 upload_date = unified_strdate(upload_date)
659aa21b 58
fc26f3b4
S
59 def make_entry(video_id, media, video_number=None):
60 return {
61 'id': video_id,
62 'url': media[1],
63 'thumbnail': media[0],
64 'title': title if video_number is None else '%s-video%s' % (title, video_number),
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 }
70
71 if len(videos) == 1:
72 return make_entry(video_id, videos[0])
73 else:
2514d263 74 return [make_entry(video_id, media, video_number + 1) for video_number, media in enumerate(videos)]