ivideon.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. from .common import InfoExtractor
  2. from ..compat import (
  3. compat_urllib_parse_urlencode,
  4. compat_urlparse,
  5. )
  6. from ..utils import qualities
  7. class IvideonIE(InfoExtractor):
  8. IE_NAME = 'ivideon'
  9. IE_DESC = 'Ivideon TV'
  10. _VALID_URL = r'https?://(?:www\.)?ivideon\.com/tv/(?:[^/]+/)*camera/(?P<id>\d+-[\da-f]+)/(?P<camera_id>\d+)'
  11. _TESTS = [{
  12. 'url': 'https://www.ivideon.com/tv/camera/100-916ca13b5c4ad9f564266424a026386d/0/',
  13. 'info_dict': {
  14. 'id': '100-916ca13b5c4ad9f564266424a026386d',
  15. 'ext': 'flv',
  16. 'title': 're:^Касса [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
  17. 'description': 'Основное предназначение - запись действий кассиров. Плюс общий вид.',
  18. 'is_live': True,
  19. },
  20. 'params': {
  21. 'skip_download': True,
  22. }
  23. }, {
  24. 'url': 'https://www.ivideon.com/tv/camera/100-c4ee4cb9ede885cf62dfbe93d7b53783/589824/?lang=ru',
  25. 'only_matching': True,
  26. }, {
  27. 'url': 'https://www.ivideon.com/tv/map/22.917923/-31.816406/16/camera/100-e7bc16c7d4b5bbd633fd5350b66dfa9a/0',
  28. 'only_matching': True,
  29. }]
  30. _QUALITIES = ('low', 'mid', 'hi')
  31. def _real_extract(self, url):
  32. mobj = self._match_valid_url(url)
  33. server_id, camera_id = mobj.group('id'), mobj.group('camera_id')
  34. camera_name, description = None, None
  35. camera_url = compat_urlparse.urljoin(
  36. url, '/tv/camera/%s/%s/' % (server_id, camera_id))
  37. webpage = self._download_webpage(camera_url, server_id, fatal=False)
  38. if webpage:
  39. config_string = self._search_regex(
  40. r'var\s+config\s*=\s*({.+?});', webpage, 'config', default=None)
  41. if config_string:
  42. config = self._parse_json(config_string, server_id, fatal=False)
  43. camera_info = config.get('ivTvAppOptions', {}).get('currentCameraInfo')
  44. if camera_info:
  45. camera_name = camera_info.get('camera_name')
  46. description = camera_info.get('misc', {}).get('description')
  47. if not camera_name:
  48. camera_name = self._html_search_meta(
  49. 'name', webpage, 'camera name', default=None) or self._search_regex(
  50. r'<h1[^>]+class="b-video-title"[^>]*>([^<]+)', webpage, 'camera name', default=None)
  51. quality = qualities(self._QUALITIES)
  52. formats = [{
  53. 'url': 'https://streaming.ivideon.com/flv/live?%s' % compat_urllib_parse_urlencode({
  54. 'server': server_id,
  55. 'camera': camera_id,
  56. 'sessionId': 'demo',
  57. 'q': quality(format_id),
  58. }),
  59. 'format_id': format_id,
  60. 'ext': 'flv',
  61. 'quality': quality(format_id),
  62. } for format_id in self._QUALITIES]
  63. return {
  64. 'id': server_id,
  65. 'title': camera_name or server_id,
  66. 'description': description,
  67. 'is_live': True,
  68. 'formats': formats,
  69. }