puhutv.py 8.2 KB

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