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.

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