[ie/dropbox] Fix password-protected video extraction (#11636)
[yt-dlp3.git] / yt_dlp / extractor / contv.py
blob63d760a39ba8fbe9280e976b9e6cd076e452c42c
1 from .common import InfoExtractor
2 from ..utils import (
3 float_or_none,
4 int_or_none,
8 class CONtvIE(InfoExtractor):
9 _VALID_URL = r'https?://(?:www\.)?contv\.com/details-movie/(?P<id>[^/]+)'
10 _TESTS = [{
11 'url': 'https://www.contv.com/details-movie/CEG10022949/days-of-thrills-&-laughter',
12 'info_dict': {
13 'id': 'CEG10022949',
14 'ext': 'mp4',
15 'title': 'Days Of Thrills & Laughter',
16 'description': 'md5:5d6b3d0b1829bb93eb72898c734802eb',
17 'upload_date': '20180703',
18 'timestamp': 1530634789.61,
20 'params': {
21 # m3u8 download
22 'skip_download': True,
24 }, {
25 'url': 'https://www.contv.com/details-movie/CLIP-show_fotld_bts/fight-of-the-living-dead:-behind-the-scenes-bites',
26 'info_dict': {
27 'id': 'CLIP-show_fotld_bts',
28 'title': 'Fight of the Living Dead: Behind the Scenes Bites',
30 'playlist_mincount': 7,
33 def _real_extract(self, url):
34 video_id = self._match_id(url)
35 details = self._download_json(
36 'http://metax.contv.live.junctiontv.net/metax/2.5/details/' + video_id,
37 video_id, query={'device': 'web'})
39 if details.get('type') == 'episodic':
40 seasons = self._download_json(
41 'http://metax.contv.live.junctiontv.net/metax/2.5/seriesfeed/json/' + video_id,
42 video_id)
43 entries = []
44 for season in seasons:
45 for episode in season.get('episodes', []):
46 episode_id = episode.get('id')
47 if not episode_id:
48 continue
49 entries.append(self.url_result(
50 'https://www.contv.com/details-movie/' + episode_id,
51 CONtvIE.ie_key(), episode_id))
52 return self.playlist_result(entries, video_id, details.get('title'))
54 m_details = details['details']
55 title = details['title']
57 formats = []
59 media_hls_url = m_details.get('media_hls_url')
60 if media_hls_url:
61 formats.extend(self._extract_m3u8_formats(
62 media_hls_url, video_id, 'mp4',
63 m3u8_id='hls', fatal=False))
65 media_mp4_url = m_details.get('media_mp4_url')
66 if media_mp4_url:
67 formats.append({
68 'format_id': 'http',
69 'url': media_mp4_url,
72 subtitles = {}
73 captions = m_details.get('captions') or {}
74 for caption_url in captions.values():
75 subtitles.setdefault('en', []).append({
76 'url': caption_url,
79 thumbnails = []
80 for image in m_details.get('images', []):
81 image_url = image.get('url')
82 if not image_url:
83 continue
84 thumbnails.append({
85 'url': image_url,
86 'width': int_or_none(image.get('width')),
87 'height': int_or_none(image.get('height')),
90 description = None
91 for p in ('large_', 'medium_', 'small_', ''):
92 d = m_details.get(p + 'description')
93 if d:
94 description = d
95 break
97 return {
98 'id': video_id,
99 'title': title,
100 'formats': formats,
101 'thumbnails': thumbnails,
102 'description': description,
103 'timestamp': float_or_none(details.get('metax_added_on'), 1000),
104 'subtitles': subtitles,
105 'duration': float_or_none(m_details.get('duration'), 1000),
106 'view_count': int_or_none(details.get('num_watched')),
107 'like_count': int_or_none(details.get('num_fav')),
108 'categories': details.get('category'),
109 'tags': details.get('tags'),
110 'season_number': int_or_none(details.get('season')),
111 'episode_number': int_or_none(details.get('episode')),
112 'release_year': int_or_none(details.get('pub_year')),