spankwire.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. }
  24. }
  25. def _real_extract(self, url):
  26. mobj = re.match(self._VALID_URL, url)
  27. video_id = mobj.group('videoid')
  28. url = 'http://www.' + mobj.group('url')
  29. req = compat_urllib_request.Request(url)
  30. req.add_header('Cookie', 'age_verified=1')
  31. webpage = self._download_webpage(req, video_id)
  32. video_title = self._html_search_regex(r'<h1>([^<]+)', webpage, u'title')
  33. video_uploader = self._html_search_regex(r'by:\s*<a [^>]*>(.+?)</a>', webpage, u'uploader', fatal=False)
  34. thumbnail = self._html_search_regex(r'flashvars\.image_url = "([^"]+)', webpage, u'thumbnail', fatal=False)
  35. description = self._html_search_regex(r'>\s*Description:</div>\s*<[^>]*>([^<]+)', webpage, u'description', fatal=False)
  36. if len(description) == 0:
  37. description = None
  38. video_urls = list(map(compat_urllib_parse.unquote , re.findall(r'flashvars\.quality_[0-9]{3}p = "([^"]+)', webpage)))
  39. if webpage.find('flashvars\.encrypted = "true"') != -1:
  40. password = self._html_search_regex(r'flashvars\.video_title = "([^"]+)', webpage, u'password').replace('+', ' ')
  41. video_urls = list(map(lambda s: aes_decrypt_text(s, password, 32).decode('utf-8'), video_urls))
  42. formats = []
  43. for video_url in video_urls:
  44. path = compat_urllib_parse_urlparse( video_url ).path
  45. extension = os.path.splitext( path )[1][1:]
  46. format = path.split('/')[4].split('_')[:2]
  47. format = "-".join( format )
  48. formats.append({
  49. 'url': video_url,
  50. 'ext': extension,
  51. 'format': format,
  52. 'format_id': format,
  53. })
  54. formats.sort(key=lambda format: list(map(lambda s: s.zfill(6), format['format'].split('-'))))
  55. return {
  56. 'id': video_id,
  57. 'uploader': video_uploader,
  58. 'title': video_title,
  59. 'thumbnail': thumbnail,
  60. 'description': description,
  61. 'formats': formats,
  62. }