+
+
+class CamdemyFolderIE(InfoExtractor):
+ _VALID_URL = r'https?://(?:www\.)?camdemy\.com/folder/(?P<id>\d+)'
+ _TESTS = [{
+ # links with trailing slash
+ 'url': 'http://www.camdemy.com/folder/450',
+ 'info_dict': {
+ 'id': '450',
+ 'title': '信號與系統 2012 & 2011 (Signals and Systems)',
+ },
+ 'playlist_mincount': 145
+ }, {
+ # links without trailing slash
+ # and multi-page
+ 'url': 'http://www.camdemy.com/folder/853',
+ 'info_dict': {
+ 'id': '853',
+ 'title': '科學計算 - 使用 Matlab'
+ },
+ 'playlist_mincount': 20
+ }, {
+ # with displayMode parameter. For testing the codes to add parameters
+ 'url': 'http://www.camdemy.com/folder/853/?displayMode=defaultOrderByOrg',
+ 'info_dict': {
+ 'id': '853',
+ 'title': '科學計算 - 使用 Matlab'
+ },
+ 'playlist_mincount': 20
+ }]
+
+ def _real_extract(self, url):
+ folder_id = self._match_id(url)
+
+ # Add displayMode=list so that all links are displayed in a single page
+ parsed_url = list(compat_urlparse.urlparse(url))
+ query = dict(compat_urlparse.parse_qsl(parsed_url[4]))
+ query.update({'displayMode': 'list'})
+ parsed_url[4] = compat_urllib_parse_urlencode(query)
+ final_url = compat_urlparse.urlunparse(parsed_url)
+
+ page = self._download_webpage(final_url, folder_id)
+ matches = re.findall(r"href='(/media/\d+/?)'", page)
+
+ entries = [self.url_result('http://www.camdemy.com' + media_path)
+ for media_path in matches]
+
+ folder_title = self._html_search_meta('keywords', page)
+
+ return self.playlist_result(entries, folder_id, folder_title)