]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/camdemy.py
[camdemy] Add new extractor
[yt-dlp.git] / youtube_dl / extractor / camdemy.py
CommitLineData
8708d764
YCH
1# coding: utf-8
2from __future__ import unicode_literals
3
4import re
5
6from .common import InfoExtractor
7from ..compat import compat_urlparse
8from ..utils import parse_iso8601
9
10
11class CamdemyIE(InfoExtractor):
12 _VALID_URL = r'http://www.camdemy.com/media/(?P<id>\d+).*'
13 _TESTS = [{
14 # single file
15 'url': 'http://www.camdemy.com/media/5181/',
16 'md5': '5a5562b6a98b37873119102e052e311b',
17 'info_dict': {
18 'id': '5181',
19 'ext': 'mp4',
20 'title': 'Ch1-1 Introduction, Signals (02-23-2012)',
21 'thumbnail': 're:^https?://.*\.jpg$',
22 'description': '',
23 'creator': 'ss11spring',
24 'upload_date': '20130114',
25 'timestamp': 1358154556,
26 }
27 }, {
28 # With non-empty description
29 'url': 'http://www.camdemy.com/media/13885',
30 'md5': '4576a3bb2581f86c61044822adbd1249',
31 'info_dict': {
32 'id': '13885',
33 'ext': 'mp4',
34 'title': 'EverCam + Camdemy QuickStart',
35 'thumbnail': 're:^https?://.*\.jpg$',
36 'description': 'md5:050b62f71ed62928f8a35f1a41e186c9',
37 'creator': 'evercam',
38 'upload_date': '20140620',
39 'timestamp': 1403271569,
40 }
41 }]
42
43 def _real_extract(self, url):
44 video_id = self._match_id(url)
45
46 page = self._download_webpage(url, video_id)
47
48 oembed_obj = self._download_json(
49 'http://www.camdemy.com/oembed/?format=json&url=' + url, video_id)
50
51 thumb_url = oembed_obj['thumbnail_url']
52 video_folder = compat_urlparse.urljoin(thumb_url, 'video/')
53 fileListXML = self._download_xml(
54 compat_urlparse.urljoin(video_folder, 'fileList.xml'),
55 video_id, 'Filelist XML')
56 fileName = fileListXML.find('./video/item/fileName').text
57
58 creation_time = self._html_search_regex(
59 r"<div class='title'>Posted :</div>.*<div class='value'>([0-9:\- ]+)<",
60 page, 'creation time', flags=re.MULTILINE | re.DOTALL) + '+08:00'
61 creation_timestamp = parse_iso8601(creation_time, delimiter=' ')
62
63 view_count_str = self._html_search_regex(
64 r"<div class='title'>Views :</div>.*<div class='value'>([0-9,]+)<",
65 page, 'view count', flags=re.MULTILINE | re.DOTALL)
66 views = int(view_count_str.replace(',', ''))
67
68 return {
69 'id': video_id,
70 'url': compat_urlparse.urljoin(video_folder, fileName),
71 'title': oembed_obj['title'],
72 'thumbnail': thumb_url,
73 'description': self._html_search_meta('description', page),
74 'creator': oembed_obj['author_name'],
75 'duration': oembed_obj['duration'],
76 'timestamp': creation_timestamp,
77 'view_count': views,
78 }