X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;ds=sidebyside;f=youtube_dl%2Fextractor%2Fcamdemy.py;h=6ffbeabd371fd6f80a9ead1d23762f760a13ba2f;hb=daa0df9e8beac1325e5fb55d828e7a3a38e74bf6;hp=9a6341f0f6e3595ffc4764870da0b0dfcc91a583;hpb=8367d3f3cbad7ddae5116c3cd5d39ebfed9711c5;p=youtube-dl diff --git a/youtube_dl/extractor/camdemy.py b/youtube_dl/extractor/camdemy.py index 9a6341f0f..6ffbeabd3 100644 --- a/youtube_dl/extractor/camdemy.py +++ b/youtube_dl/extractor/camdemy.py @@ -1,15 +1,22 @@ # coding: utf-8 from __future__ import unicode_literals +import datetime import re from .common import InfoExtractor -from ..compat import compat_urlparse -from ..utils import parse_iso8601 +from ..compat import ( + compat_urllib_parse_urlencode, + compat_urlparse, +) +from ..utils import ( + parse_iso8601, + str_to_int, +) class CamdemyIE(InfoExtractor): - _VALID_URL = r'http://www.camdemy.com/media/(?P\d+).*' + _VALID_URL = r'https?://(?:www\.)?camdemy\.com/media/(?P\d+)' _TESTS = [{ # single file 'url': 'http://www.camdemy.com/media/5181/', @@ -23,6 +30,7 @@ class CamdemyIE(InfoExtractor): 'creator': 'ss11spring', 'upload_date': '20130114', 'timestamp': 1358154556, + 'view_count': int, } }, { # With non-empty description @@ -55,44 +63,91 @@ class CamdemyIE(InfoExtractor): def _real_extract(self, url): video_id = self._match_id(url) - page = self._download_webpage(url, video_id) - srcFrom = self._html_search_regex( + src_from = self._html_search_regex( r"
Source: Posted :
.*
([0-9:\- ]+)<", - page, 'creation time', flags=re.MULTILINE | re.DOTALL) + '+08:00' - creation_timestamp = parse_iso8601(creation_time, delimiter=' ') + file_name = file_list_doc.find('./video/item/fileName').text + video_url = compat_urlparse.urljoin(video_folder, file_name) - view_count_str = self._html_search_regex( - r"
Views :
.*
([0-9,]+)<", - page, 'view count', flags=re.MULTILINE | re.DOTALL) - views = int(view_count_str.replace(',', '')) + timestamp = parse_iso8601(self._html_search_regex( + r"
Posted\s*:
\s*
([^<>]+)<", + page, 'creation time', fatal=False), + delimiter=' ', timezone=datetime.timedelta(hours=8)) + view_count = str_to_int(self._html_search_regex( + r"
Views\s*:
\s*
([^<>]+)<", + page, 'view count', fatal=False)) return { 'id': video_id, - 'url': compat_urlparse.urljoin(video_folder, fileName), + 'url': video_url, 'title': oembed_obj['title'], 'thumbnail': thumb_url, 'description': self._html_search_meta('description', page), 'creator': oembed_obj['author_name'], 'duration': oembed_obj['duration'], - 'timestamp': creation_timestamp, - 'view_count': views, + 'timestamp': timestamp, + 'view_count': view_count, } + + +class CamdemyFolderIE(InfoExtractor): + _VALID_URL = r'https?://www.camdemy.com/folder/(?P\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)