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.

63 lines
2.4 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 Tube8IE(InfoExtractor):
  14. _VALID_URL = r'^(?:https?://)?(?:www\.)?(?P<url>tube8\.com/[^/]+/[^/]+/(?P<videoid>[0-9]+)/?)'
  15. _TEST = {
  16. u'url': u'http://www.tube8.com/teen/kasia-music-video/229795/',
  17. u'file': u'229795.mp4',
  18. u'md5': u'e9e0b0c86734e5e3766e653509475db0',
  19. u'info_dict': {
  20. u"description": u"hot teen Kasia grinding",
  21. u"uploader": u"unknown",
  22. u"title": u"Kasia 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'videotitle ="([^"]+)', webpage, u'title')
  33. video_description = self._html_search_regex(r'>Description:</strong>(.+?)<', webpage, u'description', fatal=False)
  34. video_uploader = self._html_search_regex(r'>Submitted by:</strong>(?:\s|<[^>]*>)*(.+?)<', webpage, u'uploader', fatal=False)
  35. thumbnail = self._html_search_regex(r'"image_url":"([^"]+)', webpage, u'thumbnail', fatal=False)
  36. if thumbnail:
  37. thumbnail = thumbnail.replace('\\/', '/')
  38. video_url = self._html_search_regex(r'"video_url":"([^"]+)', webpage, u'video_url')
  39. if webpage.find('"encrypted":true')!=-1:
  40. password = self._html_search_regex(r'"video_title":"([^"]+)', webpage, u'password')
  41. video_url = aes_decrypt_text(video_url, password, 32).decode('utf-8')
  42. path = compat_urllib_parse_urlparse( video_url ).path
  43. extension = os.path.splitext( path )[1][1:]
  44. format = path.split('/')[4].split('_')[:2]
  45. format = "-".join( format )
  46. return {
  47. 'id': video_id,
  48. 'uploader': video_uploader,
  49. 'title': video_title,
  50. 'thumbnail': thumbnail,
  51. 'description': video_description,
  52. 'url': video_url,
  53. 'ext': extension,
  54. 'format': format,
  55. 'format_id': format,
  56. }