]>
jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/teamcoco.py
1 # -*- coding: utf-8 -*-
2 from __future__
import unicode_literals
8 from .common
import InfoExtractor
13 from ..compat
import compat_ord
16 class TeamcocoIE(InfoExtractor
):
17 _VALID_URL
= r
'http://teamcoco\.com/video/(?P<video_id>[0-9]+)?/?(?P<display_id>.*)'
20 'url': 'http://teamcoco.com/video/80187/conan-becomes-a-mary-kay-beauty-consultant',
21 'md5': '3f7746aa0dc86de18df7539903d399ea',
25 'title': 'Conan Becomes A Mary Kay Beauty Consultant',
26 'description': 'Mary Kay is perhaps the most trusted name in female beauty, so of course Conan is a natural choice to sell their products.',
31 'url': 'http://teamcoco.com/video/louis-ck-interview-george-w-bush',
32 'md5': 'cde9ba0fa3506f5f017ce11ead928f9a',
36 'description': 'Louis C.K. got starstruck by George W. Bush, so what? Part one.',
37 'title': 'Louis C.K. Interview Pt. 1 11/3/11',
42 'url': 'http://teamcoco.com/video/timothy-olyphant-drinking-whiskey',
46 'title': 'Timothy Olyphant Raises A Toast To “Justified”',
47 'description': 'md5:15501f23f020e793aeca761205e42c24',
50 'skip_download': True, # m3u8 downloads
55 r
'"eVar42"\s*:\s*(\d+)',
56 r
'Ginger\.TeamCoco\.openInApp\("video",\s*"([^"]+)"',
57 r
'"id_not"\s*:\s*(\d+)'
60 def _real_extract(self
, url
):
61 mobj
= re
.match(self
._VALID
_URL
, url
)
63 display_id
= mobj
.group('display_id')
64 webpage
= self
._download
_webpage
(url
, display_id
)
66 video_id
= mobj
.group('video_id')
68 video_id
= self
._html
_search
_regex
(
69 self
._VIDEO
_ID
_REGEXES
, webpage
, 'video id')
72 preloads
= re
.findall(r
'"preload":\s*"([^"]+)"', webpage
)
74 preload
= max([(len(p
), p
) for p
in preloads
])[1]
77 preload
= ''.join(re
.findall(r
'this\.push\("([^"]+)"\);', webpage
))
80 preload
= self
._html
_search
_regex
([
81 r
'player,\[?"([^"]+)"\]?', r
'player.init\(\[?"([^"]+)"\]?\)'
82 ], webpage
.replace('","', ''), 'preload data', default
=None)
85 preload_codes
= self
._html
_search
_regex
(
86 r
'(function.+)setTimeout\(function\(\)\{playlist',
87 webpage
, 'preload codes')
88 base64_fragments
= re
.findall(r
'"([a-zA-z0-9+/=]+)"', preload_codes
)
89 base64_fragments
.remove('init')
90 for i
in range(len(base64_fragments
)):
91 cur_sequence
= (''.join(base64_fragments
[i
:] + base64_fragments
[:i
])).encode('ascii')
93 raw_data
= base64
.b64decode(cur_sequence
)
94 except (TypeError, binascii
.Error
):
96 if compat_ord(raw_data
[0]) == compat_ord('{'):
97 data
= self
._parse
_json
(raw_data
.decode('utf-8'), video_id
, fatal
=False)
99 if not preload
and not data
:
100 raise ExtractorError(
101 'Preload information could not be extracted', expected
=True)
104 data
= self
._parse
_json
(
105 base64
.b64decode(preload
.encode('ascii')).decode('utf-8'), video_id
)
108 get_quality
= qualities(['500k', '480p', '1000k', '720p', '1080p'])
109 for filed
in data
['files']:
110 if filed
['type'] == 'hls':
111 formats
.extend(self
._extract
_m
3u8_formats
(
112 filed
['url'], video_id
, ext
='mp4'))
114 m_format
= re
.search(r
'(\d+(k|p))\.mp4', filed
['url'])
115 if m_format
is not None:
116 format_id
= m_format
.group(1)
118 format_id
= filed
['bitrate']
120 int(filed
['bitrate'])
121 if filed
['bitrate'].isdigit()
128 'format_id': format_id
,
129 'quality': get_quality(format_id
),
132 self
._sort
_formats
(formats
)
136 'display_id': display_id
,
138 'title': data
['title'],
139 'thumbnail': data
.get('thumb', {}).get('href'),
140 'description': data
.get('teaser'),
141 'duration': data
.get('duration'),
142 'age_limit': self
._family
_friendly
_search
(webpage
),