| 
									
										
										
										
											2015-02-11 16:39:15 +08:00
										 |  |  | # coding: utf-8 | 
					
						
							|  |  |  | from __future__ import unicode_literals | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import re | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from .common import InfoExtractor | 
					
						
							| 
									
										
										
										
											2015-02-12 08:55:06 +01:00
										 |  |  | from ..compat import ( | 
					
						
							| 
									
										
										
										
											2016-03-26 01:46:57 +06:00
										 |  |  |     compat_urllib_parse_urlencode, | 
					
						
							| 
									
										
										
										
											2015-02-12 08:55:06 +01:00
										 |  |  |     compat_urlparse, | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | from ..utils import ( | 
					
						
							| 
									
										
										
										
											2016-07-25 22:31:10 +07:00
										 |  |  |     clean_html, | 
					
						
							| 
									
										
										
										
											2016-07-25 22:35:12 +07:00
										 |  |  |     parse_duration, | 
					
						
							| 
									
										
										
										
											2015-02-12 08:55:06 +01:00
										 |  |  |     str_to_int, | 
					
						
							| 
									
										
										
										
											2016-07-25 22:31:10 +07:00
										 |  |  |     unified_strdate, | 
					
						
							| 
									
										
										
										
											2015-02-12 08:55:06 +01:00
										 |  |  | ) | 
					
						
							| 
									
										
										
										
											2015-02-11 16:39:15 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class CamdemyIE(InfoExtractor): | 
					
						
							| 
									
										
										
										
											2016-03-21 21:36:32 +06:00
										 |  |  |     _VALID_URL = r'https?://(?:www\.)?camdemy\.com/media/(?P<id>\d+)' | 
					
						
							| 
									
										
										
										
											2015-02-11 16:39:15 +08:00
										 |  |  |     _TESTS = [{ | 
					
						
							|  |  |  |         # single file | 
					
						
							|  |  |  |         'url': 'http://www.camdemy.com/media/5181/', | 
					
						
							|  |  |  |         'md5': '5a5562b6a98b37873119102e052e311b', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							|  |  |  |             'id': '5181', | 
					
						
							|  |  |  |             'ext': 'mp4', | 
					
						
							|  |  |  |             'title': 'Ch1-1 Introduction, Signals (02-23-2012)', | 
					
						
							| 
									
										
										
										
											2017-01-02 20:08:07 +08:00
										 |  |  |             'thumbnail': r're:^https?://.*\.jpg$', | 
					
						
							| 
									
										
										
										
											2015-02-11 16:39:15 +08:00
										 |  |  |             'creator': 'ss11spring', | 
					
						
							| 
									
										
										
										
											2016-07-25 22:35:12 +07:00
										 |  |  |             'duration': 1591, | 
					
						
							| 
									
										
										
										
											2015-02-11 16:39:15 +08:00
										 |  |  |             'upload_date': '20130114', | 
					
						
							| 
									
										
										
										
											2015-02-12 08:55:06 +01:00
										 |  |  |             'view_count': int, | 
					
						
							| 
									
										
										
										
											2015-02-11 16:39:15 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |     }, { | 
					
						
							|  |  |  |         # With non-empty description | 
					
						
							| 
									
										
										
										
											2016-07-25 22:31:10 +07:00
										 |  |  |         # webpage returns "No permission or not login" | 
					
						
							| 
									
										
										
										
											2015-02-11 16:39:15 +08:00
										 |  |  |         'url': 'http://www.camdemy.com/media/13885', | 
					
						
							|  |  |  |         'md5': '4576a3bb2581f86c61044822adbd1249', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							|  |  |  |             'id': '13885', | 
					
						
							|  |  |  |             'ext': 'mp4', | 
					
						
							|  |  |  |             'title': 'EverCam + Camdemy QuickStart', | 
					
						
							| 
									
										
										
										
											2017-01-02 20:08:07 +08:00
										 |  |  |             'thumbnail': r're:^https?://.*\.jpg$', | 
					
						
							| 
									
										
										
										
											2016-07-25 22:31:10 +07:00
										 |  |  |             'description': 'md5:2a9f989c2b153a2342acee579c6e7db6', | 
					
						
							| 
									
										
										
										
											2015-02-11 16:39:15 +08:00
										 |  |  |             'creator': 'evercam', | 
					
						
							| 
									
										
										
										
											2016-07-25 22:35:12 +07:00
										 |  |  |             'duration': 318, | 
					
						
							| 
									
										
										
										
											2015-02-11 16:39:15 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-02-12 00:11:33 +08:00
										 |  |  |     }, { | 
					
						
							| 
									
										
										
										
											2016-07-25 22:31:10 +07:00
										 |  |  |         # External source (YouTube) | 
					
						
							| 
									
										
										
										
											2015-02-12 00:11:33 +08:00
										 |  |  |         'url': 'http://www.camdemy.com/media/14842', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							|  |  |  |             'id': '2vsYQzNIsJo', | 
					
						
							|  |  |  |             'ext': 'mp4', | 
					
						
							| 
									
										
										
										
											2016-07-25 22:31:10 +07:00
										 |  |  |             'title': 'Excel 2013 Tutorial - How to add Password Protection', | 
					
						
							|  |  |  |             'description': 'Excel 2013 Tutorial for Beginners - How to add Password Protection', | 
					
						
							| 
									
										
										
										
											2015-02-12 00:11:33 +08:00
										 |  |  |             'upload_date': '20130211', | 
					
						
							|  |  |  |             'uploader': 'Hun Kim', | 
					
						
							|  |  |  |             'uploader_id': 'hunkimtutorials', | 
					
						
							| 
									
										
										
										
											2016-07-25 22:31:10 +07:00
										 |  |  |         }, | 
					
						
							|  |  |  |         'params': { | 
					
						
							|  |  |  |             'skip_download': True, | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2015-02-11 16:39:15 +08:00
										 |  |  |     }] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def _real_extract(self, url): | 
					
						
							|  |  |  |         video_id = self._match_id(url) | 
					
						
							| 
									
										
										
										
											2016-07-25 22:31:10 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         webpage = self._download_webpage(url, video_id) | 
					
						
							| 
									
										
										
										
											2015-02-11 16:39:15 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-12 08:55:06 +01:00
										 |  |  |         src_from = self._html_search_regex( | 
					
						
							| 
									
										
										
										
											2016-07-25 22:31:10 +07:00
										 |  |  |             r"class=['\"]srcFrom['\"][^>]*>Sources?(?:\s+from)?\s*:\s*<a[^>]+(?:href|title)=(['\"])(?P<url>(?:(?!\1).)+)\1", | 
					
						
							|  |  |  |             webpage, 'external source', default=None, group='url') | 
					
						
							| 
									
										
										
										
											2015-02-12 08:55:06 +01:00
										 |  |  |         if src_from: | 
					
						
							|  |  |  |             return self.url_result(src_from) | 
					
						
							| 
									
										
										
										
											2015-02-12 00:11:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-11 16:39:15 +08:00
										 |  |  |         oembed_obj = self._download_json( | 
					
						
							|  |  |  |             'http://www.camdemy.com/oembed/?format=json&url=' + url, video_id) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-25 22:35:12 +07:00
										 |  |  |         title = oembed_obj['title'] | 
					
						
							| 
									
										
										
										
											2015-02-11 16:39:15 +08:00
										 |  |  |         thumb_url = oembed_obj['thumbnail_url'] | 
					
						
							| 
									
										
										
										
											2015-02-12 14:23:25 +08:00
										 |  |  |         video_folder = compat_urlparse.urljoin(thumb_url, 'video/') | 
					
						
							| 
									
										
										
										
											2015-02-12 08:55:06 +01:00
										 |  |  |         file_list_doc = self._download_xml( | 
					
						
							| 
									
										
										
										
											2015-02-12 14:23:25 +08:00
										 |  |  |             compat_urlparse.urljoin(video_folder, 'fileList.xml'), | 
					
						
							| 
									
										
										
										
											2016-07-25 22:31:10 +07:00
										 |  |  |             video_id, 'Downloading filelist XML') | 
					
						
							| 
									
										
										
										
											2015-02-12 08:55:06 +01:00
										 |  |  |         file_name = file_list_doc.find('./video/item/fileName').text | 
					
						
							|  |  |  |         video_url = compat_urlparse.urljoin(video_folder, file_name) | 
					
						
							| 
									
										
										
										
											2015-02-11 16:39:15 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-25 22:31:10 +07:00
										 |  |  |         # Some URLs return "No permission or not login" in a webpage despite being | 
					
						
							|  |  |  |         # freely available via oembed JSON URL (e.g. http://www.camdemy.com/media/13885) | 
					
						
							|  |  |  |         upload_date = unified_strdate(self._search_regex( | 
					
						
							|  |  |  |             r'>published on ([^<]+)<', webpage, | 
					
						
							|  |  |  |             'upload date', default=None)) | 
					
						
							|  |  |  |         view_count = str_to_int(self._search_regex( | 
					
						
							|  |  |  |             r'role=["\']viewCnt["\'][^>]*>([\d,.]+) views', | 
					
						
							|  |  |  |             webpage, 'view count', default=None)) | 
					
						
							|  |  |  |         description = self._html_search_meta( | 
					
						
							|  |  |  |             'description', webpage, default=None) or clean_html( | 
					
						
							|  |  |  |             oembed_obj.get('description')) | 
					
						
							| 
									
										
										
										
											2015-02-11 16:39:15 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return { | 
					
						
							|  |  |  |             'id': video_id, | 
					
						
							| 
									
										
										
										
											2015-02-12 08:55:06 +01:00
										 |  |  |             'url': video_url, | 
					
						
							| 
									
										
										
										
											2016-07-25 22:35:12 +07:00
										 |  |  |             'title': title, | 
					
						
							| 
									
										
										
										
											2015-02-11 16:39:15 +08:00
										 |  |  |             'thumbnail': thumb_url, | 
					
						
							| 
									
										
										
										
											2016-07-25 22:31:10 +07:00
										 |  |  |             'description': description, | 
					
						
							| 
									
										
										
										
											2016-07-25 22:35:12 +07:00
										 |  |  |             'creator': oembed_obj.get('author_name'), | 
					
						
							|  |  |  |             'duration': parse_duration(oembed_obj.get('duration')), | 
					
						
							| 
									
										
										
										
											2016-07-25 22:31:10 +07:00
										 |  |  |             'upload_date': upload_date, | 
					
						
							| 
									
										
										
										
											2015-02-12 08:55:06 +01:00
										 |  |  |             'view_count': view_count, | 
					
						
							| 
									
										
										
										
											2015-02-11 16:39:15 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-02-12 14:13:19 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class CamdemyFolderIE(InfoExtractor): | 
					
						
							| 
									
										
										
										
											2016-09-08 18:29:05 +07:00
										 |  |  |     _VALID_URL = r'https?://(?:www\.)?camdemy\.com/folder/(?P<id>\d+)' | 
					
						
							| 
									
										
										
										
											2015-02-12 14:13:19 +08:00
										 |  |  |     _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 | 
					
						
							| 
									
										
										
										
											2015-02-12 14:23:25 +08:00
										 |  |  |         parsed_url = list(compat_urlparse.urlparse(url)) | 
					
						
							|  |  |  |         query = dict(compat_urlparse.parse_qsl(parsed_url[4])) | 
					
						
							| 
									
										
										
										
											2015-02-12 14:13:19 +08:00
										 |  |  |         query.update({'displayMode': 'list'}) | 
					
						
							| 
									
										
										
										
											2016-03-26 01:46:57 +06:00
										 |  |  |         parsed_url[4] = compat_urllib_parse_urlencode(query) | 
					
						
							| 
									
										
										
										
											2015-02-12 14:23:25 +08:00
										 |  |  |         final_url = compat_urlparse.urlunparse(parsed_url) | 
					
						
							| 
									
										
										
										
											2015-02-12 14:13:19 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         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) |