]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/viidea.py
[ie/orf:on] Improve extraction (#9677)
[yt-dlp.git] / yt_dlp / extractor / viidea.py
CommitLineData
0c996b9f
S
1import re
2
64e7ad60 3from .common import InfoExtractor
fb97809e 4from ..compat import (
6fdb39de 5 compat_str,
64f0e30b 6 compat_urlparse,
fb97809e 7)
3d2623a8 8from ..networking.exceptions import HTTPError
fb97809e 9from ..utils import (
64f0e30b 10 ExtractorError,
ee4337d1 11 js_to_json,
64f0e30b 12 parse_duration,
ee4337d1 13 parse_iso8601,
fb97809e 14)
64e7ad60
PH
15
16
a06bf87a 17class ViideaIE(InfoExtractor):
5886b38d 18 _VALID_URL = r'''(?x)https?://(?:www\.)?(?:
a06bf87a 19 videolectures\.net|
20 flexilearn\.viidea\.net|
21 presentations\.ocwconsortium\.org|
22 video\.travel-zoom\.si|
23 video\.pomp-forum\.si|
24 tv\.nil\.si|
25 video\.hekovnik.com|
26 video\.szko\.si|
27 kpk\.viidea\.com|
28 inside\.viidea\.net|
29 video\.kiberpipa\.org|
30 bvvideo\.si|
31 kongres\.viidea\.net|
32 edemokracija\.viidea\.com
8e3a2bd6 33 )(?:/lecture)?/(?P<id>[^/]+)(?:/video/(?P<part>\d+))?/*(?:[#?].*)?$'''
64e7ad60 34
6edaa0e2 35 _TESTS = [{
64e7ad60
PH
36 'url': 'http://videolectures.net/promogram_igor_mekjavic_eng/',
37 'info_dict': {
e8ce2375
S
38 'id': '20171',
39 'display_id': 'promogram_igor_mekjavic_eng',
64e7ad60
PH
40 'ext': 'mp4',
41 'title': 'Automatics, robotics and biocybernetics',
42 'description': 'md5:815fc1deb6b3a2bff99de2d5325be482',
ec85ded8 43 'thumbnail': r're:http://.*\.jpg',
e8ce2375 44 'timestamp': 1372349289,
64e7ad60
PH
45 'upload_date': '20130627',
46 'duration': 565,
64e7ad60 47 },
60ad3eb9
YCH
48 'params': {
49 # m3u8 download
50 'skip_download': True,
51 },
06c6efa9
S
52 }, {
53 # video with invalid direct format links (HTTP 403)
54 'url': 'http://videolectures.net/russir2010_filippova_nlp/',
55 'info_dict': {
e8ce2375
S
56 'id': '14891',
57 'display_id': 'russir2010_filippova_nlp',
06c6efa9
S
58 'ext': 'flv',
59 'title': 'NLP at Google',
60 'description': 'md5:fc7a6d9bf0302d7cc0e53f7ca23747b3',
ec85ded8 61 'thumbnail': r're:http://.*\.jpg',
e8ce2375
S
62 'timestamp': 1284375600,
63 'upload_date': '20100913',
64 'duration': 5352,
06c6efa9
S
65 },
66 'params': {
67 # rtmp download
68 'skip_download': True,
69 },
6edaa0e2 70 }, {
e8ce2375 71 # event playlist
6edaa0e2
S
72 'url': 'http://videolectures.net/deeplearning2015_montreal/',
73 'info_dict': {
ee4337d1 74 'id': '23181',
6edaa0e2 75 'title': 'Deep Learning Summer School, Montreal 2015',
ee4337d1 76 'description': 'md5:0533a85e4bd918df52a01f0e1ebe87b7',
ec85ded8 77 'thumbnail': r're:http://.*\.jpg',
ee4337d1 78 'timestamp': 1438560000,
6edaa0e2
S
79 },
80 'playlist_count': 30,
ee4337d1 81 }, {
82 # multi part lecture
83 'url': 'http://videolectures.net/mlss09uk_bishop_ibi/',
84 'info_dict': {
85 'id': '9737',
e8ce2375 86 'display_id': 'mlss09uk_bishop_ibi',
ee4337d1 87 'title': 'Introduction To Bayesian Inference',
ec85ded8 88 'thumbnail': r're:http://.*\.jpg',
ee4337d1 89 'timestamp': 1251622800,
90 },
91 'playlist': [{
92 'info_dict': {
93 'id': '9737_part1',
e8ce2375 94 'display_id': 'mlss09uk_bishop_ibi_part1',
ee4337d1 95 'ext': 'wmv',
e8ce2375 96 'title': 'Introduction To Bayesian Inference (Part 1)',
ec85ded8 97 'thumbnail': r're:http://.*\.jpg',
e8ce2375
S
98 'duration': 4622,
99 'timestamp': 1251622800,
100 'upload_date': '20090830',
ee4337d1 101 },
102 }, {
103 'info_dict': {
104 'id': '9737_part2',
e8ce2375 105 'display_id': 'mlss09uk_bishop_ibi_part2',
ee4337d1 106 'ext': 'wmv',
e8ce2375 107 'title': 'Introduction To Bayesian Inference (Part 2)',
ec85ded8 108 'thumbnail': r're:http://.*\.jpg',
e8ce2375
S
109 'duration': 5641,
110 'timestamp': 1251622800,
111 'upload_date': '20090830',
ee4337d1 112 },
113 }],
114 'playlist_count': 2,
6edaa0e2 115 }]
64e7ad60
PH
116
117 def _real_extract(self, url):
5ad28e7f 118 lecture_slug, explicit_part_id = self._match_valid_url(url).groups()
ee4337d1 119
120 webpage = self._download_webpage(url, lecture_slug)
64e7ad60 121
e8ce2375
S
122 cfg = self._parse_json(self._search_regex(
123 [r'cfg\s*:\s*({.+?})\s*,\s*[\da-zA-Z_]+\s*:\s*\(?\s*function',
124 r'cfg\s*:\s*({[^}]+})'],
125 webpage, 'cfg'), lecture_slug, js_to_json)
fb97809e 126
6fdb39de 127 lecture_id = compat_str(cfg['obj_id'])
64e7ad60 128
a06bf87a 129 base_url = self._proto_relative_url(cfg['livepipe'], 'http:')
130
64f0e30b
S
131 try:
132 lecture_data = self._download_json(
133 '%s/site/api/lecture/%s?format=json' % (base_url, lecture_id),
134 lecture_id)['lecture'][0]
135 except ExtractorError as e:
3d2623a8 136 if isinstance(e.cause, HTTPError) and e.cause.status == 403:
64f0e30b 137 msg = self._parse_json(
3d2623a8 138 e.cause.response.read().decode('utf-8'), lecture_id)
64f0e30b
S
139 raise ExtractorError(msg['detail'], expected=True)
140 raise
64e7ad60 141
ee4337d1 142 lecture_info = {
143 'id': lecture_id,
144 'display_id': lecture_slug,
145 'title': lecture_data['title'],
146 'timestamp': parse_iso8601(lecture_data.get('time')),
147 'description': lecture_data.get('description_wiki'),
148 'thumbnail': lecture_data.get('thumb'),
149 }
64e7ad60 150
e8ce2375
S
151 playlist_entries = []
152 lecture_type = lecture_data.get('type')
153 parts = [compat_str(video) for video in cfg.get('videos', [])]
ee4337d1 154 if parts:
e8ce2375
S
155 multipart = len(parts) > 1
156
157 def extract_part(part_id):
158 smil_url = '%s/%s/video/%s/smil.xml' % (base_url, lecture_slug, part_id)
ee4337d1 159 smil = self._download_smil(smil_url, lecture_id)
160 info = self._parse_smil(smil, smil_url, lecture_id)
e8ce2375
S
161 info['id'] = lecture_id if not multipart else '%s_part%s' % (lecture_id, part_id)
162 info['display_id'] = lecture_slug if not multipart else '%s_part%s' % (lecture_slug, part_id)
163 if multipart:
164 info['title'] += ' (Part %s)' % part_id
ee4337d1 165 switch = smil.find('.//switch')
166 if switch is not None:
167 info['duration'] = parse_duration(switch.attrib.get('dur'))
e8ce2375
S
168 item_info = lecture_info.copy()
169 item_info.update(info)
170 return item_info
171
172 if explicit_part_id or not multipart:
173 result = extract_part(explicit_part_id or parts[0])
ee4337d1 174 else:
e8ce2375
S
175 result = {
176 '_type': 'multi_video',
177 'entries': [extract_part(part) for part in parts],
178 }
179 result.update(lecture_info)
180
181 # Immediately return explicitly requested part or non event item
182 if explicit_part_id or lecture_type != 'evt':
183 return result
184
185 playlist_entries.append(result)
186
187 # It's probably a playlist
188 if not parts or lecture_type == 'evt':
189 playlist_webpage = self._download_webpage(
190 '%s/site/ajax/drilldown/?id=%s' % (base_url, lecture_id), lecture_id)
ee4337d1 191 entries = [
a06bf87a 192 self.url_result(compat_urlparse.urljoin(url, video_url), 'Viidea')
e8ce2375
S
193 for _, video_url in re.findall(
194 r'<a[^>]+href=(["\'])(.+?)\1[^>]+id=["\']lec=\d+', playlist_webpage)]
195 playlist_entries.extend(entries)
64e7ad60 196
e8ce2375
S
197 playlist = self.playlist_result(playlist_entries, lecture_id)
198 playlist.update(lecture_info)
199 return playlist