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