3 from .brightcove
import BrightcoveNewIE
4 from .common
import InfoExtractor
7 get_element_html_by_class
,
8 get_element_text_and_html_by_tag
,
10 from ..utils
.traversal
import traverse_obj
13 class CraftsyIE(InfoExtractor
):
14 _VALID_URL
= r
'https?://www\.craftsy\.com/class/(?P<id>[\w-]+)'
16 'url': 'https://www.craftsy.com/class/the-midnight-quilt-show-season-5/',
18 'id': 'the-midnight-quilt-show-season-5',
19 'title': 'The Midnight Quilt Show Season 5',
20 'description': 'md5:113eda818e985d1a566625fb2f833b7a',
24 'url': 'https://www.craftsy.com/class/sew-your-own-designer-handbag/',
26 'id': 'sew-your-own-designer-handbag',
27 'title': 'Sew Your Own Designer Handbag',
28 'description': 'md5:8270d0ef5427d3c895a27351aeaac276',
30 'playlist_mincount': 1,
32 'url': 'https://www.craftsy.com/class/all-access-estes-park-wool-market/',
34 'id': 'all-access-estes-park-wool-market',
35 'title': 'All Access: Estes Park Wool Market',
36 'description': 'md5:aded1bd8d38ae2fae4dae936c0ae01e7',
41 def _real_extract(self
, url
):
42 video_id
= self
._match
_id
(url
)
43 webpage
= self
._download
_webpage
(url
, video_id
)
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 {}
51 has_access
= video_data
.get('userHasAccess')
52 lessons
= traverse_obj(video_data
, ('lessons', ..., ..., lambda _
, v
: v
['video_id']))
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
:
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
})
62 if not lessons
and not has_access
:
63 self
.raise_login_required('You do not have access to this class')
65 account_id
= video_data
.get('accountId') or video_js
['data-account']
68 for lesson
in lessons
:
69 yield self
.url_result(
70 f
'http://players.brightcove.net/{account_id}/default_default/index.html?videoId={lesson["video_id"]}',
71 BrightcoveNewIE
, lesson
['video_id'], lesson
.get('title'))
73 return self
.playlist_result(
74 entries(lessons
), video_id
, self
._html
_search
_meta
(('og:title', 'twitter:title'), webpage
),
75 self
._html
_search
_meta
(('og:description', 'description'), webpage
, default
=None))