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