logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

asiancrush.py (7807B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import functools
  4. import re
  5. from .common import InfoExtractor
  6. from .kaltura import KalturaIE
  7. from ..utils import (
  8. extract_attributes,
  9. int_or_none,
  10. OnDemandPagedList,
  11. parse_age_limit,
  12. strip_or_none,
  13. try_get,
  14. )
  15. class AsianCrushBaseIE(InfoExtractor):
  16. _VALID_URL_BASE = r'https?://(?:www\.)?(?P<host>(?:(?:asiancrush|yuyutv|midnightpulp)\.com|(?:cocoro|retrocrush)\.tv))'
  17. _KALTURA_KEYS = [
  18. 'video_url', 'progressive_url', 'download_url', 'thumbnail_url',
  19. 'widescreen_thumbnail_url', 'screencap_widescreen',
  20. ]
  21. _API_SUFFIX = {'retrocrush.tv': '-ott'}
  22. def _call_api(self, host, endpoint, video_id, query, resource):
  23. return self._download_json(
  24. 'https://api%s.%s/%s' % (self._API_SUFFIX.get(host, ''), host, endpoint), video_id,
  25. 'Downloading %s JSON metadata' % resource, query=query,
  26. headers=self.geo_verification_headers())['objects']
  27. def _download_object_data(self, host, object_id, resource):
  28. return self._call_api(
  29. host, 'search', object_id, {'id': object_id}, resource)[0]
  30. def _get_object_description(self, obj):
  31. return strip_or_none(obj.get('long_description') or obj.get('short_description'))
  32. def _parse_video_data(self, video):
  33. title = video['name']
  34. entry_id, partner_id = [None] * 2
  35. for k in self._KALTURA_KEYS:
  36. k_url = video.get(k)
  37. if k_url:
  38. mobj = re.search(r'/p/(\d+)/.+?/entryId/([^/]+)/', k_url)
  39. if mobj:
  40. partner_id, entry_id = mobj.groups()
  41. break
  42. meta_categories = try_get(video, lambda x: x['meta']['categories'], list) or []
  43. categories = list(filter(None, [c.get('name') for c in meta_categories]))
  44. show_info = video.get('show_info') or {}
  45. return {
  46. '_type': 'url_transparent',
  47. 'url': 'kaltura:%s:%s' % (partner_id, entry_id),
  48. 'ie_key': KalturaIE.ie_key(),
  49. 'id': entry_id,
  50. 'title': title,
  51. 'description': self._get_object_description(video),
  52. 'age_limit': parse_age_limit(video.get('mpaa_rating') or video.get('tv_rating')),
  53. 'categories': categories,
  54. 'series': show_info.get('show_name'),
  55. 'season_number': int_or_none(show_info.get('season_num')),
  56. 'season_id': show_info.get('season_id'),
  57. 'episode_number': int_or_none(show_info.get('episode_num')),
  58. }
  59. class AsianCrushIE(AsianCrushBaseIE):
  60. _VALID_URL = r'%s/video/(?:[^/]+/)?0+(?P<id>\d+)v\b' % AsianCrushBaseIE._VALID_URL_BASE
  61. _TESTS = [{
  62. 'url': 'https://www.asiancrush.com/video/004289v/women-who-flirt',
  63. 'md5': 'c3b740e48d0ba002a42c0b72857beae6',
  64. 'info_dict': {
  65. 'id': '1_y4tmjm5r',
  66. 'ext': 'mp4',
  67. 'title': 'Women Who Flirt',
  68. 'description': 'md5:b65c7e0ae03a85585476a62a186f924c',
  69. 'timestamp': 1496936429,
  70. 'upload_date': '20170608',
  71. 'uploader_id': 'craig@crifkin.com',
  72. 'age_limit': 13,
  73. 'categories': 'count:5',
  74. 'duration': 5812,
  75. },
  76. }, {
  77. 'url': 'https://www.asiancrush.com/video/she-was-pretty/011886v-pretty-episode-3/',
  78. 'only_matching': True,
  79. }, {
  80. 'url': 'https://www.yuyutv.com/video/013886v/the-act-of-killing/',
  81. 'only_matching': True,
  82. }, {
  83. 'url': 'https://www.yuyutv.com/video/peep-show/013922v-warring-factions/',
  84. 'only_matching': True,
  85. }, {
  86. 'url': 'https://www.midnightpulp.com/video/010400v/drifters/',
  87. 'only_matching': True,
  88. }, {
  89. 'url': 'https://www.midnightpulp.com/video/mononoke/016378v-zashikiwarashi-part-1/',
  90. 'only_matching': True,
  91. }, {
  92. 'url': 'https://www.cocoro.tv/video/the-wonderful-wizard-of-oz/008878v-the-wonderful-wizard-of-oz-ep01/',
  93. 'only_matching': True,
  94. }, {
  95. 'url': 'https://www.retrocrush.tv/video/true-tears/012328v-i...gave-away-my-tears',
  96. 'only_matching': True,
  97. }]
  98. def _real_extract(self, url):
  99. host, video_id = re.match(self._VALID_URL, url).groups()
  100. if host == 'cocoro.tv':
  101. webpage = self._download_webpage(url, video_id)
  102. embed_vars = self._parse_json(self._search_regex(
  103. r'iEmbedVars\s*=\s*({.+?})', webpage, 'embed vars',
  104. default='{}'), video_id, fatal=False) or {}
  105. video_id = embed_vars.get('entry_id') or video_id
  106. video = self._download_object_data(host, video_id, 'video')
  107. return self._parse_video_data(video)
  108. class AsianCrushPlaylistIE(AsianCrushBaseIE):
  109. _VALID_URL = r'%s/series/0+(?P<id>\d+)s\b' % AsianCrushBaseIE._VALID_URL_BASE
  110. _TESTS = [{
  111. 'url': 'https://www.asiancrush.com/series/006447s/fruity-samurai',
  112. 'info_dict': {
  113. 'id': '6447',
  114. 'title': 'Fruity Samurai',
  115. 'description': 'md5:7535174487e4a202d3872a7fc8f2f154',
  116. },
  117. 'playlist_count': 13,
  118. }, {
  119. 'url': 'https://www.yuyutv.com/series/013920s/peep-show/',
  120. 'only_matching': True,
  121. }, {
  122. 'url': 'https://www.midnightpulp.com/series/016375s/mononoke/',
  123. 'only_matching': True,
  124. }, {
  125. 'url': 'https://www.cocoro.tv/series/008549s/the-wonderful-wizard-of-oz/',
  126. 'only_matching': True,
  127. }, {
  128. 'url': 'https://www.retrocrush.tv/series/012355s/true-tears',
  129. 'only_matching': True,
  130. }]
  131. _PAGE_SIZE = 1000000000
  132. def _fetch_page(self, domain, parent_id, page):
  133. videos = self._call_api(
  134. domain, 'getreferencedobjects', parent_id, {
  135. 'max': self._PAGE_SIZE,
  136. 'object_type': 'video',
  137. 'parent_id': parent_id,
  138. 'start': page * self._PAGE_SIZE,
  139. }, 'page %d' % (page + 1))
  140. for video in videos:
  141. yield self._parse_video_data(video)
  142. def _real_extract(self, url):
  143. host, playlist_id = re.match(self._VALID_URL, url).groups()
  144. if host == 'cocoro.tv':
  145. webpage = self._download_webpage(url, playlist_id)
  146. entries = []
  147. for mobj in re.finditer(
  148. r'<a[^>]+href=(["\'])(?P<url>%s.*?)\1[^>]*>' % AsianCrushIE._VALID_URL,
  149. webpage):
  150. attrs = extract_attributes(mobj.group(0))
  151. if attrs.get('class') == 'clearfix':
  152. entries.append(self.url_result(
  153. mobj.group('url'), ie=AsianCrushIE.ie_key()))
  154. title = self._html_search_regex(
  155. r'(?s)<h1\b[^>]\bid=["\']movieTitle[^>]+>(.+?)</h1>', webpage,
  156. 'title', default=None) or self._og_search_title(
  157. webpage, default=None) or self._html_search_meta(
  158. 'twitter:title', webpage, 'title',
  159. default=None) or self._search_regex(
  160. r'<title>([^<]+)</title>', webpage, 'title', fatal=False)
  161. if title:
  162. title = re.sub(r'\s*\|\s*.+?$', '', title)
  163. description = self._og_search_description(
  164. webpage, default=None) or self._html_search_meta(
  165. 'twitter:description', webpage, 'description', fatal=False)
  166. else:
  167. show = self._download_object_data(host, playlist_id, 'show')
  168. title = show.get('name')
  169. description = self._get_object_description(show)
  170. entries = OnDemandPagedList(
  171. functools.partial(self._fetch_page, host, playlist_id),
  172. self._PAGE_SIZE)
  173. return self.playlist_result(entries, playlist_id, title, description)