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