spankwire.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_urllib_parse_unquote,
  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. _TESTS = [{
  17. # download URL pattern: */<height>P_<tbr>K_<video_id>.mp4
  18. 'url': 'http://www.spankwire.com/Buckcherry-s-X-Rated-Music-Video-Crazy-Bitch/video103545/',
  19. 'md5': '8bbfde12b101204b39e4b9fe7eb67095',
  20. 'info_dict': {
  21. 'id': '103545',
  22. 'ext': 'mp4',
  23. 'title': 'Buckcherry`s X Rated Music Video Crazy Bitch',
  24. 'description': 'Crazy Bitch X rated music video.',
  25. 'uploader': 'oreusz',
  26. 'uploader_id': '124697',
  27. 'upload_date': '20070507',
  28. 'age_limit': 18,
  29. }
  30. }, {
  31. # download URL pattern: */mp4_<format_id>_<video_id>.mp4
  32. 'url': 'http://www.spankwire.com/Titcums-Compiloation-I/video1921551/',
  33. 'md5': '09b3c20833308b736ae8902db2f8d7e6',
  34. 'info_dict': {
  35. 'id': '1921551',
  36. 'ext': 'mp4',
  37. 'title': 'Titcums Compiloation I',
  38. 'description': 'cum on tits',
  39. 'uploader': 'dannyh78999',
  40. 'uploader_id': '3056053',
  41. 'upload_date': '20150822',
  42. 'age_limit': 18,
  43. },
  44. }]
  45. def _real_extract(self, url):
  46. mobj = re.match(self._VALID_URL, url)
  47. video_id = mobj.group('videoid')
  48. url = 'http://www.' + mobj.group('url')
  49. req = compat_urllib_request.Request(url)
  50. req.add_header('Cookie', 'age_verified=1')
  51. webpage = self._download_webpage(req, video_id)
  52. title = self._html_search_regex(
  53. r'<h1>([^<]+)', webpage, 'title')
  54. description = self._html_search_regex(
  55. r'(?s)<div\s+id="descriptionContent">(.+?)</div>',
  56. webpage, 'description', fatal=False)
  57. thumbnail = self._html_search_regex(
  58. r'playerData\.screenShot\s*=\s*["\']([^"\']+)["\']',
  59. webpage, 'thumbnail', fatal=False)
  60. uploader = self._html_search_regex(
  61. r'by:\s*<a [^>]*>(.+?)</a>',
  62. webpage, 'uploader', fatal=False)
  63. uploader_id = self._html_search_regex(
  64. r'by:\s*<a href="/user/viewProfile\?.*?UserId=(\d+).*?"',
  65. webpage, 'uploader id', fatal=False)
  66. upload_date = unified_strdate(self._html_search_regex(
  67. r'</a> on (.+?) at \d+:\d+',
  68. webpage, 'upload date', fatal=False))
  69. view_count = str_to_int(self._html_search_regex(
  70. r'<div id="viewsCounter"><span>([\d,\.]+)</span> views</div>',
  71. webpage, 'view count', fatal=False))
  72. comment_count = str_to_int(self._html_search_regex(
  73. r'<span\s+id="spCommentCount"[^>]*>([\d,\.]+)</span>',
  74. webpage, 'comment count', fatal=False))
  75. videos = re.findall(
  76. r'playerData\.cdnPath([0-9]{3,})\s*=\s*(?:encodeURIComponent\()?["\']([^"\']+)["\']', webpage)
  77. heights = [int(video[0]) for video in videos]
  78. video_urls = list(map(compat_urllib_parse_unquote, [video[1] for video in videos]))
  79. if webpage.find('flashvars\.encrypted = "true"') != -1:
  80. password = self._search_regex(
  81. r'flashvars\.video_title = "([^"]+)',
  82. webpage, 'password').replace('+', ' ')
  83. video_urls = list(map(
  84. lambda s: aes_decrypt_text(s, password, 32).decode('utf-8'),
  85. video_urls))
  86. formats = []
  87. for height, video_url in zip(heights, video_urls):
  88. path = compat_urllib_parse_urlparse(video_url).path
  89. _, quality = path.split('/')[4].split('_')[:2]
  90. f = {
  91. 'url': video_url,
  92. 'height': height,
  93. }
  94. tbr = self._search_regex(r'^(\d+)[Kk]$', quality, 'tbr', default=None)
  95. if tbr:
  96. f.update({
  97. 'tbr': int(tbr),
  98. 'format_id': '%dp' % height,
  99. })
  100. else:
  101. f['format_id'] = quality
  102. formats.append(f)
  103. self._sort_formats(formats)
  104. age_limit = self._rta_search(webpage)
  105. return {
  106. 'id': video_id,
  107. 'title': title,
  108. 'description': description,
  109. 'thumbnail': thumbnail,
  110. 'uploader': uploader,
  111. 'uploader_id': uploader_id,
  112. 'upload_date': upload_date,
  113. 'view_count': view_count,
  114. 'comment_count': comment_count,
  115. 'formats': formats,
  116. 'age_limit': age_limit,
  117. }