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.

84 lines
3.0 KiB

  1. from __future__ import unicode_literals
  2. import os
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. compat_urllib_parse_urlparse,
  7. compat_urllib_request,
  8. compat_urllib_parse,
  9. )
  10. from ..aes import (
  11. aes_decrypt_text
  12. )
  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. 'file': '103545.mp4',
  18. 'md5': '1b3f55e345500552dbc252a3e9c1af43',
  19. 'info_dict': {
  20. "uploader": "oreusz",
  21. "title": "Buckcherry`s X Rated Music Video Crazy Bitch",
  22. "description": "Crazy Bitch X rated music video.",
  23. "age_limit": 18,
  24. }
  25. }
  26. def _real_extract(self, url):
  27. mobj = re.match(self._VALID_URL, url)
  28. video_id = mobj.group('videoid')
  29. url = 'http://www.' + mobj.group('url')
  30. req = compat_urllib_request.Request(url)
  31. req.add_header('Cookie', 'age_verified=1')
  32. webpage = self._download_webpage(req, video_id)
  33. video_title = self._html_search_regex(r'<h1>([^<]+)', webpage, 'title')
  34. video_uploader = self._html_search_regex(
  35. r'by:\s*<a [^>]*>(.+?)</a>', webpage, 'uploader', fatal=False)
  36. thumbnail = self._html_search_regex(
  37. r'flashvars\.image_url = "([^"]+)', webpage, 'thumbnail', fatal=False)
  38. description = self._html_search_regex(
  39. r'<div\s+id="descriptionContent">([^<]+)<', webpage, 'description', fatal=False)
  40. video_urls = list(map(compat_urllib_parse.unquote , re.findall(r'flashvars\.quality_[0-9]{3}p = "([^"]+)', webpage)))
  41. if webpage.find('flashvars\.encrypted = "true"') != -1:
  42. password = self._html_search_regex(r'flashvars\.video_title = "([^"]+)', webpage, 'password').replace('+', ' ')
  43. video_urls = list(map(lambda s: aes_decrypt_text(s, password, 32).decode('utf-8'), video_urls))
  44. formats = []
  45. for video_url in video_urls:
  46. path = compat_urllib_parse_urlparse(video_url).path
  47. extension = os.path.splitext(path)[1][1:]
  48. format = path.split('/')[4].split('_')[:2]
  49. resolution, bitrate_str = format
  50. format = "-".join(format)
  51. height = int(resolution.rstrip('P'))
  52. tbr = int(bitrate_str.rstrip('K'))
  53. formats.append({
  54. 'url': video_url,
  55. 'ext': extension,
  56. 'resolution': resolution,
  57. 'format': format,
  58. 'tbr': tbr,
  59. 'height': height,
  60. 'format_id': format,
  61. })
  62. self._sort_formats(formats)
  63. age_limit = self._rta_search(webpage)
  64. return {
  65. 'id': video_id,
  66. 'uploader': video_uploader,
  67. 'title': video_title,
  68. 'thumbnail': thumbnail,
  69. 'description': description,
  70. 'formats': formats,
  71. 'age_limit': age_limit,
  72. }