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.

113 lines
3.9 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 (
  7. extract_attributes,
  8. remove_end,
  9. )
  10. class AsianCrushIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?asiancrush\.com/video/(?:[^/]+/)?0+(?P<id>\d+)v\b'
  12. _TESTS = [{
  13. 'url': 'https://www.asiancrush.com/video/012869v/women-who-flirt/',
  14. 'md5': 'c3b740e48d0ba002a42c0b72857beae6',
  15. 'info_dict': {
  16. 'id': '1_y4tmjm5r',
  17. 'ext': 'mp4',
  18. 'title': 'Women Who Flirt',
  19. 'description': 'md5:3db14e9186197857e7063522cb89a805',
  20. 'timestamp': 1496936429,
  21. 'upload_date': '20170608',
  22. 'uploader_id': 'craig@crifkin.com',
  23. },
  24. }, {
  25. 'url': 'https://www.asiancrush.com/video/she-was-pretty/011886v-pretty-episode-3/',
  26. 'only_matching': True,
  27. }]
  28. def _real_extract(self, url):
  29. video_id = self._match_id(url)
  30. webpage = self._download_webpage(url, video_id)
  31. entry_id, partner_id, title = [None] * 3
  32. vars = self._parse_json(
  33. self._search_regex(
  34. r'iEmbedVars\s*=\s*({.+?})', webpage, 'embed vars',
  35. default='{}'), video_id, fatal=False)
  36. if vars:
  37. entry_id = vars.get('entry_id')
  38. partner_id = vars.get('partner_id')
  39. title = vars.get('vid_label')
  40. if not entry_id:
  41. entry_id = self._search_regex(
  42. r'\bentry_id["\']\s*:\s*["\'](\d+)', webpage, 'entry id')
  43. player = self._download_webpage(
  44. 'https://api.asiancrush.com/embeddedVideoPlayer', video_id,
  45. query={'id': entry_id})
  46. kaltura_id = self._search_regex(
  47. r'entry_id["\']\s*:\s*(["\'])(?P<id>(?:(?!\1).)+)\1', player,
  48. 'kaltura id', group='id')
  49. if not partner_id:
  50. partner_id = self._search_regex(
  51. r'/p(?:artner_id)?/(\d+)', player, 'partner id',
  52. default='513551')
  53. return self.url_result(
  54. 'kaltura:%s:%s' % (partner_id, kaltura_id),
  55. ie=KalturaIE.ie_key(), video_id=kaltura_id,
  56. video_title=title)
  57. class AsianCrushPlaylistIE(InfoExtractor):
  58. _VALID_URL = r'https?://(?:www\.)?asiancrush\.com/series/0+(?P<id>\d+)s\b'
  59. _TEST = {
  60. 'url': 'https://www.asiancrush.com/series/012481s/scholar-walks-night/',
  61. 'info_dict': {
  62. 'id': '12481',
  63. 'title': 'Scholar Who Walks the Night',
  64. 'description': 'md5:7addd7c5132a09fd4741152d96cce886',
  65. },
  66. 'playlist_count': 20,
  67. }
  68. def _real_extract(self, url):
  69. playlist_id = self._match_id(url)
  70. webpage = self._download_webpage(url, playlist_id)
  71. entries = []
  72. for mobj in re.finditer(
  73. r'<a[^>]+href=(["\'])(?P<url>%s.*?)\1[^>]*>' % AsianCrushIE._VALID_URL,
  74. webpage):
  75. attrs = extract_attributes(mobj.group(0))
  76. if attrs.get('class') == 'clearfix':
  77. entries.append(self.url_result(
  78. mobj.group('url'), ie=AsianCrushIE.ie_key()))
  79. title = remove_end(
  80. self._html_search_regex(
  81. r'(?s)<h1\b[^>]\bid=["\']movieTitle[^>]+>(.+?)</h1>', webpage,
  82. 'title', default=None) or self._og_search_title(
  83. webpage, default=None) or self._html_search_meta(
  84. 'twitter:title', webpage, 'title',
  85. default=None) or self._search_regex(
  86. r'<title>([^<]+)</title>', webpage, 'title', fatal=False),
  87. ' | AsianCrush')
  88. description = self._og_search_description(
  89. webpage, default=None) or self._html_search_meta(
  90. 'twitter:description', webpage, 'description', fatal=False)
  91. return self.playlist_result(entries, playlist_id, title, description)