2 import xml.etree.ElementTree
4 from .common import InfoExtractor
10 class TeamcocoIE(InfoExtractor):
11 _VALID_URL = r'http://teamcoco\.com/video/(?P<url_title>.*)'
13 u'url': u'http://teamcoco.com/video/louis-ck-interview-george-w-bush',
14 u'file': u'19705.mp4',
15 u'md5': u'cde9ba0fa3506f5f017ce11ead928f9a',
17 u"description": u"Louis C.K. got starstruck by George W. Bush, so what? Part one.",
18 u"title": u"Louis C.K. Interview Pt. 1 11/3/11"
22 def _real_extract(self, url):
23 mobj = re.match(self._VALID_URL, url)
25 raise ExtractorError(u'Invalid URL: %s' % url)
26 url_title = mobj.group('url_title')
27 webpage = self._download_webpage(url, url_title)
29 video_id = self._html_search_regex(r'<article class="video" data-id="(\d+?)"',
32 self.report_extraction(video_id)
34 data_url = 'http://teamcoco.com/cvp/2.0/%s.xml' % video_id
35 data_xml = self._download_webpage(data_url, video_id, 'Downloading data webpage')
36 data = xml.etree.ElementTree.fromstring(data_xml.encode('utf-8'))
39 qualities = ['500k', '480p', '1000k', '720p', '1080p']
41 for file in data.findall('files/file'):
42 if file.attrib.get('playmode') == 'all':
43 # it just duplicates one of the entries
46 m_format = re.search(r'(\d+(k|p))\.mp4', file_url)
47 if m_format is not None:
48 format_id = m_format.group(1)
50 format_id = file.attrib['bitrate']
54 'format_id': format_id,
58 return qualities.index(f['format_id'])
61 formats.sort(key=sort_key)
63 raise ExtractorError(u'Unable to extract video URL')
68 'title': self._og_search_title(webpage),
69 'thumbnail': self._og_search_thumbnail(webpage),
70 'description': self._og_search_description(webpage),