[firsttv] Fix video URL regex
[youtube-dl] / youtube_dl / extractor / firsttv.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 int_or_none
8
9
10 class FirstTVIE(InfoExtractor):
11     IE_NAME = 'firsttv'
12     IE_DESC = 'Видеоархив - Первый канал'
13     _VALID_URL = r'http://(?:www\.)?1tv\.ru/videoarchive/(?P<id>\d+)'
14
15     _TEST = {
16         'url': 'http://www.1tv.ru/videoarchive/73390',
17         'md5': '3de6390cf0cca4a5eae1d1d83895e5ad',
18         'info_dict': {
19             'id': '73390',
20             'ext': 'mp4',
21             'title': 'Олимпийские канатные дороги',
22             'description': 'md5:cc730d2bf4215463e37fff6a1e277b13',
23             'thumbnail': 'http://img1.1tv.ru/imgsize640x360/PR20140210114657.JPG',
24             'duration': 149,
25         }
26     }
27
28     def _real_extract(self, url):
29         mobj = re.match(self._VALID_URL, url)
30         video_id = mobj.group('id')
31
32         webpage = self._download_webpage(url, video_id, 'Downloading page')
33
34         video_url = self._html_search_regex(
35             r'''(?s)jwplayer\('flashvideoportal_1'\)\.setup\({.*?'file': '([^']+)'.*?}\);''', webpage, 'video URL')
36
37         title = self._html_search_regex(
38             r'<div class="tv_translation">\s*<h1><a href="[^"]+">([^<]*)</a>', webpage, 'title')
39         description = self._html_search_regex(
40             r'<div class="descr">\s*<div>&nbsp;</div>\s*<p>([^<]*)</p></div>', webpage, 'description', fatal=False)
41
42         thumbnail = self._og_search_thumbnail(webpage)
43         duration = self._og_search_property('video:duration', webpage, 'video duration', fatal=False)
44
45         like_count = self._html_search_regex(r'title="Понравилось".*?/></label> \[(\d+)\]',
46             webpage, 'like count', fatal=False)
47         dislike_count = self._html_search_regex(r'title="Не понравилось".*?/></label> \[(\d+)\]',
48             webpage, 'dislike count', fatal=False)
49
50         return {
51             'id': video_id,
52             'url': video_url,
53             'thumbnail': thumbnail,
54             'title': title,
55             'description': description,
56             'duration': int_or_none(duration),
57             'like_count': int_or_none(like_count),
58             'dislike_count': int_or_none(dislike_count),
59         }