ivideon.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_urllib_parse
  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. _QUALITIES = ('low', 'mid', 'hi')
  28. def _real_extract(self, url):
  29. mobj = re.match(self._VALID_URL, url)
  30. server_id, camera_id = mobj.group('id'), mobj.group('camera_id')
  31. camera_name, description = None, None
  32. webpage = self._download_webpage(url, server_id, fatal=False)
  33. if webpage:
  34. config_string = self._search_regex(
  35. r'var\s+config\s*=\s*({.+?});', webpage, 'config', default=None)
  36. if config_string:
  37. config = self._parse_json(config_string, server_id, fatal=False)
  38. camera_info = config.get('ivTvAppOptions', {}).get('currentCameraInfo')
  39. if camera_info:
  40. camera_name = camera_info.get('camera_name')
  41. description = camera_info.get('misc', {}).get('description')
  42. if not camera_name:
  43. camera_name = self._html_search_meta(
  44. 'name', webpage, 'camera name', default=None) or self._search_regex(
  45. r'<h1[^>]+class="b-video-title"[^>]*>([^<]+)', webpage, 'camera name', default=None)
  46. quality = qualities(self._QUALITIES)
  47. formats = [{
  48. 'url': 'https://streaming.ivideon.com/flv/live?%s' % compat_urllib_parse.urlencode({
  49. 'server': server_id,
  50. 'camera': camera_id,
  51. 'sessionId': 'demo',
  52. 'q': quality(format_id),
  53. }),
  54. 'format_id': format_id,
  55. 'ext': 'flv',
  56. 'quality': quality(format_id),
  57. } for format_id in self._QUALITIES]
  58. self._sort_formats(formats)
  59. return {
  60. 'id': server_id,
  61. 'title': self._live_title(camera_name or server_id),
  62. 'description': description,
  63. 'is_live': True,
  64. 'formats': formats,
  65. }