]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/teamcoco.py
[vine] Modernize
[yt-dlp.git] / youtube_dl / extractor / teamcoco.py
CommitLineData
bb198c95
PH
1from __future__ import unicode_literals
2
314368c8 3import base64
cd8b8302
PH
4import re
5
6from .common import InfoExtractor
314368c8 7from ..utils import qualities
cd8b8302
PH
8
9
10class TeamcocoIE(InfoExtractor):
dfb2cb5c 11 _VALID_URL = r'http://teamcoco\.com/video/(?P<video_id>[0-9]+)?/?(?P<display_id>.*)'
bb799e81 12 _TESTS = [
9e1a5b84
JW
13 {
14 'url': 'http://teamcoco.com/video/80187/conan-becomes-a-mary-kay-beauty-consultant',
9e1a5b84
JW
15 'md5': '3f7746aa0dc86de18df7539903d399ea',
16 'info_dict': {
17d2712d
PH
17 'id': '80187',
18 'ext': 'mp4',
9e1a5b84 19 'title': 'Conan Becomes A Mary Kay Beauty Consultant',
641eb10d
NJ
20 'description': 'Mary Kay is perhaps the most trusted name in female beauty, so of course Conan is a natural choice to sell their products.',
21 'age_limit': 0,
9e1a5b84
JW
22 }
23 }, {
24 'url': 'http://teamcoco.com/video/louis-ck-interview-george-w-bush',
9e1a5b84
JW
25 'md5': 'cde9ba0fa3506f5f017ce11ead928f9a',
26 'info_dict': {
17d2712d
PH
27 'id': '19705',
28 'ext': 'mp4',
314368c8
NJ
29 'description': 'Louis C.K. got starstruck by George W. Bush, so what? Part one.',
30 'title': 'Louis C.K. Interview Pt. 1 11/3/11',
641eb10d 31 'age_limit': 0,
9e1a5b84 32 }
bb799e81 33 }
bb799e81 34 ]
3811c567
NJ
35 _VIDEO_ID_REGEXES = (
36 r'"eVar42"\s*:\s*(\d+)',
37 r'Ginger\.TeamCoco\.openInApp\("video",\s*"([^"]+)"',
38 r'"id_not"\s*:\s*(\d+)'
39 )
cd8b8302
PH
40
41 def _real_extract(self, url):
42 mobj = re.match(self._VALID_URL, url)
dfb2cb5c
PH
43
44 display_id = mobj.group('display_id')
45 webpage = self._download_webpage(url, display_id)
5f6a1245 46
314368c8 47 video_id = mobj.group('video_id')
dfb2cb5c 48 if not video_id:
04ee53ec 49 video_id = self._html_search_regex(
3811c567 50 self._VIDEO_ID_REGEXES, webpage, 'video id')
cd8b8302 51
314368c8
NJ
52 embed_url = 'http://teamcoco.com/embed/v/%s' % video_id
53 embed = self._download_webpage(
54 embed_url, video_id, 'Downloading embed page')
55
8b910bda 56 player_data = self._parse_json(self._search_regex(
fbfcc297 57 r'Y\.Ginger\.Module\.Player(?:;var\s*player\s*=\s*new\s*m)?\((\{.*?\})\);', embed, 'player data'), video_id)
314368c8 58 data = self._parse_json(
8b910bda 59 base64.b64decode(player_data['preload'].encode('ascii')).decode('utf-8'), video_id)
cd8b8302 60
e7e6b54d 61 formats = []
314368c8
NJ
62 get_quality = qualities(['500k', '480p', '1000k', '720p', '1080p'])
63 for filed in data['files']:
64 m_format = re.search(r'(\d+(k|p))\.mp4', filed['url'])
e7e6b54d
JMF
65 if m_format is not None:
66 format_id = m_format.group(1)
67 else:
314368c8 68 format_id = filed['bitrate']
befdc8f3 69 tbr = (
314368c8
NJ
70 int(filed['bitrate'])
71 if filed['bitrate'].isdigit()
befdc8f3
PH
72 else None)
73
e7e6b54d 74 formats.append({
314368c8 75 'url': filed['url'],
e7e6b54d 76 'ext': 'mp4',
befdc8f3 77 'tbr': tbr,
e7e6b54d 78 'format_id': format_id,
314368c8 79 'quality': get_quality(format_id),
e7e6b54d 80 })
befdc8f3
PH
81
82 self._sort_formats(formats)
cd8b8302 83
e7e6b54d 84 return {
bb198c95 85 'id': video_id,
dfb2cb5c 86 'display_id': display_id,
e7e6b54d 87 'formats': formats,
314368c8
NJ
88 'title': data['title'],
89 'thumbnail': data.get('thumb', {}).get('href'),
90 'description': data.get('teaser'),
641eb10d 91 'age_limit': self._family_friendly_search(webpage),
e7e6b54d 92 }