]>
Commit | Line | Data |
---|---|---|
cd8b8302 PH |
1 | import re |
2 | ||
3 | from .common import InfoExtractor | |
4 | from ..utils import ( | |
5 | ExtractorError, | |
6 | ) | |
7 | ||
8 | ||
9 | class TeamcocoIE(InfoExtractor): | |
10 | _VALID_URL = r'http://teamcoco\.com/video/(?P<url_title>.*)' | |
6f5ac90c PH |
11 | _TEST = { |
12 | u'url': u'http://teamcoco.com/video/louis-ck-interview-george-w-bush', | |
13 | u'file': u'19705.mp4', | |
ac2547f5 | 14 | u'md5': u'cde9ba0fa3506f5f017ce11ead928f9a', |
6f5ac90c PH |
15 | u'info_dict': { |
16 | u"description": u"Louis C.K. got starstruck by George W. Bush, so what? Part one.", | |
17 | u"title": u"Louis C.K. Interview Pt. 1 11/3/11" | |
18 | } | |
19 | } | |
cd8b8302 PH |
20 | |
21 | def _real_extract(self, url): | |
22 | mobj = re.match(self._VALID_URL, url) | |
23 | if mobj is None: | |
24 | raise ExtractorError(u'Invalid URL: %s' % url) | |
25 | url_title = mobj.group('url_title') | |
26 | webpage = self._download_webpage(url, url_title) | |
27 | ||
28 | video_id = self._html_search_regex(r'<article class="video" data-id="(\d+?)"', | |
29 | webpage, u'video id') | |
30 | ||
31 | self.report_extraction(video_id) | |
32 | ||
cd8b8302 | 33 | data_url = 'http://teamcoco.com/cvp/2.0/%s.xml' % video_id |
e26f8712 | 34 | data = self._download_xml(data_url, video_id, 'Downloading data webpage') |
cd8b8302 | 35 | |
ac2547f5 | 36 | |
e7e6b54d JMF |
37 | qualities = ['500k', '480p', '1000k', '720p', '1080p'] |
38 | formats = [] | |
39 | for file in data.findall('files/file'): | |
40 | if file.attrib.get('playmode') == 'all': | |
41 | # it just duplicates one of the entries | |
42 | break | |
43 | file_url = file.text | |
44 | m_format = re.search(r'(\d+(k|p))\.mp4', file_url) | |
45 | if m_format is not None: | |
46 | format_id = m_format.group(1) | |
47 | else: | |
48 | format_id = file.attrib['bitrate'] | |
49 | formats.append({ | |
50 | 'url': file_url, | |
51 | 'ext': 'mp4', | |
52 | 'format_id': format_id, | |
53 | }) | |
54 | def sort_key(f): | |
ac2547f5 | 55 | try: |
e7e6b54d JMF |
56 | return qualities.index(f['format_id']) |
57 | except ValueError: | |
58 | return -1 | |
59 | formats.sort(key=sort_key) | |
60 | if not formats: | |
cc13cc02 | 61 | raise ExtractorError(u'Unable to extract video URL') |
cd8b8302 | 62 | |
e7e6b54d | 63 | return { |
cd8b8302 | 64 | 'id': video_id, |
e7e6b54d | 65 | 'formats': formats, |
46720279 JMF |
66 | 'title': self._og_search_title(webpage), |
67 | 'thumbnail': self._og_search_thumbnail(webpage), | |
68 | 'description': self._og_search_description(webpage), | |
e7e6b54d | 69 | } |