]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/tvigle.py
[vgtv] Improve HLS formats extraction
[yt-dlp.git] / youtube_dl / extractor / tvigle.py
CommitLineData
dcdb292f 1# coding: utf-8
fb8b8fdd
S
2from __future__ import unicode_literals
3
7f2a9f1b
S
4import re
5
fb8b8fdd
S
6from .common import InfoExtractor
7from ..utils import (
15b74b94 8 ExtractorError,
884ae747 9 float_or_none,
eb47569f 10 int_or_none,
819039ee 11 parse_age_limit,
fb8b8fdd
S
12)
13
14
15class TvigleIE(InfoExtractor):
16 IE_NAME = 'tvigle'
17 IE_DESC = 'Интернет-телевидение Tvigle.ru'
7f2a9f1b 18 _VALID_URL = r'https?://(?:www\.)?(?:tvigle\.ru/(?:[^/]+/)+(?P<display_id>[^/]+)/$|cloud\.tvigle\.ru/video/(?P<id>\d+))'
c7095dad 19
b3aec476
S
20 _GEO_BYPASS = False
21 _GEO_COUNTRIES = ['RU']
22
c7095dad
S
23 _TESTS = [
24 {
819039ee
S
25 'url': 'http://www.tvigle.ru/video/sokrat/',
26 'md5': '36514aed3657d4f70b4b2cef8eb520cd',
c7095dad 27 'info_dict': {
819039ee
S
28 'id': '1848932',
29 'display_id': 'sokrat',
30 'ext': 'flv',
31 'title': 'Сократ',
eb47569f 32 'description': 'md5:d6b92ffb7217b4b8ebad2e7665253c17',
819039ee 33 'duration': 6586,
eb47569f 34 'age_limit': 12,
c7095dad 35 },
3153a2c9 36 'skip': 'georestricted',
c7095dad
S
37 },
38 {
884ae747 39 'url': 'http://www.tvigle.ru/video/vladimir-vysotskii/vedushchii-teleprogrammy-60-minut-ssha-o-vladimire-vysotskom/',
eb47569f 40 'md5': 'e7efe5350dd5011d0de6550b53c3ba7b',
c7095dad 41 'info_dict': {
884ae747 42 'id': '5142516',
eb47569f 43 'ext': 'flv',
c7095dad
S
44 'title': 'Ведущий телепрограммы «60 минут» (США) о Владимире Высоцком',
45 'description': 'md5:027f7dc872948f14c96d19b4178428a4',
884ae747
S
46 'duration': 186.080,
47 'age_limit': 0,
c7095dad 48 },
3153a2c9 49 'skip': 'georestricted',
7f2a9f1b
S
50 }, {
51 'url': 'https://cloud.tvigle.ru/video/5267604/',
52 'only_matching': True,
53 }
c7095dad 54 ]
fb8b8fdd
S
55
56 def _real_extract(self, url):
7f2a9f1b
S
57 mobj = re.match(self._VALID_URL, url)
58 video_id = mobj.group('id')
59 display_id = mobj.group('display_id')
fb8b8fdd 60
7f2a9f1b
S
61 if not video_id:
62 webpage = self._download_webpage(url, display_id)
63 video_id = self._html_search_regex(
12a51345
S
64 (r'<div[^>]+class=["\']player["\'][^>]+id=["\'](\d+)',
65 r'var\s+cloudId\s*=\s*["\'](\d+)',
66 r'class="video-preview current_playing" id="(\d+)"'),
7f2a9f1b 67 webpage, 'video id')
fb8b8fdd 68
884ae747
S
69 video_data = self._download_json(
70 'http://cloud.tvigle.ru/api/play/video/%s/' % video_id, display_id)
fb8b8fdd 71
884ae747
S
72 item = video_data['playlist']['items'][0]
73
15b74b94
S
74 videos = item.get('videos')
75
76 error_message = item.get('errorMessage')
77 if not videos and error_message:
b3aec476
S
78 if item.get('isGeoBlocked') is True:
79 self.raise_geo_restricted(
80 msg=error_message, countries=self._GEO_COUNTRIES)
81 else:
82 raise ExtractorError(
83 '%s returned error: %s' % (self.IE_NAME, error_message),
84 expected=True)
15b74b94 85
884ae747 86 title = item['title']
7584e38c
S
87 description = item.get('description')
88 thumbnail = item.get('thumbnail')
819039ee
S
89 duration = float_or_none(item.get('durationMilliseconds'), 1000)
90 age_limit = parse_age_limit(item.get('ageRestrictions'))
fb8b8fdd 91
884ae747
S
92 formats = []
93 for vcodec, fmts in item['videos'].items():
1988647d
S
94 if vcodec == 'hls':
95 continue
eb47569f
S
96 for format_id, video_url in fmts.items():
97 if format_id == 'm3u8':
eb47569f
S
98 continue
99 height = self._search_regex(
100 r'^(\d+)[pP]$', format_id, 'height', default=None)
884ae747
S
101 formats.append({
102 'url': video_url,
eb47569f 103 'format_id': '%s-%s' % (vcodec, format_id),
884ae747 104 'vcodec': vcodec,
eb47569f 105 'height': int_or_none(height),
7584e38c 106 'filesize': int_or_none(item.get('video_files_size', {}).get(vcodec, {}).get(format_id)),
884ae747 107 })
fb8b8fdd
S
108 self._sort_formats(formats)
109
110 return {
111 'id': video_id,
884ae747 112 'display_id': display_id,
fb8b8fdd
S
113 'title': title,
114 'description': description,
115 'thumbnail': thumbnail,
884ae747
S
116 'duration': duration,
117 'age_limit': age_limit,
fb8b8fdd 118 'formats': formats,
5f6a1245 119 }