]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/teamcoco.py
[ntvru] Adapt to new direct delivery and modernize (Closes #4918)
[yt-dlp.git] / youtube_dl / extractor / teamcoco.py
CommitLineData
bb198c95
PH
1from __future__ import unicode_literals
2
cd8b8302
PH
3import re
4
5from .common import InfoExtractor
cd8b8302
PH
6
7
8class TeamcocoIE(InfoExtractor):
dfb2cb5c 9 _VALID_URL = r'http://teamcoco\.com/video/(?P<video_id>[0-9]+)?/?(?P<display_id>.*)'
bb799e81 10 _TESTS = [
9e1a5b84
JW
11 {
12 'url': 'http://teamcoco.com/video/80187/conan-becomes-a-mary-kay-beauty-consultant',
9e1a5b84
JW
13 'md5': '3f7746aa0dc86de18df7539903d399ea',
14 'info_dict': {
17d2712d
PH
15 'id': '80187',
16 'ext': 'mp4',
9e1a5b84 17 'title': 'Conan Becomes A Mary Kay Beauty Consultant',
641eb10d
NJ
18 'description': 'Mary Kay is perhaps the most trusted name in female beauty, so of course Conan is a natural choice to sell their products.',
19 'age_limit': 0,
9e1a5b84
JW
20 }
21 }, {
22 'url': 'http://teamcoco.com/video/louis-ck-interview-george-w-bush',
9e1a5b84
JW
23 'md5': 'cde9ba0fa3506f5f017ce11ead928f9a',
24 'info_dict': {
17d2712d
PH
25 'id': '19705',
26 'ext': 'mp4',
9e1a5b84 27 "description": "Louis C.K. got starstruck by George W. Bush, so what? Part one.",
641eb10d
NJ
28 "title": "Louis C.K. Interview Pt. 1 11/3/11",
29 'age_limit': 0,
9e1a5b84 30 }
bb799e81 31 }
bb799e81 32 ]
cd8b8302
PH
33
34 def _real_extract(self, url):
35 mobj = re.match(self._VALID_URL, url)
dfb2cb5c
PH
36
37 display_id = mobj.group('display_id')
38 webpage = self._download_webpage(url, display_id)
5f6a1245 39
fa387d2d 40 video_id = mobj.group("video_id")
dfb2cb5c 41 if not video_id:
04ee53ec 42 video_id = self._html_search_regex(
17d2712d 43 r'<div\s+class="player".*?data-id="(\d+?)"',
04ee53ec 44 webpage, 'video id')
cd8b8302 45
cd8b8302 46 data_url = 'http://teamcoco.com/cvp/2.0/%s.xml' % video_id
dfb2cb5c
PH
47 data = self._download_xml(
48 data_url, display_id, 'Downloading data webpage')
cd8b8302 49
e7e6b54d
JMF
50 qualities = ['500k', '480p', '1000k', '720p', '1080p']
51 formats = []
befdc8f3
PH
52 for filed in data.findall('files/file'):
53 if filed.attrib.get('playmode') == 'all':
e7e6b54d
JMF
54 # it just duplicates one of the entries
55 break
befdc8f3 56 file_url = filed.text
e7e6b54d
JMF
57 m_format = re.search(r'(\d+(k|p))\.mp4', file_url)
58 if m_format is not None:
59 format_id = m_format.group(1)
60 else:
befdc8f3
PH
61 format_id = filed.attrib['bitrate']
62 tbr = (
63 int(filed.attrib['bitrate'])
64 if filed.attrib['bitrate'].isdigit()
65 else None)
66
67 try:
68 quality = qualities.index(format_id)
69 except ValueError:
70 quality = -1
e7e6b54d
JMF
71 formats.append({
72 'url': file_url,
73 'ext': 'mp4',
befdc8f3 74 'tbr': tbr,
e7e6b54d 75 'format_id': format_id,
befdc8f3 76 'quality': quality,
e7e6b54d 77 })
befdc8f3
PH
78
79 self._sort_formats(formats)
cd8b8302 80
e7e6b54d 81 return {
bb198c95 82 'id': video_id,
dfb2cb5c 83 'display_id': display_id,
e7e6b54d 84 'formats': formats,
bb198c95
PH
85 'title': self._og_search_title(webpage),
86 'thumbnail': self._og_search_thumbnail(webpage),
46720279 87 'description': self._og_search_description(webpage),
641eb10d 88 'age_limit': self._family_friendly_search(webpage),
e7e6b54d 89 }