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.

57 lines
2.2 KiB

  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import compat_urllib_request
  4. class FourTubeIE(InfoExtractor):
  5. IE_NAME = '4tube'
  6. _VALID_URL = r'(?:https?://)?www\.4tube\.com/videos/(?P<id>\d+)/.*'
  7. _TEST = {
  8. 'url': 'http://www.4tube.com/videos/209733/hot-babe-holly-michaels-gets-her-ass-stuffed-by-black',
  9. 'md5': '6516c8ac63b03de06bc8eac14362db4f',
  10. 'info_dict': {
  11. 'id': '209733',
  12. 'ext': 'mp4',
  13. 'title': 'Hot Babe Holly Michaels gets her ass stuffed by black'
  14. }
  15. }
  16. def _real_extract(self, url):
  17. mobj = re.match(self._VALID_URL, url)
  18. video_id = mobj.group('id')
  19. webpage_url = 'http://www.4tube.com/videos/' + video_id
  20. webpage = self._download_webpage(webpage_url, video_id)
  21. self.report_extraction(video_id)
  22. playlist_json = self._html_search_regex(r'var playerConfigPlaylist\s+=\s+([^;]+)', webpage, u'Playlist')
  23. media_id = self._search_regex(r'idMedia:\s*(\d+)', playlist_json, u"Media Id")
  24. thumbnail_url = self._search_regex(r'image:\s*"([^"]*)', playlist_json, u'Thumbnail')
  25. sources = self._search_regex(r'sources:\s*\[([^\]]*)\]', playlist_json, u'Sources').split(',')
  26. title = self._search_regex(r'title:\s*"([^"]*)', playlist_json, u'Title')
  27. token_url = "http://tkn.4tube.com/{0}/desktop/{1}".format(media_id, "+".join(sources))
  28. headers = {
  29. b'Content-Type': b'application/x-www-form-urlencoded',
  30. b'Origin': b'http://www.4tube.com',
  31. }
  32. token_req = compat_urllib_request.Request(token_url, b'{}', headers)
  33. tokens = self._download_json(token_req, video_id)
  34. formats = [{
  35. 'url': tokens[format]['token'],
  36. 'format_id': format + 'p',
  37. 'resolution': format + 'p',
  38. 'quality': int(format),
  39. } for format in sources]
  40. return [{
  41. 'id': video_id,
  42. 'title': title,
  43. 'formats': formats,
  44. 'thumbnail': thumbnail_url,
  45. 'age_limit': 18,
  46. 'webpage_url': webpage_url,
  47. }]