]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/vyborymos.py
[youtube] Detect DRM better
[yt-dlp.git] / yt_dlp / extractor / vyborymos.py
CommitLineData
14ae11ef
S
1# coding: utf-8
2from __future__ import unicode_literals
3
4from .common import InfoExtractor
a1da888d 5from ..compat import compat_str
14ae11ef
S
6
7
8class VyboryMosIE(InfoExtractor):
9 _VALID_URL = r'https?://vybory\.mos\.ru/(?:#precinct/|account/channels\?.*?\bstation_id=)(?P<id>\d+)'
10 _TESTS = [{
11 'url': 'http://vybory.mos.ru/#precinct/13636',
12 'info_dict': {
13 'id': '13636',
14 'ext': 'mp4',
15 'title': 're:^Участковая избирательная комиссия №2231 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
16 'description': 'Россия, Москва, улица Введенского, 32А',
17 'is_live': True,
18 },
19 'params': {
20 'skip_download': True,
21 }
22 }, {
23 'url': 'http://vybory.mos.ru/account/channels?station_id=13636',
24 'only_matching': True,
25 }]
26
27 def _real_extract(self, url):
28 station_id = self._match_id(url)
29
30 channels = self._download_json(
31 'http://vybory.mos.ru/account/channels?station_id=%s' % station_id,
a1da888d 32 station_id, 'Downloading channels JSON')
14ae11ef
S
33
34 formats = []
35 for cam_num, (sid, hosts, name, _) in enumerate(channels, 1):
36 for num, host in enumerate(hosts, 1):
37 formats.append({
38 'url': 'http://%s/master.m3u8?sid=%s' % (host, sid),
39 'ext': 'mp4',
40 'format_id': 'camera%d-host%d' % (cam_num, num),
41 'format_note': '%s, %s' % (name, host),
42 })
43
44 info = self._download_json(
a1da888d
S
45 'http://vybory.mos.ru/json/voting_stations/%s/%s.json'
46 % (compat_str(station_id)[:3], station_id),
39ca3b5c 47 station_id, 'Downloading station JSON', fatal=False) or {}
14ae11ef
S
48
49 return {
50 'id': station_id,
39ca3b5c 51 'title': info.get('name') or station_id,
14ae11ef
S
52 'description': info.get('address'),
53 'is_live': True,
54 'formats': formats,
55 }