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