]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/viidea.py
525e303d4340c7db11a2c3c94cd4153e95e8b2c0
[youtubedl] / youtube_dl / extractor / viidea.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..compat import (
7 compat_urlparse,
8 compat_str,
9 )
10 from ..utils import (
11 parse_duration,
12 js_to_json,
13 parse_iso8601,
14 )
15
16
17 class ViideaIE(InfoExtractor):
18 _VALID_URL = r'''(?x)http://(?:www\.)?(?:
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
33 )(?:/lecture)?/(?P<id>[^/]+)(?:/video/(?P<part>\d+))?/*(?:[#?].*)?$'''
34
35 _TESTS = [{
36 'url': 'http://videolectures.net/promogram_igor_mekjavic_eng/',
37 'info_dict': {
38 'id': '20171',
39 'display_id': 'promogram_igor_mekjavic_eng',
40 'ext': 'mp4',
41 'title': 'Automatics, robotics and biocybernetics',
42 'description': 'md5:815fc1deb6b3a2bff99de2d5325be482',
43 'thumbnail': 're:http://.*\.jpg',
44 'timestamp': 1372349289,
45 'upload_date': '20130627',
46 'duration': 565,
47 },
48 }, {
49 # video with invalid direct format links (HTTP 403)
50 'url': 'http://videolectures.net/russir2010_filippova_nlp/',
51 'info_dict': {
52 'id': '14891',
53 'display_id': 'russir2010_filippova_nlp',
54 'ext': 'flv',
55 'title': 'NLP at Google',
56 'description': 'md5:fc7a6d9bf0302d7cc0e53f7ca23747b3',
57 'thumbnail': 're:http://.*\.jpg',
58 'timestamp': 1284375600,
59 'upload_date': '20100913',
60 'duration': 5352,
61 },
62 'params': {
63 # rtmp download
64 'skip_download': True,
65 },
66 }, {
67 # event playlist
68 'url': 'http://videolectures.net/deeplearning2015_montreal/',
69 'info_dict': {
70 'id': '23181',
71 'title': 'Deep Learning Summer School, Montreal 2015',
72 'description': 'md5:0533a85e4bd918df52a01f0e1ebe87b7',
73 'thumbnail': 're:http://.*\.jpg',
74 'timestamp': 1438560000,
75 },
76 'playlist_count': 30,
77 }, {
78 # multi part lecture
79 'url': 'http://videolectures.net/mlss09uk_bishop_ibi/',
80 'info_dict': {
81 'id': '9737',
82 'display_id': 'mlss09uk_bishop_ibi',
83 'title': 'Introduction To Bayesian Inference',
84 'thumbnail': 're:http://.*\.jpg',
85 'timestamp': 1251622800,
86 },
87 'playlist': [{
88 'info_dict': {
89 'id': '9737_part1',
90 'display_id': 'mlss09uk_bishop_ibi_part1',
91 'ext': 'wmv',
92 'title': 'Introduction To Bayesian Inference (Part 1)',
93 'thumbnail': 're:http://.*\.jpg',
94 'duration': 4622,
95 'timestamp': 1251622800,
96 'upload_date': '20090830',
97 },
98 }, {
99 'info_dict': {
100 'id': '9737_part2',
101 'display_id': 'mlss09uk_bishop_ibi_part2',
102 'ext': 'wmv',
103 'title': 'Introduction To Bayesian Inference (Part 2)',
104 'thumbnail': 're:http://.*\.jpg',
105 'duration': 5641,
106 'timestamp': 1251622800,
107 'upload_date': '20090830',
108 },
109 }],
110 'playlist_count': 2,
111 }]
112
113 def _real_extract(self, url):
114 lecture_slug, explicit_part_id = re.match(self._VALID_URL, url).groups()
115
116 webpage = self._download_webpage(url, lecture_slug)
117
118 cfg = self._parse_json(self._search_regex(
119 [r'cfg\s*:\s*({.+?})\s*,\s*[\da-zA-Z_]+\s*:\s*\(?\s*function',
120 r'cfg\s*:\s*({[^}]+})'],
121 webpage, 'cfg'), lecture_slug, js_to_json)
122
123 lecture_id = compat_str(cfg['obj_id'])
124
125 base_url = self._proto_relative_url(cfg['livepipe'], 'http:')
126
127 lecture_data = self._download_json(
128 '%s/site/api/lecture/%s?format=json' % (base_url, lecture_id),
129 lecture_id)['lecture'][0]
130
131 lecture_info = {
132 'id': lecture_id,
133 'display_id': lecture_slug,
134 'title': lecture_data['title'],
135 'timestamp': parse_iso8601(lecture_data.get('time')),
136 'description': lecture_data.get('description_wiki'),
137 'thumbnail': lecture_data.get('thumb'),
138 }
139
140 playlist_entries = []
141 lecture_type = lecture_data.get('type')
142 parts = [compat_str(video) for video in cfg.get('videos', [])]
143 if parts:
144 multipart = len(parts) > 1
145
146 def extract_part(part_id):
147 smil_url = '%s/%s/video/%s/smil.xml' % (base_url, lecture_slug, part_id)
148 smil = self._download_smil(smil_url, lecture_id)
149 info = self._parse_smil(smil, smil_url, lecture_id)
150 info['id'] = lecture_id if not multipart else '%s_part%s' % (lecture_id, part_id)
151 info['display_id'] = lecture_slug if not multipart else '%s_part%s' % (lecture_slug, part_id)
152 if multipart:
153 info['title'] += ' (Part %s)' % part_id
154 switch = smil.find('.//switch')
155 if switch is not None:
156 info['duration'] = parse_duration(switch.attrib.get('dur'))
157 item_info = lecture_info.copy()
158 item_info.update(info)
159 return item_info
160
161 if explicit_part_id or not multipart:
162 result = extract_part(explicit_part_id or parts[0])
163 else:
164 result = {
165 '_type': 'multi_video',
166 'entries': [extract_part(part) for part in parts],
167 }
168 result.update(lecture_info)
169
170 # Immediately return explicitly requested part or non event item
171 if explicit_part_id or lecture_type != 'evt':
172 return result
173
174 playlist_entries.append(result)
175
176 # It's probably a playlist
177 if not parts or lecture_type == 'evt':
178 playlist_webpage = self._download_webpage(
179 '%s/site/ajax/drilldown/?id=%s' % (base_url, lecture_id), lecture_id)
180 entries = [
181 self.url_result(compat_urlparse.urljoin(url, video_url), 'Viidea')
182 for _, video_url in re.findall(
183 r'<a[^>]+href=(["\'])(.+?)\1[^>]+id=["\']lec=\d+', playlist_webpage)]
184 playlist_entries.extend(entries)
185
186 playlist = self.playlist_result(playlist_entries, lecture_id)
187 playlist.update(lecture_info)
188 return playlist