You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

247 lines
8.5 KiB

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