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.

95 lines
3.6 KiB

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