]>
Commit | Line | Data |
---|---|---|
497d77e1 AG |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | from .common import InfoExtractor | |
5 | from ..utils import int_or_none | |
6 | ||
7 | ||
8 | class KelbyOneIE(InfoExtractor): | |
9 | _VALID_URL = r'https?://members\.kelbyone\.com/course/(?P<id>[^$&?#/]+)' | |
10 | ||
11 | _TESTS = [{ | |
12 | 'url': 'https://members.kelbyone.com/course/glyn-dewis-mastering-selections/', | |
13 | 'playlist_mincount': 1, | |
14 | 'info_dict': { | |
15 | 'id': 'glyn-dewis-mastering-selections', | |
16 | 'title': 'Trailer - Mastering Selections in Photoshop', | |
17 | }, | |
18 | 'playlist': [{ | |
19 | 'info_dict': { | |
20 | 'id': 'MkiOnLqK', | |
21 | 'ext': 'mp4', | |
22 | 'title': 'Trailer - Mastering Selections in Photoshop', | |
23 | 'description': 'md5:d41d8cd98f00b204e9800998ecf8427e', | |
24 | 'thumbnail': 'https://content.jwplatform.com/v2/media/MkiOnLqK/poster.jpg?width=720', | |
25 | 'timestamp': 1601568639, | |
26 | 'duration': 90, | |
27 | 'upload_date': '20201001', | |
28 | }, | |
29 | }] | |
30 | }] | |
31 | ||
32 | def _entries(self, playlist): | |
33 | for item in playlist: | |
34 | video_id = item['mediaid'] | |
35 | thumbnails = [{ | |
36 | 'url': image.get('src'), | |
37 | 'width': int_or_none(image.get('width')), | |
38 | } for image in item.get('images') or []] | |
39 | formats, subtitles = [], {} | |
40 | for source in item.get('sources') or []: | |
41 | if not source.get('file'): | |
42 | continue | |
43 | if source.get('type') == 'application/vnd.apple.mpegurl': | |
44 | fmts, subs = self._extract_m3u8_formats_and_subtitles(source['file'], video_id) | |
45 | formats.extend(fmts) | |
46 | subtitles = self._merge_subtitles(subs, subtitles) | |
47 | elif source.get('type') == 'audio/mp4': | |
48 | formats.append({ | |
49 | 'format_id': source.get('label'), | |
50 | 'url': source['file'], | |
51 | 'vcodec': 'none', | |
52 | }) | |
53 | else: | |
54 | formats.append({ | |
55 | 'format_id': source.get('label'), | |
56 | 'height': source.get('height'), | |
57 | 'width': source.get('width'), | |
58 | 'url': source['file'], | |
59 | }) | |
60 | for track in item.get('tracks'): | |
61 | if track.get('kind') == 'captions' and track.get('file'): | |
62 | subtitles.setdefault('en', []).append({ | |
63 | 'url': track['file'], | |
64 | }) | |
65 | self._sort_formats(formats) | |
66 | yield { | |
67 | 'id': video_id, | |
68 | 'title': item['title'], | |
69 | 'description': item.get('description'), | |
70 | 'thumbnails': thumbnails, | |
71 | 'thumbnail': item.get('image'), | |
72 | 'timestamp': item.get('pubdate'), | |
73 | 'duration': item.get('duration'), | |
74 | 'formats': formats, | |
75 | 'subtitles': subtitles, | |
76 | } | |
77 | ||
78 | def _real_extract(self, url): | |
79 | item_id = self._match_id(url) | |
80 | webpage = self._download_webpage(url, item_id) | |
81 | playlist_url = self._html_search_regex(r'playlist"\:"(https.*content\.jwplatform\.com.*json)"', webpage, 'playlist url').replace('\\', '') | |
82 | course_data = self._download_json(playlist_url, item_id) | |
83 | return self.playlist_result(self._entries(course_data['playlist']), item_id, | |
84 | course_data.get('title'), course_data.get('description')) |