4 from .common import InfoExtractor
5 from ..utils import ExtractorError
8 class LyndaIE(InfoExtractor):
10 IE_DESC = u'lynda.com videos'
11 _VALID_URL = r'https?://www\.lynda\.com/[^/]+/[^/]+/\d+/(\d+)-\d\.html'
14 u'url': u'http://www.lynda.com/Bootstrap-tutorials/Using-exercise-files/110885/114408-4.html',
15 u'file': u'114408.mp4',
16 u'md5': u'ecfc6862da89489161fb9cd5f5a6fac1',
18 u'title': u'Using the exercise files',
23 def _real_extract(self, url):
24 mobj = re.match(self._VALID_URL, url)
25 video_id = mobj.group(1)
27 page = self._download_webpage('http://www.lynda.com/ajax/player?videoId=%s&type=video' % video_id,
28 video_id, u'Downloading video JSON')
29 video_json = json.loads(page)
31 if u'Status' in video_json and video_json[u'Status'] == u'NotFound':
32 raise ExtractorError(u'Video %s does not exist' % video_id, expected=True)
34 if video_json[u'HasAccess'] is False:
35 raise ExtractorError(u'Video %s is only available for members' % video_id, expected=True)
37 video_id = video_json[u'ID']
38 duration = video_json[u'DurationInSeconds']
39 title = video_json[u'Title']
41 formats = [{'url': fmt[u'Url'],
42 'ext': fmt[u'Extension'],
43 'width': fmt[u'Width'],
44 'height': fmt[u'Height'],
45 'filesize': fmt[u'FileSize'],
46 'format_id': fmt[u'Resolution']
47 } for fmt in video_json[u'Formats']]
49 self._sort_formats(formats)
59 class LyndaCourseIE(InfoExtractor):
60 IE_NAME = u'lynda:course'
61 IE_DESC = u'lynda.com online courses'
63 # Course link equals to welcome/introduction video link of same course
64 # We will recognize it as course link
65 _VALID_URL = r'https?://(?:www|m)\.lynda\.com/(?P<coursepath>[^/]+/[^/]+/(?P<courseid>\d+))-\d\.html'
67 def _real_extract(self, url):
68 mobj = re.match(self._VALID_URL, url)
69 course_path = mobj.group('coursepath')
70 course_id = mobj.group('courseid')
72 page = self._download_webpage('http://www.lynda.com/ajax/player?courseId=%s&type=course' % course_id,
73 course_id, u'Downloading course JSON')
74 course_json = json.loads(page)
76 if u'Status' in course_json and course_json[u'Status'] == u'NotFound':
77 raise ExtractorError(u'Course %s does not exist' % course_id, expected=True)
79 unaccessible_videos = 0
82 for chapter in course_json[u'Chapters']:
83 for video in chapter[u'Videos']:
84 if video[u'HasAccess'] is not True:
85 unaccessible_videos += 1
87 videos.append(video[u'ID'])
89 if unaccessible_videos > 0:
90 self._downloader.report_warning(u'%s videos are only available for members and will not be downloaded' % unaccessible_videos)
92 entries = [self.url_result('http://www.lynda.com/%s/%s-4.html' % (course_path, video_id), 'Lynda') for video_id in videos]
94 course_title = course_json[u'Title']
96 return self.playlist_result(entries, course_id, course_title)