ivideon.py 3.0 KB

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