logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

vyborymos.py (2031B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import compat_str
  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. def _real_extract(self, url):
  24. station_id = self._match_id(url)
  25. channels = self._download_json(
  26. 'http://vybory.mos.ru/account/channels?station_id=%s' % station_id,
  27. station_id, 'Downloading channels JSON')
  28. formats = []
  29. for cam_num, (sid, hosts, name, _) in enumerate(channels, 1):
  30. for num, host in enumerate(hosts, 1):
  31. formats.append({
  32. 'url': 'http://%s/master.m3u8?sid=%s' % (host, sid),
  33. 'ext': 'mp4',
  34. 'format_id': 'camera%d-host%d' % (cam_num, num),
  35. 'format_note': '%s, %s' % (name, host),
  36. })
  37. info = self._download_json(
  38. 'http://vybory.mos.ru/json/voting_stations/%s/%s.json'
  39. % (compat_str(station_id)[:3], station_id),
  40. station_id, 'Downloading station JSON', fatal=False)
  41. return {
  42. 'id': station_id,
  43. 'title': self._live_title(info['name'] if info else station_id),
  44. 'description': info.get('address'),
  45. 'is_live': True,
  46. 'formats': formats,
  47. }