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.8 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. )
  9. from ..aes import (
  10. aes_decrypt_text
  11. )
  12. class SpankwireIE(InfoExtractor):
  13. _VALID_URL = r'^(?:https?://)?(?:www\.)?(?P<url>spankwire\.com/[^/]*/video(?P<videoid>[0-9]+)/?)'
  14. _TEST = {
  15. u'url': u'http://www.spankwire.com/Buckcherry-s-X-Rated-Music-Video-Crazy-Bitch/video103545/',
  16. u'file': u'103545.mp4',
  17. u'md5': u'1b3f55e345500552dbc252a3e9c1af43',
  18. u'info_dict': {
  19. u"uploader": u"oreusz",
  20. u"title": u"Buckcherry`s X Rated Music Video Crazy Bitch",
  21. u"description": u"Crazy Bitch X rated music video.",
  22. u"age_limit": 18,
  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(
  34. r'by:\s*<a [^>]*>(.+?)</a>', webpage, u'uploader', fatal=False)
  35. thumbnail = self._html_search_regex(
  36. r'flashvars\.image_url = "([^"]+)', webpage, u'thumbnail', fatal=False)
  37. description = self._html_search_regex(
  38. r'<div\s+id="descriptionContent">([^<]+)<', webpage, u'description', fatal=False)
  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. }