[tvigle] Add age limit
[youtube-dl] / youtube_dl / extractor / tvigle.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     unified_strdate,
9     clean_html,
10     int_or_none,
11 )
12
13
14 class TvigleIE(InfoExtractor):
15     IE_NAME = 'tvigle'
16     IE_DESC = 'Интернет-телевидение Tvigle.ru'
17     _VALID_URL = r'http://(?:www\.)?tvigle\.ru/category/.+?video=(?P<id>\d+)'
18
19     _TEST = {
20         'url': 'http://www.tvigle.ru/category/cinema/1608/?video=503081',
21         'md5': '09afba4616666249f087efc6dcf83cb3',
22         'info_dict': {
23             'id': '503081',
24             'ext': 'flv',
25             'title': 'Брат 2 ',
26             'description': 'md5:f5a42970f50648cee3d7ad740f3ae769',
27             'upload_date': '20110919',
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         video_data = self._download_xml(
36             'http://www.tvigle.ru/xml/single.php?obj=%s' % video_id, video_id, 'Downloading video XML')
37
38         video = video_data.find('./video')
39
40         title = video.get('name')
41         description = video.get('anons')
42         if description:
43             description = clean_html(description)
44         thumbnail = video_data.get('img')
45         upload_date = unified_strdate(video.get('date'))
46         like_count = int_or_none(video.get('vtp'))
47
48         formats = []
49         for num, (format_id, format_note) in enumerate([['low_file', 'SQ'], ['file', 'HQ'], ['hd', 'HD 720']]):
50             video_url = video.get(format_id)
51             if not video_url:
52                 continue
53             formats.append({
54                 'url': video_url,
55                 'format_id': format_id,
56                 'format_note': format_note,
57                 'quality': num,
58             })
59
60         self._sort_formats(formats)
61
62         return {
63             'id': video_id,
64             'title': title,
65             'description': description,
66             'thumbnail': thumbnail,
67             'upload_date': upload_date,
68             'like_count': like_count,
69             'age_limit': 18,
70             'formats': formats,
71         }