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.

111 lines
4.0 KiB

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