]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/teamcoco.py
[gdcvault] Fix rtmp streams (Closes #5024)
[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 ]
3811c567
NJ
33 _VIDEO_ID_REGEXES = (
34 r'"eVar42"\s*:\s*(\d+)',
35 r'Ginger\.TeamCoco\.openInApp\("video",\s*"([^"]+)"',
36 r'"id_not"\s*:\s*(\d+)'
37 )
cd8b8302
PH
38
39 def _real_extract(self, url):
40 mobj = re.match(self._VALID_URL, url)
dfb2cb5c
PH
41
42 display_id = mobj.group('display_id')
43 webpage = self._download_webpage(url, display_id)
5f6a1245 44
fa387d2d 45 video_id = mobj.group("video_id")
dfb2cb5c 46 if not video_id:
04ee53ec 47 video_id = self._html_search_regex(
3811c567 48 self._VIDEO_ID_REGEXES, webpage, 'video id')
cd8b8302 49
cd8b8302 50 data_url = 'http://teamcoco.com/cvp/2.0/%s.xml' % video_id
dfb2cb5c
PH
51 data = self._download_xml(
52 data_url, display_id, 'Downloading data webpage')
cd8b8302 53
e7e6b54d
JMF
54 qualities = ['500k', '480p', '1000k', '720p', '1080p']
55 formats = []
befdc8f3
PH
56 for filed in data.findall('files/file'):
57 if filed.attrib.get('playmode') == 'all':
e7e6b54d
JMF
58 # it just duplicates one of the entries
59 break
befdc8f3 60 file_url = filed.text
e7e6b54d
JMF
61 m_format = re.search(r'(\d+(k|p))\.mp4', file_url)
62 if m_format is not None:
63 format_id = m_format.group(1)
64 else:
befdc8f3
PH
65 format_id = filed.attrib['bitrate']
66 tbr = (
67 int(filed.attrib['bitrate'])
68 if filed.attrib['bitrate'].isdigit()
69 else None)
70
71 try:
72 quality = qualities.index(format_id)
73 except ValueError:
74 quality = -1
e7e6b54d
JMF
75 formats.append({
76 'url': file_url,
77 'ext': 'mp4',
befdc8f3 78 'tbr': tbr,
e7e6b54d 79 'format_id': format_id,
befdc8f3 80 'quality': quality,
e7e6b54d 81 })
befdc8f3
PH
82
83 self._sort_formats(formats)
cd8b8302 84
e7e6b54d 85 return {
bb198c95 86 'id': video_id,
dfb2cb5c 87 'display_id': display_id,
e7e6b54d 88 'formats': formats,
bb198c95
PH
89 'title': self._og_search_title(webpage),
90 'thumbnail': self._og_search_thumbnail(webpage),
46720279 91 'description': self._og_search_description(webpage),
641eb10d 92 'age_limit': self._family_friendly_search(webpage),
e7e6b54d 93 }