]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/vyborymos.py
Use canonical URL in Vcs-Git.
[youtubedl] / youtube_dl / extractor / vyborymos.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..compat import compat_str
6
7
8 class 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,
32 station_id, 'Downloading channels JSON')
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(
45 'http://vybory.mos.ru/json/voting_stations/%s/%s.json'
46 % (compat_str(station_id)[:3], station_id),
47 station_id, 'Downloading station JSON', fatal=False)
48
49 return {
50 'id': station_id,
51 'title': self._live_title(info['name'] if info else station_id),
52 'description': info.get('address'),
53 'is_live': True,
54 'formats': formats,
55 }