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.

145 lines
5.2 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from .kaltura import KalturaIE
  6. from ..utils import extract_attributes
  7. class AsianCrushIE(InfoExtractor):
  8. _VALID_URL_BASE = r'https?://(?:www\.)?(?P<host>(?:(?:asiancrush|yuyutv|midnightpulp)\.com|cocoro\.tv))'
  9. _VALID_URL = r'%s/video/(?:[^/]+/)?0+(?P<id>\d+)v\b' % _VALID_URL_BASE
  10. _TESTS = [{
  11. 'url': 'https://www.asiancrush.com/video/012869v/women-who-flirt/',
  12. 'md5': 'c3b740e48d0ba002a42c0b72857beae6',
  13. 'info_dict': {
  14. 'id': '1_y4tmjm5r',
  15. 'ext': 'mp4',
  16. 'title': 'Women Who Flirt',
  17. 'description': 'md5:7e986615808bcfb11756eb503a751487',
  18. 'timestamp': 1496936429,
  19. 'upload_date': '20170608',
  20. 'uploader_id': 'craig@crifkin.com',
  21. },
  22. }, {
  23. 'url': 'https://www.asiancrush.com/video/she-was-pretty/011886v-pretty-episode-3/',
  24. 'only_matching': True,
  25. }, {
  26. 'url': 'https://www.yuyutv.com/video/013886v/the-act-of-killing/',
  27. 'only_matching': True,
  28. }, {
  29. 'url': 'https://www.yuyutv.com/video/peep-show/013922v-warring-factions/',
  30. 'only_matching': True,
  31. }, {
  32. 'url': 'https://www.midnightpulp.com/video/010400v/drifters/',
  33. 'only_matching': True,
  34. }, {
  35. 'url': 'https://www.midnightpulp.com/video/mononoke/016378v-zashikiwarashi-part-1/',
  36. 'only_matching': True,
  37. }, {
  38. 'url': 'https://www.cocoro.tv/video/the-wonderful-wizard-of-oz/008878v-the-wonderful-wizard-of-oz-ep01/',
  39. 'only_matching': True,
  40. }]
  41. def _real_extract(self, url):
  42. mobj = re.match(self._VALID_URL, url)
  43. host = mobj.group('host')
  44. video_id = mobj.group('id')
  45. webpage = self._download_webpage(url, video_id)
  46. entry_id, partner_id, title = [None] * 3
  47. vars = self._parse_json(
  48. self._search_regex(
  49. r'iEmbedVars\s*=\s*({.+?})', webpage, 'embed vars',
  50. default='{}'), video_id, fatal=False)
  51. if vars:
  52. entry_id = vars.get('entry_id')
  53. partner_id = vars.get('partner_id')
  54. title = vars.get('vid_label')
  55. if not entry_id:
  56. entry_id = self._search_regex(
  57. r'\bentry_id["\']\s*:\s*["\'](\d+)', webpage, 'entry id')
  58. player = self._download_webpage(
  59. 'https://api.%s/embeddedVideoPlayer' % host, video_id,
  60. query={'id': entry_id})
  61. kaltura_id = self._search_regex(
  62. r'entry_id["\']\s*:\s*(["\'])(?P<id>(?:(?!\1).)+)\1', player,
  63. 'kaltura id', group='id')
  64. if not partner_id:
  65. partner_id = self._search_regex(
  66. r'/p(?:artner_id)?/(\d+)', player, 'partner id',
  67. default='513551')
  68. description = self._html_search_regex(
  69. r'(?s)<div[^>]+\bclass=["\']description["\'][^>]*>(.+?)</div>',
  70. webpage, 'description', fatal=False)
  71. return {
  72. '_type': 'url_transparent',
  73. 'url': 'kaltura:%s:%s' % (partner_id, kaltura_id),
  74. 'ie_key': KalturaIE.ie_key(),
  75. 'id': video_id,
  76. 'title': title,
  77. 'description': description,
  78. }
  79. class AsianCrushPlaylistIE(InfoExtractor):
  80. _VALID_URL = r'%s/series/0+(?P<id>\d+)s\b' % AsianCrushIE._VALID_URL_BASE
  81. _TESTS = [{
  82. 'url': 'https://www.asiancrush.com/series/012481s/scholar-walks-night/',
  83. 'info_dict': {
  84. 'id': '12481',
  85. 'title': 'Scholar Who Walks the Night',
  86. 'description': 'md5:7addd7c5132a09fd4741152d96cce886',
  87. },
  88. 'playlist_count': 20,
  89. }, {
  90. 'url': 'https://www.yuyutv.com/series/013920s/peep-show/',
  91. 'only_matching': True,
  92. }, {
  93. 'url': 'https://www.midnightpulp.com/series/016375s/mononoke/',
  94. 'only_matching': True,
  95. }, {
  96. 'url': 'https://www.cocoro.tv/series/008549s/the-wonderful-wizard-of-oz/',
  97. 'only_matching': True,
  98. }]
  99. def _real_extract(self, url):
  100. playlist_id = self._match_id(url)
  101. webpage = self._download_webpage(url, playlist_id)
  102. entries = []
  103. for mobj in re.finditer(
  104. r'<a[^>]+href=(["\'])(?P<url>%s.*?)\1[^>]*>' % AsianCrushIE._VALID_URL,
  105. webpage):
  106. attrs = extract_attributes(mobj.group(0))
  107. if attrs.get('class') == 'clearfix':
  108. entries.append(self.url_result(
  109. mobj.group('url'), ie=AsianCrushIE.ie_key()))
  110. title = self._html_search_regex(
  111. r'(?s)<h1\b[^>]\bid=["\']movieTitle[^>]+>(.+?)</h1>', webpage,
  112. 'title', default=None) or self._og_search_title(
  113. webpage, default=None) or self._html_search_meta(
  114. 'twitter:title', webpage, 'title',
  115. default=None) or self._search_regex(
  116. r'<title>([^<]+)</title>', webpage, 'title', fatal=False)
  117. if title:
  118. title = re.sub(r'\s*\|\s*.+?$', '', title)
  119. description = self._og_search_description(
  120. webpage, default=None) or self._html_search_meta(
  121. 'twitter:description', webpage, 'description', fatal=False)
  122. return self.playlist_result(entries, playlist_id, title, description)