]>
Commit | Line | Data |
---|---|---|
64e7ad60 PH |
1 | from __future__ import unicode_literals |
2 | ||
0c996b9f S |
3 | import re |
4 | ||
64e7ad60 | 5 | from .common import InfoExtractor |
fb97809e S |
6 | from ..compat import ( |
7 | compat_HTTPError, | |
8 | compat_urlparse, | |
9 | ) | |
10 | from ..utils import ( | |
11 | ExtractorError, | |
12 | parse_duration, | |
ee4337d1 | 13 | js_to_json, |
14 | parse_iso8601, | |
fb97809e | 15 | ) |
64e7ad60 PH |
16 | |
17 | ||
a06bf87a | 18 | class ViideaIE(InfoExtractor): |
19 | _VALID_URL = r'''(?x)http://(?:www\.)?(?: | |
20 | videolectures\.net| | |
21 | flexilearn\.viidea\.net| | |
22 | presentations\.ocwconsortium\.org| | |
23 | video\.travel-zoom\.si| | |
24 | video\.pomp-forum\.si| | |
25 | tv\.nil\.si| | |
26 | video\.hekovnik.com| | |
27 | video\.szko\.si| | |
28 | kpk\.viidea\.com| | |
29 | inside\.viidea\.net| | |
30 | video\.kiberpipa\.org| | |
31 | bvvideo\.si| | |
32 | kongres\.viidea\.net| | |
33 | edemokracija\.viidea\.com | |
34 | )(?:/lecture)?/(?P<id>[^/]+)(?:/video/(?P<part>\d+))?''' | |
64e7ad60 | 35 | |
6edaa0e2 | 36 | _TESTS = [{ |
64e7ad60 PH |
37 | 'url': 'http://videolectures.net/promogram_igor_mekjavic_eng/', |
38 | 'info_dict': { | |
ee4337d1 | 39 | 'id': '20171_part1', |
64e7ad60 PH |
40 | 'ext': 'mp4', |
41 | 'title': 'Automatics, robotics and biocybernetics', | |
42 | 'description': 'md5:815fc1deb6b3a2bff99de2d5325be482', | |
43 | 'upload_date': '20130627', | |
44 | 'duration': 565, | |
45 | 'thumbnail': 're:http://.*\.jpg', | |
46 | }, | |
06c6efa9 S |
47 | }, { |
48 | # video with invalid direct format links (HTTP 403) | |
49 | 'url': 'http://videolectures.net/russir2010_filippova_nlp/', | |
50 | 'info_dict': { | |
ee4337d1 | 51 | 'id': '14891_part1', |
06c6efa9 S |
52 | 'ext': 'flv', |
53 | 'title': 'NLP at Google', | |
54 | 'description': 'md5:fc7a6d9bf0302d7cc0e53f7ca23747b3', | |
55 | 'duration': 5352, | |
56 | 'thumbnail': 're:http://.*\.jpg', | |
57 | }, | |
58 | 'params': { | |
59 | # rtmp download | |
60 | 'skip_download': True, | |
61 | }, | |
6edaa0e2 S |
62 | }, { |
63 | 'url': 'http://videolectures.net/deeplearning2015_montreal/', | |
64 | 'info_dict': { | |
ee4337d1 | 65 | 'id': '23181', |
6edaa0e2 | 66 | 'title': 'Deep Learning Summer School, Montreal 2015', |
ee4337d1 | 67 | 'description': 'md5:0533a85e4bd918df52a01f0e1ebe87b7', |
68 | 'timestamp': 1438560000, | |
6edaa0e2 S |
69 | }, |
70 | 'playlist_count': 30, | |
ee4337d1 | 71 | }, { |
72 | # multi part lecture | |
73 | 'url': 'http://videolectures.net/mlss09uk_bishop_ibi/', | |
74 | 'info_dict': { | |
75 | 'id': '9737', | |
76 | 'title': 'Introduction To Bayesian Inference', | |
77 | 'timestamp': 1251622800, | |
78 | }, | |
79 | 'playlist': [{ | |
80 | 'info_dict': { | |
81 | 'id': '9737_part1', | |
82 | 'ext': 'wmv', | |
83 | 'title': 'Introduction To Bayesian Inference', | |
84 | }, | |
85 | }, { | |
86 | 'info_dict': { | |
87 | 'id': '9737_part2', | |
88 | 'ext': 'wmv', | |
89 | 'title': 'Introduction To Bayesian Inference', | |
90 | }, | |
91 | }], | |
92 | 'playlist_count': 2, | |
6edaa0e2 | 93 | }] |
64e7ad60 PH |
94 | |
95 | def _real_extract(self, url): | |
ee4337d1 | 96 | lecture_slug, part = re.match(self._VALID_URL, url).groups() |
97 | ||
98 | webpage = self._download_webpage(url, lecture_slug) | |
64e7ad60 | 99 | |
ee4337d1 | 100 | cfg = self._parse_json(self._search_regex(r'cfg\s*:\s*({[^}]+})', webpage, 'cfg'), lecture_slug, js_to_json) |
fb97809e | 101 | |
ee4337d1 | 102 | lecture_id = str(cfg['obj_id']) |
64e7ad60 | 103 | |
a06bf87a | 104 | base_url = self._proto_relative_url(cfg['livepipe'], 'http:') |
105 | ||
106 | lecture_data = self._download_json('%s/site/api/lecture/%s?format=json' % (base_url, lecture_id), lecture_id)['lecture'][0] | |
64e7ad60 | 107 | |
ee4337d1 | 108 | lecture_info = { |
109 | 'id': lecture_id, | |
110 | 'display_id': lecture_slug, | |
111 | 'title': lecture_data['title'], | |
112 | 'timestamp': parse_iso8601(lecture_data.get('time')), | |
113 | 'description': lecture_data.get('description_wiki'), | |
114 | 'thumbnail': lecture_data.get('thumb'), | |
115 | } | |
64e7ad60 | 116 | |
ee4337d1 | 117 | entries = [] |
118 | parts = cfg.get('videos') | |
119 | if parts: | |
120 | if len(parts) == 1: | |
121 | part = str(parts[0]) | |
122 | if part: | |
a06bf87a | 123 | smil_url = '%s/%s/video/%s/smil.xml' % (base_url, lecture_slug, part) |
ee4337d1 | 124 | smil = self._download_smil(smil_url, lecture_id) |
125 | info = self._parse_smil(smil, smil_url, lecture_id) | |
126 | info['id'] = '%s_part%s' % (lecture_id, part) | |
127 | switch = smil.find('.//switch') | |
128 | if switch is not None: | |
129 | info['duration'] = parse_duration(switch.attrib.get('dur')) | |
130 | return info | |
131 | else: | |
132 | for part in parts: | |
a06bf87a | 133 | entries.append(self.url_result('%s/video/%s' % (base_url, lecture_id, part), 'Viidea')) |
ee4337d1 | 134 | lecture_info['_type'] = 'multi_video' |
135 | else: | |
136 | # Probably a playlist | |
a06bf87a | 137 | playlist_webpage = self._download_webpage('%s/site/ajax/drilldown/?id=%s' % (base_url, lecture_id), lecture_id) |
ee4337d1 | 138 | entries = [ |
a06bf87a | 139 | self.url_result(compat_urlparse.urljoin(url, video_url), 'Viidea') |
140 | for _, video_url in re.findall(r'<a[^>]+href=(["\'])(.+?)\1[^>]+id=["\']lec=\d+', playlist_webpage)] | |
ee4337d1 | 141 | lecture_info['_type'] = 'playlist' |
64e7ad60 | 142 | |
ee4337d1 | 143 | lecture_info['entries'] = entries |
144 | return lecture_info |