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.

94 lines
3.6 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. compat_urllib_request,
  6. unified_strdate,
  7. str_to_int,
  8. parse_duration,
  9. clean_html,
  10. )
  11. class FourTubeIE(InfoExtractor):
  12. IE_NAME = '4tube'
  13. _VALID_URL = r'https?://(?:www\.)?4tube\.com/videos/(?P<id>\d+)'
  14. _TEST = {
  15. 'url': 'http://www.4tube.com/videos/209733/hot-babe-holly-michaels-gets-her-ass-stuffed-by-black',
  16. 'md5': '6516c8ac63b03de06bc8eac14362db4f',
  17. 'info_dict': {
  18. 'id': '209733',
  19. 'ext': 'mp4',
  20. 'title': 'Hot Babe Holly Michaels gets her ass stuffed by black',
  21. 'uploader': 'WCP Club',
  22. 'uploader_id': 'wcp-club',
  23. 'upload_date': '20131031',
  24. 'duration': 583,
  25. }
  26. }
  27. def _real_extract(self, url):
  28. mobj = re.match(self._VALID_URL, url)
  29. video_id = mobj.group('id')
  30. webpage_url = 'http://www.4tube.com/videos/' + video_id
  31. webpage = self._download_webpage(webpage_url, video_id)
  32. self.report_extraction(video_id)
  33. playlist_json = self._html_search_regex(r'var playerConfigPlaylist\s+=\s+([^;]+)', webpage, 'Playlist')
  34. media_id = self._search_regex(r'idMedia:\s*(\d+)', playlist_json, 'Media Id')
  35. sources = self._search_regex(r'sources:\s*\[([^\]]*)\]', playlist_json, 'Sources').split(',')
  36. title = self._search_regex(r'title:\s*"([^"]*)', playlist_json, 'Title')
  37. thumbnail_url = self._search_regex(r'image:\s*"([^"]*)', playlist_json, 'Thumbnail', fatal=False)
  38. uploader_str = self._search_regex(r'<span>Uploaded by</span>(.*?)<span>', webpage, 'uploader', fatal=False)
  39. mobj = re.search(r'<a href="/sites/(?P<id>[^"]+)"><strong>(?P<name>[^<]+)</strong></a>', uploader_str)
  40. (uploader, uploader_id) = (mobj.group('name'), mobj.group('id')) if mobj else (clean_html(uploader_str), None)
  41. upload_date = None
  42. view_count = None
  43. duration = None
  44. description = self._html_search_meta('description', webpage, 'description')
  45. if description:
  46. upload_date = self._search_regex(r'Published Date: (\d{2} [a-zA-Z]{3} \d{4})', description, 'upload date',
  47. fatal=False)
  48. if upload_date:
  49. upload_date = unified_strdate(upload_date)
  50. view_count = self._search_regex(r'Views: ([\d,\.]+)', description, 'view count', fatal=False)
  51. if view_count:
  52. view_count = str_to_int(view_count)
  53. duration = parse_duration(self._search_regex(r'Length: (\d+m\d+s)', description, 'duration', fatal=False))
  54. token_url = "http://tkn.4tube.com/{0}/desktop/{1}".format(media_id, "+".join(sources))
  55. headers = {
  56. b'Content-Type': b'application/x-www-form-urlencoded',
  57. b'Origin': b'http://www.4tube.com',
  58. }
  59. token_req = compat_urllib_request.Request(token_url, b'{}', headers)
  60. tokens = self._download_json(token_req, video_id)
  61. formats = [{
  62. 'url': tokens[format]['token'],
  63. 'format_id': format + 'p',
  64. 'resolution': format + 'p',
  65. 'quality': int(format),
  66. } for format in sources]
  67. self._sort_formats(formats)
  68. return {
  69. 'id': video_id,
  70. 'title': title,
  71. 'formats': formats,
  72. 'thumbnail': thumbnail_url,
  73. 'uploader': uploader,
  74. 'uploader_id': uploader_id,
  75. 'upload_date': upload_date,
  76. 'view_count': view_count,
  77. 'duration': duration,
  78. 'age_limit': 18,
  79. 'webpage_url': webpage_url,
  80. }