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.

74 lines
2.9 KiB

  1. import os
  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. unescapeHTML,
  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. u'url': u'http://www.spankwire.com/Buckcherry-s-X-Rated-Music-Video-Crazy-Bitch/video103545/',
  17. u'file': u'103545.mp4',
  18. u'md5': u'1b3f55e345500552dbc252a3e9c1af43',
  19. u'info_dict': {
  20. u"uploader": u"oreusz",
  21. u"title": u"Buckcherry`s X Rated Music Video Crazy Bitch",
  22. u"description": u"Crazy Bitch X rated music video.",
  23. u"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, u'title')
  34. video_uploader = self._html_search_regex(r'by:\s*<a [^>]*>(.+?)</a>', webpage, u'uploader', fatal=False)
  35. thumbnail = self._html_search_regex(r'flashvars\.image_url = "([^"]+)', webpage, u'thumbnail', fatal=False)
  36. description = self._html_search_regex(r'>\s*Description:</div>\s*<[^>]*>([^<]+)', webpage, u'description', fatal=False)
  37. if len(description) == 0:
  38. description = None
  39. video_urls = list(map(compat_urllib_parse.unquote , re.findall(r'flashvars\.quality_[0-9]{3}p = "([^"]+)', webpage)))
  40. if webpage.find('flashvars\.encrypted = "true"') != -1:
  41. password = self._html_search_regex(r'flashvars\.video_title = "([^"]+)', webpage, u'password').replace('+', ' ')
  42. video_urls = list(map(lambda s: aes_decrypt_text(s, password, 32).decode('utf-8'), video_urls))
  43. formats = []
  44. for video_url in video_urls:
  45. path = compat_urllib_parse_urlparse( video_url ).path
  46. extension = os.path.splitext( path )[1][1:]
  47. format = path.split('/')[4].split('_')[:2]
  48. format = "-".join( format )
  49. formats.append({
  50. 'url': video_url,
  51. 'ext': extension,
  52. 'format': format,
  53. 'format_id': format,
  54. })
  55. formats.sort(key=lambda format: list(map(lambda s: s.zfill(6), format['format'].split('-'))))
  56. age_limit = self._rta_search(webpage)
  57. return {
  58. 'id': video_id,
  59. 'uploader': video_uploader,
  60. 'title': video_title,
  61. 'thumbnail': thumbnail,
  62. 'description': description,
  63. 'formats': formats,
  64. 'age_limit': age_limit,
  65. }