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
4.1 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_urllib_parse,
  6. compat_urllib_parse_urlparse,
  7. compat_urllib_request,
  8. )
  9. from ..utils import (
  10. str_to_int,
  11. unified_strdate,
  12. )
  13. from ..aes import aes_decrypt_text
  14. class SpankwireIE(InfoExtractor):
  15. _VALID_URL = r'https?://(?:www\.)?(?P<url>spankwire\.com/[^/]*/video(?P<videoid>[0-9]+)/?)'
  16. _TEST = {
  17. 'url': 'http://www.spankwire.com/Buckcherry-s-X-Rated-Music-Video-Crazy-Bitch/video103545/',
  18. 'md5': '8bbfde12b101204b39e4b9fe7eb67095',
  19. 'info_dict': {
  20. 'id': '103545',
  21. 'ext': 'mp4',
  22. 'title': 'Buckcherry`s X Rated Music Video Crazy Bitch',
  23. 'description': 'Crazy Bitch X rated music video.',
  24. 'uploader': 'oreusz',
  25. 'uploader_id': '124697',
  26. 'upload_date': '20070507',
  27. 'age_limit': 18,
  28. }
  29. }
  30. def _real_extract(self, url):
  31. mobj = re.match(self._VALID_URL, url)
  32. video_id = mobj.group('videoid')
  33. url = 'http://www.' + mobj.group('url')
  34. req = compat_urllib_request.Request(url)
  35. req.add_header('Cookie', 'age_verified=1')
  36. webpage = self._download_webpage(req, video_id)
  37. title = self._html_search_regex(
  38. r'<h1>([^<]+)', webpage, 'title')
  39. description = self._html_search_regex(
  40. r'(?s)<div\s+id="descriptionContent">(.+?)</div>',
  41. webpage, 'description', fatal=False)
  42. thumbnail = self._html_search_regex(
  43. r'playerData\.screenShot\s*=\s*["\']([^"\']+)["\']',
  44. webpage, 'thumbnail', fatal=False)
  45. uploader = self._html_search_regex(
  46. r'by:\s*<a [^>]*>(.+?)</a>',
  47. webpage, 'uploader', fatal=False)
  48. uploader_id = self._html_search_regex(
  49. r'by:\s*<a href="/Profile\.aspx\?.*?UserId=(\d+).*?"',
  50. webpage, 'uploader id', fatal=False)
  51. upload_date = unified_strdate(self._html_search_regex(
  52. r'</a> on (.+?) at \d+:\d+',
  53. webpage, 'upload date', fatal=False))
  54. view_count = str_to_int(self._html_search_regex(
  55. r'<div id="viewsCounter"><span>([\d,\.]+)</span> views</div>',
  56. webpage, 'view count', fatal=False))
  57. comment_count = str_to_int(self._html_search_regex(
  58. r'<span\s+id="spCommentCount"[^>]*>([\d,\.]+)</span>',
  59. webpage, 'comment count', fatal=False))
  60. video_urls = list(map(
  61. compat_urllib_parse.unquote,
  62. re.findall(r'playerData\.cdnPath[0-9]{3,}\s*=\s*(?:encodeURIComponent\()?["\']([^"\']+)["\']', webpage)))
  63. if webpage.find('flashvars\.encrypted = "true"') != -1:
  64. password = self._search_regex(
  65. r'flashvars\.video_title = "([^"]+)',
  66. webpage, 'password').replace('+', ' ')
  67. video_urls = list(map(
  68. lambda s: aes_decrypt_text(s, password, 32).decode('utf-8'),
  69. video_urls))
  70. formats = []
  71. for video_url in video_urls:
  72. path = compat_urllib_parse_urlparse(video_url).path
  73. format = path.split('/')[4].split('_')[:2]
  74. resolution, bitrate_str = format
  75. format = "-".join(format)
  76. height = int(resolution.rstrip('Pp'))
  77. tbr = int(bitrate_str.rstrip('Kk'))
  78. formats.append({
  79. 'url': video_url,
  80. 'resolution': resolution,
  81. 'format': format,
  82. 'tbr': tbr,
  83. 'height': height,
  84. 'format_id': format,
  85. })
  86. self._sort_formats(formats)
  87. age_limit = self._rta_search(webpage)
  88. return {
  89. 'id': video_id,
  90. 'title': title,
  91. 'description': description,
  92. 'thumbnail': thumbnail,
  93. 'uploader': uploader,
  94. 'uploader_id': uploader_id,
  95. 'upload_date': upload_date,
  96. 'view_count': view_count,
  97. 'comment_count': comment_count,
  98. 'formats': formats,
  99. 'age_limit': age_limit,
  100. }