]>
Commit | Line | Data |
---|---|---|
6de82b44 | 1 | from .common import InfoExtractor |
8fd2a7be S |
2 | from ..compat import ( |
3 | compat_HTTPError, | |
4 | compat_str, | |
5 | ) | |
6de82b44 | 6 | from ..utils import ( |
8fd2a7be | 7 | ExtractorError, |
6de82b44 E |
8 | int_or_none, |
9 | float_or_none, | |
8fd2a7be | 10 | parse_resolution, |
6de82b44 | 11 | str_or_none, |
6de82b44 | 12 | try_get, |
8fd2a7be S |
13 | unified_timestamp, |
14 | url_or_none, | |
15 | urljoin, | |
6de82b44 E |
16 | ) |
17 | ||
18 | ||
19 | class PuhuTVIE(InfoExtractor): | |
8fd2a7be | 20 | _VALID_URL = r'https?://(?:www\.)?puhutv\.com/(?P<id>[^/?#&]+)-izle' |
6de82b44 | 21 | IE_NAME = 'puhutv' |
8fd2a7be S |
22 | _TESTS = [{ |
23 | # film | |
24 | 'url': 'https://puhutv.com/sut-kardesler-izle', | |
162bcc68 | 25 | 'md5': 'a347470371d56e1585d1b2c8dab01c96', |
8fd2a7be S |
26 | 'info_dict': { |
27 | 'id': '5085', | |
28 | 'display_id': 'sut-kardesler', | |
29 | 'ext': 'mp4', | |
30 | 'title': 'Süt Kardeşler', | |
162bcc68 | 31 | 'description': 'md5:ca09da25b7e57cbb5a9280d6e48d17aa', |
8fd2a7be S |
32 | 'thumbnail': r're:^https?://.*\.jpg$', |
33 | 'duration': 4832.44, | |
34 | 'creator': 'Arzu Film', | |
162bcc68 RA |
35 | 'timestamp': 1561062602, |
36 | 'upload_date': '20190620', | |
8fd2a7be S |
37 | 'release_year': 1976, |
38 | 'view_count': int, | |
162bcc68 | 39 | 'tags': list, |
6de82b44 | 40 | }, |
8fd2a7be S |
41 | }, { |
42 | # episode, geo restricted, bypassable with --geo-verification-proxy | |
43 | 'url': 'https://puhutv.com/jet-sosyete-1-bolum-izle', | |
44 | 'only_matching': True, | |
45 | }, { | |
46 | # 4k, with subtitles | |
47 | 'url': 'https://puhutv.com/dip-1-bolum-izle', | |
48 | 'only_matching': True, | |
49 | }] | |
6de82b44 E |
50 | _SUBTITLE_LANGS = { |
51 | 'English': 'en', | |
52 | 'Deutsch': 'de', | |
53 | 'عربى': 'ar' | |
54 | } | |
55 | ||
56 | def _real_extract(self, url): | |
8fd2a7be S |
57 | display_id = self._match_id(url) |
58 | ||
6de82b44 | 59 | info = self._download_json( |
8fd2a7be S |
60 | urljoin(url, '/api/slug/%s-izle' % display_id), |
61 | display_id)['data'] | |
6de82b44 | 62 | |
8fd2a7be | 63 | video_id = compat_str(info['id']) |
162bcc68 RA |
64 | show = info.get('title') or {} |
65 | title = info.get('name') or show['name'] | |
6de82b44 | 66 | if info.get('display_name'): |
162bcc68 | 67 | title = '%s %s' % (title, info['display_name']) |
6de82b44 | 68 | |
8fd2a7be S |
69 | try: |
70 | videos = self._download_json( | |
71 | 'https://puhutv.com/api/assets/%s/videos' % video_id, | |
72 | display_id, 'Downloading video JSON', | |
73 | headers=self.geo_verification_headers()) | |
74 | except ExtractorError as e: | |
75 | if isinstance(e.cause, compat_HTTPError) and e.cause.code == 403: | |
76 | self.raise_geo_restricted() | |
77 | raise | |
78 | ||
162bcc68 | 79 | urls = [] |
8fd2a7be | 80 | formats = [] |
162bcc68 | 81 | |
8fd2a7be S |
82 | for video in videos['data']['videos']: |
83 | media_url = url_or_none(video.get('url')) | |
162bcc68 | 84 | if not media_url or media_url in urls: |
8fd2a7be | 85 | continue |
162bcc68 RA |
86 | urls.append(media_url) |
87 | ||
8fd2a7be | 88 | playlist = video.get('is_playlist') |
162bcc68 | 89 | if (video.get('stream_type') == 'hls' and playlist is True) or 'playlist.m3u8' in media_url: |
f7f30491 | 90 | formats.extend(self._extract_m3u8_formats( |
8fd2a7be | 91 | media_url, video_id, 'mp4', entry_protocol='m3u8_native', |
f7f30491 | 92 | m3u8_id='hls', fatal=False)) |
8fd2a7be | 93 | continue |
162bcc68 | 94 | |
8fd2a7be S |
95 | quality = int_or_none(video.get('quality')) |
96 | f = { | |
97 | 'url': media_url, | |
98 | 'ext': 'mp4', | |
99 | 'height': quality | |
100 | } | |
101 | video_format = video.get('video_format') | |
162bcc68 RA |
102 | is_hls = (video_format == 'hls' or '/hls/' in media_url or '/chunklist.m3u8' in media_url) and playlist is False |
103 | if is_hls: | |
8fd2a7be S |
104 | format_id = 'hls' |
105 | f['protocol'] = 'm3u8_native' | |
106 | elif video_format == 'mp4': | |
107 | format_id = 'http' | |
8fd2a7be S |
108 | else: |
109 | continue | |
110 | if quality: | |
111 | format_id += '-%sp' % quality | |
112 | f['format_id'] = format_id | |
113 | formats.append(f) | |
114 | self._sort_formats(formats) | |
115 | ||
8fd2a7be | 116 | creator = try_get( |
162bcc68 | 117 | show, lambda x: x['producer']['name'], compat_str) |
8fd2a7be | 118 | |
162bcc68 | 119 | content = info.get('content') or {} |
8fd2a7be S |
120 | |
121 | images = try_get( | |
162bcc68 | 122 | content, lambda x: x['images']['wide'], dict) or {} |
8fd2a7be S |
123 | thumbnails = [] |
124 | for image_id, image_url in images.items(): | |
125 | if not isinstance(image_url, compat_str): | |
126 | continue | |
127 | if not image_url.startswith(('http', '//')): | |
128 | image_url = 'https://%s' % image_url | |
129 | t = parse_resolution(image_id) | |
130 | t.update({ | |
131 | 'id': image_id, | |
132 | 'url': image_url | |
133 | }) | |
134 | thumbnails.append(t) | |
135 | ||
6de82b44 | 136 | tags = [] |
162bcc68 | 137 | for genre in show.get('genres') or []: |
8fd2a7be | 138 | if not isinstance(genre, dict): |
6de82b44 | 139 | continue |
8fd2a7be S |
140 | genre_name = genre.get('name') |
141 | if genre_name and isinstance(genre_name, compat_str): | |
142 | tags.append(genre_name) | |
6de82b44 E |
143 | |
144 | subtitles = {} | |
162bcc68 | 145 | for subtitle in content.get('subtitles') or []: |
6de82b44 E |
146 | if not isinstance(subtitle, dict): |
147 | continue | |
148 | lang = subtitle.get('language') | |
162bcc68 | 149 | sub_url = url_or_none(subtitle.get('url') or subtitle.get('file')) |
6de82b44 E |
150 | if not lang or not isinstance(lang, compat_str) or not sub_url: |
151 | continue | |
152 | subtitles[self._SUBTITLE_LANGS.get(lang, lang)] = [{ | |
153 | 'url': sub_url | |
154 | }] | |
155 | ||
6de82b44 E |
156 | return { |
157 | 'id': video_id, | |
158 | 'display_id': display_id, | |
159 | 'title': title, | |
162bcc68 RA |
160 | 'description': info.get('description') or show.get('description'), |
161 | 'season_id': str_or_none(info.get('season_id')), | |
162 | 'season_number': int_or_none(info.get('season_number')), | |
163 | 'episode_number': int_or_none(info.get('episode_number')), | |
164 | 'release_year': int_or_none(show.get('released_at')), | |
165 | 'timestamp': unified_timestamp(info.get('created_at')), | |
8fd2a7be | 166 | 'creator': creator, |
162bcc68 RA |
167 | 'view_count': int_or_none(content.get('watch_count')), |
168 | 'duration': float_or_none(content.get('duration_in_ms'), 1000), | |
6de82b44 E |
169 | 'tags': tags, |
170 | 'subtitles': subtitles, | |
6de82b44 E |
171 | 'thumbnails': thumbnails, |
172 | 'formats': formats | |
173 | } | |
174 | ||
175 | ||
176 | class PuhuTVSerieIE(InfoExtractor): | |
8fd2a7be | 177 | _VALID_URL = r'https?://(?:www\.)?puhutv\.com/(?P<id>[^/?#&]+)-detay' |
6de82b44 | 178 | IE_NAME = 'puhutv:serie' |
8fd2a7be S |
179 | _TESTS = [{ |
180 | 'url': 'https://puhutv.com/deniz-yildizi-detay', | |
181 | 'info_dict': { | |
182 | 'title': 'Deniz Yıldızı', | |
183 | 'id': 'deniz-yildizi', | |
6de82b44 | 184 | }, |
8fd2a7be S |
185 | 'playlist_mincount': 205, |
186 | }, { | |
187 | # a film detail page which is using same url with serie page | |
188 | 'url': 'https://puhutv.com/kaybedenler-kulubu-detay', | |
189 | 'only_matching': True, | |
190 | }] | |
191 | ||
192 | def _extract_entries(self, seasons): | |
6de82b44 | 193 | for season in seasons: |
8fd2a7be S |
194 | season_id = season.get('id') |
195 | if not season_id: | |
196 | continue | |
197 | page = 1 | |
6de82b44 E |
198 | has_more = True |
199 | while has_more is True: | |
8fd2a7be | 200 | season = self._download_json( |
6de82b44 | 201 | 'https://galadriel.puhutv.com/seasons/%s' % season_id, |
8fd2a7be S |
202 | season_id, 'Downloading page %s' % page, query={ |
203 | 'page': page, | |
6de82b44 E |
204 | 'per': 40, |
205 | }) | |
8fd2a7be S |
206 | episodes = season.get('episodes') |
207 | if isinstance(episodes, list): | |
208 | for ep in episodes: | |
209 | slug_path = str_or_none(ep.get('slugPath')) | |
210 | if not slug_path: | |
211 | continue | |
212 | video_id = str_or_none(int_or_none(ep.get('id'))) | |
213 | yield self.url_result( | |
214 | 'https://puhutv.com/%s' % slug_path, | |
215 | ie=PuhuTVIE.ie_key(), video_id=video_id, | |
216 | video_title=ep.get('name') or ep.get('eventLabel')) | |
217 | page += 1 | |
218 | has_more = season.get('hasMore') | |
6de82b44 E |
219 | |
220 | def _real_extract(self, url): | |
221 | playlist_id = self._match_id(url) | |
222 | ||
223 | info = self._download_json( | |
8fd2a7be S |
224 | urljoin(url, '/api/slug/%s-detay' % playlist_id), |
225 | playlist_id)['data'] | |
6de82b44 | 226 | |
6de82b44 E |
227 | seasons = info.get('seasons') |
228 | if seasons: | |
8fd2a7be S |
229 | return self.playlist_result( |
230 | self._extract_entries(seasons), playlist_id, info.get('name')) | |
231 | ||
232 | # For films, these are using same url with series | |
233 | video_id = info.get('slug') or info['assets'][0]['slug'] | |
234 | return self.url_result( | |
235 | 'https://puhutv.com/%s-izle' % video_id, | |
236 | PuhuTVIE.ie_key(), video_id) |