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