]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/tvigle.py
debian/watch: Make use of the signing key from upstream.
[youtubedl] / 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/.+?[\?&]v(?:ideo)?=(?P<id>\d+)'
18
19 _TESTS = [
20 {
21 'url': 'http://www.tvigle.ru/category/cinema/1608/?video=503081',
22 'md5': '09afba4616666249f087efc6dcf83cb3',
23 'info_dict': {
24 'id': '503081',
25 'ext': 'flv',
26 'title': 'Брат 2 ',
27 'description': 'md5:f5a42970f50648cee3d7ad740f3ae769',
28 'upload_date': '20110919',
29 },
30 },
31 {
32 'url': 'http://www.tvigle.ru/category/men/vysotskiy_vospominaniya02/?flt=196&v=676433',
33 'md5': 'e7efe5350dd5011d0de6550b53c3ba7b',
34 'info_dict': {
35 'id': '676433',
36 'ext': 'flv',
37 'title': 'Ведущий телепрограммы «60 минут» (США) о Владимире Высоцком',
38 'description': 'md5:027f7dc872948f14c96d19b4178428a4',
39 'upload_date': '20121218',
40 },
41 },
42 ]
43
44 def _real_extract(self, url):
45 mobj = re.match(self._VALID_URL, url)
46 video_id = mobj.group('id')
47
48 video_data = self._download_xml(
49 'http://www.tvigle.ru/xml/single.php?obj=%s' % video_id, video_id, 'Downloading video XML')
50
51 video = video_data.find('./video')
52
53 title = video.get('name')
54 description = video.get('anons')
55 if description:
56 description = clean_html(description)
57 thumbnail = video_data.get('img')
58 upload_date = unified_strdate(video.get('date'))
59 like_count = int_or_none(video.get('vtp'))
60
61 formats = []
62 for num, (format_id, format_note) in enumerate([['low_file', 'SQ'], ['file', 'HQ'], ['hd', 'HD 720']]):
63 video_url = video.get(format_id)
64 if not video_url:
65 continue
66 formats.append({
67 'url': video_url,
68 'format_id': format_id,
69 'format_note': format_note,
70 'quality': num,
71 })
72
73 self._sort_formats(formats)
74
75 return {
76 'id': video_id,
77 'title': title,
78 'description': description,
79 'thumbnail': thumbnail,
80 'upload_date': upload_date,
81 'like_count': like_count,
82 'age_limit': 18,
83 'formats': formats,
84 }