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