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.

65 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. 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'videotitle ="([^"]+)', webpage, u'title')
  34. video_description = self._html_search_regex(r'>Description:</strong>(.+?)<', webpage, u'description', fatal=False)
  35. video_uploader = self._html_search_regex(r'>Submitted by:</strong>(?:\s|<[^>]*>)*(.+?)<', webpage, u'uploader', fatal=False)
  36. thumbnail = self._html_search_regex(r'"image_url":"([^"]+)', webpage, u'thumbnail', fatal=False)
  37. if thumbnail:
  38. thumbnail = thumbnail.replace('\\/', '/')
  39. video_url = self._html_search_regex(r'"video_url":"([^"]+)', webpage, u'video_url')
  40. if webpage.find('"encrypted":true')!=-1:
  41. password = self._html_search_regex(r'"video_title":"([^"]+)', webpage, u'password')
  42. video_url = aes_decrypt_text(video_url, password, 32).decode('utf-8')
  43. path = compat_urllib_parse_urlparse( video_url ).path
  44. extension = os.path.splitext( path )[1][1:]
  45. format = path.split('/')[4].split('_')[:2]
  46. format = "-".join( format )
  47. return {
  48. 'id': video_id,
  49. 'uploader': video_uploader,
  50. 'title': video_title,
  51. 'thumbnail': thumbnail,
  52. 'description': video_description,
  53. 'url': video_url,
  54. 'ext': extension,
  55. 'format': format,
  56. 'format_id': format,
  57. 'age_limit': 18,
  58. }