]>
Commit | Line | Data |
---|---|---|
e2707a83 AS |
1 | from .common import InfoExtractor |
2 | from ..utils import ( | |
3 | clean_html, | |
2a57b62b S |
4 | extract_attributes, |
5 | float_or_none, | |
e2707a83 | 6 | int_or_none, |
2a57b62b | 7 | try_get, |
e2707a83 AS |
8 | ) |
9 | ||
10 | ||
2a57b62b S |
11 | class EllenTubeBaseIE(InfoExtractor): |
12 | def _extract_data_config(self, webpage, video_id): | |
13 | details = self._search_regex( | |
14 | r'(<[^>]+\bdata-component=(["\'])[Dd]etails.+?></div>)', webpage, | |
15 | 'details') | |
16 | return self._parse_json( | |
17 | extract_attributes(details)['data-config'], video_id) | |
e2707a83 | 18 | |
2a57b62b | 19 | def _extract_video(self, data, video_id): |
e2707a83 | 20 | title = data['title'] |
e2707a83 AS |
21 | |
22 | formats = [] | |
23 | duration = None | |
24 | for entry in data.get('media'): | |
25 | if entry.get('id') == 'm3u8': | |
ea5ca8e7 | 26 | formats, subtitles = self._extract_m3u8_formats_and_subtitles( |
2a57b62b S |
27 | entry['url'], video_id, 'mp4', |
28 | entry_protocol='m3u8_native', m3u8_id='hls') | |
e2707a83 AS |
29 | duration = int_or_none(entry.get('duration')) |
30 | break | |
2a57b62b S |
31 | |
32 | def get_insight(kind): | |
33 | return int_or_none(try_get( | |
34 | data, lambda x: x['insight']['%ss' % kind])) | |
35 | ||
e2707a83 | 36 | return { |
2a57b62b | 37 | 'extractor_key': EllenTubeIE.ie_key(), |
e2707a83 AS |
38 | 'id': video_id, |
39 | 'title': title, | |
2a57b62b | 40 | 'description': data.get('description'), |
e2707a83 | 41 | 'duration': duration, |
2a57b62b S |
42 | 'thumbnail': data.get('thumbnail'), |
43 | 'timestamp': float_or_none(data.get('publishTime'), scale=1000), | |
44 | 'view_count': get_insight('view'), | |
45 | 'like_count': get_insight('like'), | |
e2707a83 | 46 | 'formats': formats, |
ea5ca8e7 | 47 | 'subtitles': subtitles, |
e2707a83 AS |
48 | } |
49 | ||
50 | ||
2a57b62b S |
51 | class EllenTubeIE(EllenTubeBaseIE): |
52 | _VALID_URL = r'''(?x) | |
53 | (?: | |
54 | ellentube:| | |
55 | https://api-prod\.ellentube\.com/ellenapi/api/item/ | |
56 | ) | |
57 | (?P<id>[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}) | |
58 | ''' | |
59 | _TESTS = [{ | |
60 | 'url': 'https://api-prod.ellentube.com/ellenapi/api/item/0822171c-3829-43bf-b99f-d77358ae75e3', | |
e2707a83 AS |
61 | 'md5': '2fabc277131bddafdd120e0fc0f974c9', |
62 | 'info_dict': { | |
63 | 'id': '0822171c-3829-43bf-b99f-d77358ae75e3', | |
64 | 'ext': 'mp4', | |
65 | 'title': 'Ellen Meets Las Vegas Survivors Jesus Campos and Stephen Schuck', | |
66 | 'description': 'md5:76e3355e2242a78ad9e3858e5616923f', | |
2a57b62b | 67 | 'thumbnail': r're:^https?://.+?', |
e2707a83 | 68 | 'duration': 514, |
2a57b62b S |
69 | 'timestamp': 1508505120, |
70 | 'upload_date': '20171020', | |
71 | 'view_count': int, | |
72 | 'like_count': int, | |
e2707a83 | 73 | } |
2a57b62b S |
74 | }, { |
75 | 'url': 'ellentube:734a3353-f697-4e79-9ca9-bfc3002dc1e0', | |
76 | 'only_matching': True, | |
77 | }] | |
e2707a83 AS |
78 | |
79 | def _real_extract(self, url): | |
2a57b62b S |
80 | video_id = self._match_id(url) |
81 | data = self._download_json( | |
82 | 'https://api-prod.ellentube.com/ellenapi/api/item/%s' % video_id, | |
83 | video_id) | |
84 | return self._extract_video(data, video_id) | |
e2707a83 AS |
85 | |
86 | ||
2a57b62b S |
87 | class EllenTubeVideoIE(EllenTubeBaseIE): |
88 | _VALID_URL = r'https?://(?:www\.)?ellentube\.com/video/(?P<id>.+?)\.html' | |
89 | _TEST = { | |
90 | 'url': 'https://www.ellentube.com/video/ellen-meets-las-vegas-survivors-jesus-campos-and-stephen-schuck.html', | |
91 | 'only_matching': True, | |
92 | } | |
e2707a83 | 93 | |
2a57b62b S |
94 | def _real_extract(self, url): |
95 | display_id = self._match_id(url) | |
e2707a83 | 96 | webpage = self._download_webpage(url, display_id) |
2a57b62b S |
97 | video_id = self._extract_data_config(webpage, display_id)['id'] |
98 | return self.url_result( | |
99 | 'ellentube:%s' % video_id, ie=EllenTubeIE.ie_key(), | |
100 | video_id=video_id) | |
e2707a83 AS |
101 | |
102 | ||
2a57b62b S |
103 | class EllenTubePlaylistIE(EllenTubeBaseIE): |
104 | _VALID_URL = r'https?://(?:www\.)?ellentube\.com/(?:episode|studios)/(?P<id>.+?)\.html' | |
105 | _TESTS = [{ | |
e2707a83 AS |
106 | 'url': 'https://www.ellentube.com/episode/dax-shepard-jordan-fisher-haim.html', |
107 | 'info_dict': { | |
108 | 'id': 'dax-shepard-jordan-fisher-haim', | |
2a57b62b S |
109 | 'title': "Dax Shepard, 'DWTS' Team Jordan Fisher & Lindsay Arnold, HAIM", |
110 | 'description': 'md5:bfc982194dabb3f4e325e43aa6b2e21c', | |
e2707a83 AS |
111 | }, |
112 | 'playlist_count': 6, | |
2a57b62b | 113 | }, { |
e2707a83 | 114 | 'url': 'https://www.ellentube.com/studios/macey-goes-rving0.html', |
2a57b62b S |
115 | 'only_matching': True, |
116 | }] | |
e2707a83 AS |
117 | |
118 | def _real_extract(self, url): | |
119 | display_id = self._match_id(url) | |
2a57b62b S |
120 | webpage = self._download_webpage(url, display_id) |
121 | data = self._extract_data_config(webpage, display_id)['data'] | |
122 | feed = self._download_json( | |
123 | 'https://api-prod.ellentube.com/ellenapi/api/feed/?%s' | |
124 | % data['filter'], display_id) | |
125 | entries = [ | |
126 | self._extract_video(elem, elem['id']) | |
127 | for elem in feed if elem.get('type') == 'VIDEO' and elem.get('id')] | |
128 | return self.playlist_result( | |
129 | entries, display_id, data.get('title'), | |
130 | clean_html(data.get('description'))) |