]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/ellentube.py
6eb00f9c98cb9fea596819b8502a802d931a50ad
[yt-dlp.git] / yt_dlp / extractor / ellentube.py
1 from .common import InfoExtractor
2 from ..utils import (
3 clean_html,
4 extract_attributes,
5 float_or_none,
6 int_or_none,
7 try_get,
8 )
9
10
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)
18
19 def _extract_video(self, data, video_id):
20 title = data['title']
21
22 formats = []
23 duration = None
24 for entry in data.get('media'):
25 if entry.get('id') == 'm3u8':
26 formats, subtitles = self._extract_m3u8_formats_and_subtitles(
27 entry['url'], video_id, 'mp4',
28 entry_protocol='m3u8_native', m3u8_id='hls')
29 duration = int_or_none(entry.get('duration'))
30 break
31
32 def get_insight(kind):
33 return int_or_none(try_get(
34 data, lambda x: x['insight']['%ss' % kind]))
35
36 return {
37 'extractor_key': EllenTubeIE.ie_key(),
38 'id': video_id,
39 'title': title,
40 'description': data.get('description'),
41 'duration': duration,
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'),
46 'formats': formats,
47 'subtitles': subtitles,
48 }
49
50
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',
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',
67 'thumbnail': r're:^https?://.+?',
68 'duration': 514,
69 'timestamp': 1508505120,
70 'upload_date': '20171020',
71 'view_count': int,
72 'like_count': int,
73 }
74 }, {
75 'url': 'ellentube:734a3353-f697-4e79-9ca9-bfc3002dc1e0',
76 'only_matching': True,
77 }]
78
79 def _real_extract(self, url):
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)
85
86
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 }
93
94 def _real_extract(self, url):
95 display_id = self._match_id(url)
96 webpage = self._download_webpage(url, display_id)
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)
101
102
103 class EllenTubePlaylistIE(EllenTubeBaseIE):
104 _VALID_URL = r'https?://(?:www\.)?ellentube\.com/(?:episode|studios)/(?P<id>.+?)\.html'
105 _TESTS = [{
106 'url': 'https://www.ellentube.com/episode/dax-shepard-jordan-fisher-haim.html',
107 'info_dict': {
108 'id': 'dax-shepard-jordan-fisher-haim',
109 'title': "Dax Shepard, 'DWTS' Team Jordan Fisher & Lindsay Arnold, HAIM",
110 'description': 'md5:bfc982194dabb3f4e325e43aa6b2e21c',
111 },
112 'playlist_count': 6,
113 }, {
114 'url': 'https://www.ellentube.com/studios/macey-goes-rving0.html',
115 'only_matching': True,
116 }]
117
118 def _real_extract(self, url):
119 display_id = self._match_id(url)
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')))