1 from __future__ import unicode_literals
5 from .common import InfoExtractor
6 from .vimeo import VimeoIE
7 from ..compat import compat_str
19 class RayWenderlichIE(InfoExtractor):
23 videos\.raywenderlich\.com/courses|
24 (?:www\.)?raywenderlich\.com
26 (?P<course_id>[^/]+)/lessons/(?P<id>\d+)
30 'url': 'https://www.raywenderlich.com/3530-testing-in-ios/lessons/1',
34 'title': 'Introduction',
35 'description': 'md5:804d031b3efa9fcb49777d512d74f722',
36 'timestamp': 1513906277,
37 'upload_date': '20171222',
39 'uploader': 'Ray Wenderlich',
40 'uploader_id': 'user3304672',
44 'skip_download': True,
46 'add_ie': [VimeoIE.ie_key()],
47 'expected_warnings': ['HTTP Error 403: Forbidden'],
49 'url': 'https://videos.raywenderlich.com/courses/105-testing-in-ios/lessons/1',
50 'only_matching': True,
54 def _extract_video_id(data, lesson_id):
57 groups = try_get(data, lambda x: x['groups'], list) or []
61 if not isinstance(group, dict):
63 contents = try_get(data, lambda x: x['contents'], list) or []
64 for content in contents:
65 if not isinstance(content, dict):
67 ordinal = int_or_none(content.get('ordinal'))
68 if ordinal != lesson_id:
70 video_id = content.get('identifier')
72 return compat_str(video_id)
74 def _real_extract(self, url):
75 mobj = re.match(self._VALID_URL, url)
76 course_id, lesson_id = mobj.group('course_id', 'id')
77 display_id = '%s/%s' % (course_id, lesson_id)
79 webpage = self._download_webpage(url, display_id)
81 thumbnail = self._og_search_thumbnail(
82 webpage, default=None) or self._html_search_meta(
83 'twitter:image', webpage, 'thumbnail')
85 if '>Subscribe to unlock' in webpage:
87 'This content is only available for subscribers',
91 'thumbnail': thumbnail,
94 vimeo_id = self._search_regex(
95 r'data-vimeo-id=["\'](\d+)', webpage, 'vimeo id', default=None)
98 data = self._parse_json(
100 r'data-collection=(["\'])(?P<data>{.+?})\1', webpage,
101 'data collection', default='{}', group='data'),
102 display_id, transform_source=unescapeHTML, fatal=False)
103 video_id = self._extract_video_id(
104 data, lesson_id) or self._search_regex(
105 r'/videos/(\d+)/', thumbnail, 'video id')
108 'X-Requested-With': 'XMLHttpRequest',
110 csrf_token = self._html_search_meta(
111 'csrf-token', webpage, 'csrf token', default=None)
113 headers['X-CSRF-Token'] = csrf_token
114 video = self._download_json(
115 'https://videos.raywenderlich.com/api/v1/videos/%s.json'
116 % video_id, display_id, headers=headers)['video']
117 vimeo_id = video['clips'][0]['provider_id']
119 '_type': 'url_transparent',
120 'title': video.get('name'),
121 'description': video.get('description') or video.get(
123 'duration': int_or_none(video.get('duration')),
124 'timestamp': unified_timestamp(video.get('created_at')),
127 return merge_dicts(info, self.url_result(
128 VimeoIE._smuggle_referrer(
129 'https://player.vimeo.com/video/%s' % vimeo_id, url),
130 ie=VimeoIE.ie_key(), video_id=vimeo_id))
133 class RayWenderlichCourseIE(InfoExtractor):
134 _VALID_URL = r'''(?x)
137 videos\.raywenderlich\.com/courses|
138 (?:www\.)?raywenderlich\.com
144 'url': 'https://www.raywenderlich.com/3530-testing-in-ios',
146 'title': 'Testing in iOS',
147 'id': '3530-testing-in-ios',
152 'playlist_count': 29,
156 def suitable(cls, url):
157 return False if RayWenderlichIE.suitable(url) else super(
158 RayWenderlichCourseIE, cls).suitable(url)
160 def _real_extract(self, url):
161 course_id = self._match_id(url)
163 webpage = self._download_webpage(url, course_id)
167 for lesson_url in re.findall(
168 r'<a[^>]+\bhref=["\'](/%s/lessons/\d+)' % course_id, webpage):
169 if lesson_url in lesson_urls:
171 lesson_urls.add(lesson_url)
172 entries.append(self.url_result(
173 urljoin(url, lesson_url), ie=RayWenderlichIE.ie_key()))
175 title = self._og_search_title(
176 webpage, default=None) or self._html_search_meta(
177 'twitter:title', webpage, 'title', default=None)
179 return self.playlist_result(entries, course_id, title)