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