2 from __future__ import unicode_literals
4 from .common import InfoExtractor
22 class PuhuTVIE(InfoExtractor):
23 _VALID_URL = r'https?://(?:www\.)?puhutv\.com/(?P<id>[^/?#&]+)-izle'
27 'url': 'https://puhutv.com/sut-kardesler-izle',
28 'md5': 'fbd8f2d8e7681f8bcd51b592475a6ae7',
31 'display_id': 'sut-kardesler',
33 'title': 'Süt Kardeşler',
34 'description': 'md5:405fd024df916ca16731114eb18e511a',
35 'thumbnail': r're:^https?://.*\.jpg$',
37 'creator': 'Arzu Film',
38 'timestamp': 1469778212,
39 'upload_date': '20160729',
42 'tags': ['Aile', 'Komedi', 'Klasikler'],
45 # episode, geo restricted, bypassable with --geo-verification-proxy
46 'url': 'https://puhutv.com/jet-sosyete-1-bolum-izle',
47 'only_matching': True,
50 'url': 'https://puhutv.com/dip-1-bolum-izle',
51 'only_matching': True,
59 def _real_extract(self, url):
60 display_id = self._match_id(url)
62 info = self._download_json(
63 urljoin(url, '/api/slug/%s-izle' % display_id),
66 video_id = compat_str(info['id'])
67 title = info.get('name') or info['title']['name']
68 if info.get('display_name'):
69 title = '%s %s' % (title, info.get('display_name'))
72 videos = self._download_json(
73 'https://puhutv.com/api/assets/%s/videos' % video_id,
74 display_id, 'Downloading video JSON',
75 headers=self.geo_verification_headers())
76 except ExtractorError as e:
77 if isinstance(e.cause, compat_HTTPError) and e.cause.code == 403:
78 self.raise_geo_restricted()
82 for video in videos['data']['videos']:
83 media_url = url_or_none(video.get('url'))
86 playlist = video.get('is_playlist')
87 if video.get('stream_type') == 'hls' and playlist is True:
88 formats.extend(self._extract_m3u8_formats(
89 media_url, video_id, 'mp4', entry_protocol='m3u8_native',
90 m3u8_id='hls', fatal=False))
92 quality = int_or_none(video.get('quality'))
98 video_format = video.get('video_format')
99 if video_format == 'hls' and playlist is False:
101 f['protocol'] = 'm3u8_native'
102 elif video_format == 'mp4':
108 format_id += '-%sp' % quality
109 f['format_id'] = format_id
111 self._sort_formats(formats)
113 description = try_get(
114 info, lambda x: x['title']['description'],
115 compat_str) or info.get('description')
116 timestamp = unified_timestamp(info.get('created_at'))
118 info, lambda x: x['title']['producer']['name'], compat_str)
120 duration = float_or_none(
121 try_get(info, lambda x: x['content']['duration_in_ms'], int),
123 view_count = try_get(info, lambda x: x['content']['watch_count'], int)
126 info, lambda x: x['content']['images']['wide'], dict) or {}
128 for image_id, image_url in images.items():
129 if not isinstance(image_url, compat_str):
131 if not image_url.startswith(('http', '//')):
132 image_url = 'https://%s' % image_url
133 t = parse_resolution(image_id)
140 release_year = try_get(info, lambda x: x['title']['released_at'], int)
142 season_number = int_or_none(info.get('season_number'))
143 season_id = str_or_none(info.get('season_id'))
144 episode_number = int_or_none(info.get('episode_number'))
147 for genre in try_get(info, lambda x: x['title']['genres'], list) or []:
148 if not isinstance(genre, dict):
150 genre_name = genre.get('name')
151 if genre_name and isinstance(genre_name, compat_str):
152 tags.append(genre_name)
155 for subtitle in try_get(
156 info, lambda x: x['content']['subtitles'], list) or []:
157 if not isinstance(subtitle, dict):
159 lang = subtitle.get('language')
160 sub_url = url_or_none(subtitle.get('url'))
161 if not lang or not isinstance(lang, compat_str) or not sub_url:
163 subtitles[self._SUBTITLE_LANGS.get(lang, lang)] = [{
169 'display_id': display_id,
171 'description': description,
172 'season_id': season_id,
173 'season_number': season_number,
174 'episode_number': episode_number,
175 'release_year': release_year,
176 'timestamp': timestamp,
178 'view_count': view_count,
179 'duration': duration,
181 'subtitles': subtitles,
182 'thumbnails': thumbnails,
187 class PuhuTVSerieIE(InfoExtractor):
188 _VALID_URL = r'https?://(?:www\.)?puhutv\.com/(?P<id>[^/?#&]+)-detay'
189 IE_NAME = 'puhutv:serie'
191 'url': 'https://puhutv.com/deniz-yildizi-detay',
193 'title': 'Deniz Yıldızı',
194 'id': 'deniz-yildizi',
196 'playlist_mincount': 205,
198 # a film detail page which is using same url with serie page
199 'url': 'https://puhutv.com/kaybedenler-kulubu-detay',
200 'only_matching': True,
203 def _extract_entries(self, seasons):
204 for season in seasons:
205 season_id = season.get('id')
210 while has_more is True:
211 season = self._download_json(
212 'https://galadriel.puhutv.com/seasons/%s' % season_id,
213 season_id, 'Downloading page %s' % page, query={
217 episodes = season.get('episodes')
218 if isinstance(episodes, list):
220 slug_path = str_or_none(ep.get('slugPath'))
223 video_id = str_or_none(int_or_none(ep.get('id')))
224 yield self.url_result(
225 'https://puhutv.com/%s' % slug_path,
226 ie=PuhuTVIE.ie_key(), video_id=video_id,
227 video_title=ep.get('name') or ep.get('eventLabel'))
229 has_more = season.get('hasMore')
231 def _real_extract(self, url):
232 playlist_id = self._match_id(url)
234 info = self._download_json(
235 urljoin(url, '/api/slug/%s-detay' % playlist_id),
238 seasons = info.get('seasons')
240 return self.playlist_result(
241 self._extract_entries(seasons), playlist_id, info.get('name'))
243 # For films, these are using same url with series
244 video_id = info.get('slug') or info['assets'][0]['slug']
245 return self.url_result(
246 'https://puhutv.com/%s-izle' % video_id,
247 PuhuTVIE.ie_key(), video_id)