[1tv] Cover arbitraty URLs
[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 = '1tv'
12     IE_DESC = 'Первый канал'
13     _VALID_URL = r'http://(?:www\.)?1tv\.ru/(?:[^/]+/)+(?P<id>.+)'
14
15     _TESTS = [{
16         'url': 'http://www.1tv.ru/videoarchive/73390',
17         'md5': '777f525feeec4806130f4f764bc18a4f',
18         'info_dict': {
19             'id': '73390',
20             'ext': 'mp4',
21             'title': 'Олимпийские канатные дороги',
22             'description': 'md5:d41d8cd98f00b204e9800998ecf8427e',
23             'thumbnail': 're:^https?://.*\.(?:jpg|JPG)$',
24             'duration': 149,
25             'like_count': int,
26             'dislike_count': int,
27         },
28         'skip': 'Only works from Russia',
29     }, {
30         'url': 'http://www.1tv.ru/prj/inprivate/vypusk/35930',
31         'md5': 'a1b6b60d530ebcf8daacf4565762bbaf',
32         'info_dict': {
33             'id': '35930',
34             'ext': 'mp4',
35             'title': 'Наедине со всеми. Людмила Сенчина',
36             'description': 'md5:89553aed1d641416001fe8d450f06cb9',
37             'thumbnail': 're:^https?://.*\.(?:jpg|JPG)$',
38             'duration': 2694,
39         },
40         'skip': 'Only works from Russia',
41     }]
42
43     def _real_extract(self, url):
44         video_id = self._match_id(url)
45
46         webpage = self._download_webpage(url, video_id, 'Downloading page')
47
48         video_url = self._html_search_regex(
49             r'''(?s)(?:jwplayer\('flashvideoportal_1'\)\.setup\({|var\s+playlistObj\s*=).*?'file'\s*:\s*'([^']+)'.*?}\);''',
50             webpage, 'video URL')
51
52         title = self._html_search_regex(
53             [r'<div class="tv_translation">\s*<h1><a href="[^"]+">([^<]*)</a>',
54              r"'title'\s*:\s*'([^']+)'"], webpage, 'title')
55         description = self._html_search_regex(
56             r'<div class="descr">\s*<div>&nbsp;</div>\s*<p>([^<]*)</p></div>',
57             webpage, 'description', default=None) or self._html_search_meta(
58                 'description', webpage, 'description')
59
60         thumbnail = self._og_search_thumbnail(webpage)
61         duration = self._og_search_property(
62             'video:duration', webpage,
63             'video duration', fatal=False)
64
65         like_count = self._html_search_regex(
66             r'title="Понравилось".*?/></label> \[(\d+)\]',
67             webpage, 'like count', default=None)
68         dislike_count = self._html_search_regex(
69             r'title="Не понравилось".*?/></label> \[(\d+)\]',
70             webpage, 'dislike count', default=None)
71
72         return {
73             'id': video_id,
74             'url': video_url,
75             'thumbnail': thumbnail,
76             'title': title,
77             'description': description,
78             'duration': int_or_none(duration),
79             'like_count': int_or_none(like_count),
80             'dislike_count': int_or_none(dislike_count),
81         }