logo

youtube-dl

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

ivideon.py (3254B)


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