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