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