]>
Commit | Line | Data |
---|---|---|
bb5a7cb8 B |
1 | from .brightcove import BrightcoveNewIE |
2 | from .common import InfoExtractor | |
3 | ||
4 | from ..utils import ( | |
5 | dict_get, | |
6 | get_element_by_id, | |
7 | js_to_json, | |
8 | traverse_obj, | |
9 | ) | |
10 | ||
11 | ||
12 | class CraftsyIE(InfoExtractor): | |
13 | _VALID_URL = r'https?://www.craftsy.com/class/(?P<id>[a-z0-9_-]+)/' | |
14 | _TESTS = [{ | |
15 | 'url': 'https://www.craftsy.com/class/the-midnight-quilt-show-season-5/', | |
16 | 'info_dict': { | |
17 | 'id': 'the-midnight-quilt-show-season-5', | |
18 | 'title': 'The Midnight Quilt Show Season 5', | |
19 | 'description': 'md5:113eda818e985d1a566625fb2f833b7a', | |
20 | }, | |
21 | 'playlist_count': 10, | |
22 | }, { | |
23 | 'url': 'https://www.craftsy.com/class/sew-your-own-designer-handbag/', | |
24 | 'info_dict': { | |
25 | 'id': 'sew-your-own-designer-handbag', | |
26 | 'title': 'Sew Your Own Designer Handbag', | |
27 | 'description': 'md5:8270d0ef5427d3c895a27351aeaac276', | |
28 | }, | |
29 | 'playlist_mincount': 1, | |
30 | }, { | |
31 | 'url': 'https://www.craftsy.com/class/all-access-estes-park-wool-market/', | |
32 | 'info_dict': { | |
33 | 'id': 'all-access-estes-park-wool-market', | |
34 | 'title': 'All Access: Estes Park Wool Market', | |
35 | 'description': 'md5:aded1bd8d38ae2fae4dae936c0ae01e7', | |
36 | }, | |
37 | 'playlist_count': 6, | |
38 | }] | |
39 | ||
40 | def _real_extract(self, url): | |
41 | video_id = self._match_id(url) | |
42 | webpage = self._download_webpage(url, video_id) | |
43 | ||
44 | video_data = self._parse_json(self._search_regex( | |
45 | r'class_video_player_vars\s*=\s*({.*})\s*;', | |
46 | get_element_by_id('vidstore-classes_class-video-player-js-extra', webpage), | |
47 | 'video data'), video_id, transform_source=js_to_json) | |
48 | ||
49 | account_id = traverse_obj(video_data, ('video_player', 'bc_account_id')) | |
50 | ||
51 | entries = [] | |
52 | class_preview = traverse_obj(video_data, ('video_player', 'class_preview')) | |
53 | if class_preview: | |
54 | v_id = class_preview.get('video_id') | |
55 | entries.append(self.url_result( | |
56 | f'http://players.brightcove.net/{account_id}/default_default/index.html?videoId={v_id}', | |
57 | BrightcoveNewIE, v_id, class_preview.get('title'))) | |
58 | ||
59 | if dict_get(video_data, ('is_free', 'user_has_access')): | |
60 | entries += [ | |
61 | self.url_result( | |
62 | f'http://players.brightcove.net/{account_id}/default_default/index.html?videoId={lesson["video_id"]}', | |
63 | BrightcoveNewIE, lesson['video_id'], lesson.get('title')) | |
64 | for lesson in video_data['lessons']] | |
65 | ||
66 | return self.playlist_result( | |
67 | entries, video_id, video_data.get('class_title'), | |
68 | self._html_search_meta(('og:description', 'description'), webpage, default=None)) |