]>
Commit | Line | Data |
---|---|---|
96f3924b | 1 | import json |
2 | ||
bb5a7cb8 B |
3 | from .brightcove import BrightcoveNewIE |
4 | from .common import InfoExtractor | |
bb5a7cb8 | 5 | from ..utils import ( |
96f3924b | 6 | extract_attributes, |
7 | get_element_html_by_class, | |
8 | get_element_text_and_html_by_tag, | |
bb5a7cb8 | 9 | ) |
96f3924b | 10 | from ..utils.traversal import traverse_obj |
bb5a7cb8 B |
11 | |
12 | ||
13 | class CraftsyIE(InfoExtractor): | |
b634ba74 | 14 | _VALID_URL = r'https?://www\.craftsy\.com/class/(?P<id>[\w-]+)' |
bb5a7cb8 B |
15 | _TESTS = [{ |
16 | 'url': 'https://www.craftsy.com/class/the-midnight-quilt-show-season-5/', | |
17 | 'info_dict': { | |
18 | 'id': 'the-midnight-quilt-show-season-5', | |
19 | 'title': 'The Midnight Quilt Show Season 5', | |
20 | 'description': 'md5:113eda818e985d1a566625fb2f833b7a', | |
21 | }, | |
22 | 'playlist_count': 10, | |
23 | }, { | |
24 | 'url': 'https://www.craftsy.com/class/sew-your-own-designer-handbag/', | |
25 | 'info_dict': { | |
26 | 'id': 'sew-your-own-designer-handbag', | |
27 | 'title': 'Sew Your Own Designer Handbag', | |
28 | 'description': 'md5:8270d0ef5427d3c895a27351aeaac276', | |
29 | }, | |
30 | 'playlist_mincount': 1, | |
31 | }, { | |
32 | 'url': 'https://www.craftsy.com/class/all-access-estes-park-wool-market/', | |
33 | 'info_dict': { | |
34 | 'id': 'all-access-estes-park-wool-market', | |
35 | 'title': 'All Access: Estes Park Wool Market', | |
36 | 'description': 'md5:aded1bd8d38ae2fae4dae936c0ae01e7', | |
37 | }, | |
38 | 'playlist_count': 6, | |
39 | }] | |
40 | ||
41 | def _real_extract(self, url): | |
42 | video_id = self._match_id(url) | |
43 | webpage = self._download_webpage(url, video_id) | |
44 | ||
96f3924b | 45 | video_player = get_element_html_by_class('class-video-player', webpage) |
46 | video_data = traverse_obj(video_player, ( | |
47 | {extract_attributes}, 'wire:snapshot', {json.loads}, 'data', {dict})) or {} | |
48 | video_js = traverse_obj(video_player, ( | |
49 | {lambda x: get_element_text_and_html_by_tag('video-js', x)}, 1, {extract_attributes})) or {} | |
50 | ||
51 | has_access = video_data.get('userHasAccess') | |
52 | lessons = traverse_obj(video_data, ('lessons', ..., ..., lambda _, v: v['video_id'])) | |
53 | ||
54 | preview_id = video_js.get('data-video-id') | |
55 | if preview_id and preview_id not in traverse_obj(lessons, (..., 'video_id')): | |
56 | if not lessons and not has_access: | |
57 | self.report_warning( | |
58 | 'Only extracting preview. For the full class, pass cookies ' | |
59 | + f'from an account that has access. {self._login_hint()}') | |
60 | lessons.append({'video_id': preview_id}) | |
bb5a7cb8 | 61 | |
96f3924b | 62 | if not lessons and not has_access: |
63 | self.raise_login_required('You do not have access to this class') | |
bb5a7cb8 | 64 | |
96f3924b | 65 | account_id = video_data.get('accountId') or video_js['data-account'] |
bb5a7cb8 | 66 | |
96f3924b | 67 | def entries(lessons): |
68 | for lesson in lessons: | |
69 | yield self.url_result( | |
bb5a7cb8 B |
70 | f'http://players.brightcove.net/{account_id}/default_default/index.html?videoId={lesson["video_id"]}', |
71 | BrightcoveNewIE, lesson['video_id'], lesson.get('title')) | |
bb5a7cb8 B |
72 | |
73 | return self.playlist_result( | |
96f3924b | 74 | entries(lessons), video_id, self._html_search_meta(('og:title', 'twitter:title'), webpage), |
bb5a7cb8 | 75 | self._html_search_meta(('og:description', 'description'), webpage, default=None)) |