vyborymos.py 1.9 KB

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