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.

122 lines
4.4 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. import json
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. compat_urllib_request,
  7. parse_duration,
  8. str_to_int,
  9. )
  10. class XTubeIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?(?P<url>xtube\.com/watch\.php\?v=(?P<videoid>[^/?&]+))'
  12. _TEST = {
  13. 'url': 'http://www.xtube.com/watch.php?v=kVTUy_G222_',
  14. 'md5': '092fbdd3cbe292c920ef6fc6a8a9cdab',
  15. 'info_dict': {
  16. 'id': 'kVTUy_G222_',
  17. 'ext': 'mp4',
  18. 'title': 'strange erotica',
  19. 'description': 'surreal gay themed erotica...almost an ET kind of thing',
  20. 'uploader': 'greenshowers',
  21. 'duration': 450,
  22. 'age_limit': 18,
  23. }
  24. }
  25. def _real_extract(self, url):
  26. mobj = re.match(self._VALID_URL, url)
  27. video_id = mobj.group('videoid')
  28. url = 'http://www.' + mobj.group('url')
  29. req = compat_urllib_request.Request(url)
  30. req.add_header('Cookie', 'age_verified=1')
  31. webpage = self._download_webpage(req, video_id)
  32. video_title = self._html_search_regex(r'<p class="title">([^<]+)', webpage, 'title')
  33. video_uploader = self._html_search_regex(
  34. r'so_s\.addVariable\("owner_u", "([^"]+)', webpage, 'uploader', fatal=False)
  35. video_description = self._html_search_regex(
  36. r'<p class="fieldsDesc">([^<]+)', webpage, 'description', fatal=False)
  37. duration = parse_duration(self._html_search_regex(
  38. r'<span class="bold">Runtime:</span> ([^<]+)</p>', webpage, 'duration', fatal=False))
  39. view_count = self._html_search_regex(
  40. r'<span class="bold">Views:</span> ([\d,\.]+)</p>', webpage, 'view count', fatal=False)
  41. if view_count:
  42. view_count = str_to_int(view_count)
  43. comment_count = self._html_search_regex(
  44. r'<div id="commentBar">([\d,\.]+) Comments</div>', webpage, 'comment count', fatal=False)
  45. if comment_count:
  46. comment_count = str_to_int(comment_count)
  47. player_quality_option = json.loads(self._html_search_regex(
  48. r'playerQualityOption = ({.+?});', webpage, 'player quality option'))
  49. QUALITIES = ['3gp', 'mp4_normal', 'mp4_high', 'flv', 'mp4_ultra', 'mp4_720', 'mp4_1080']
  50. formats = [
  51. {
  52. 'url': furl,
  53. 'format_id': format_id,
  54. 'preference': QUALITIES.index(format_id) if format_id in QUALITIES else -1,
  55. } for format_id, furl in player_quality_option.items()
  56. ]
  57. self._sort_formats(formats)
  58. return {
  59. 'id': video_id,
  60. 'title': video_title,
  61. 'uploader': video_uploader,
  62. 'description': video_description,
  63. 'duration': duration,
  64. 'view_count': view_count,
  65. 'comment_count': comment_count,
  66. 'formats': formats,
  67. 'age_limit': 18,
  68. }
  69. class XTubeUserIE(InfoExtractor):
  70. IE_DESC = 'XTube user profile'
  71. _VALID_URL = r'https?://(?:www\.)?xtube\.com/community/profile\.php\?(.*?)user=(?P<username>[^&#]+)(?:$|[&#])'
  72. _TEST = {
  73. 'url': 'http://www.xtube.com/community/profile.php?user=greenshowers',
  74. 'info_dict': {
  75. 'id': 'greenshowers',
  76. },
  77. 'playlist_mincount': 155,
  78. }
  79. def _real_extract(self, url):
  80. mobj = re.match(self._VALID_URL, url)
  81. username = mobj.group('username')
  82. profile_page = self._download_webpage(
  83. url, username, note='Retrieving profile page')
  84. video_count = int(self._search_regex(
  85. r'<strong>%s\'s Videos \(([0-9]+)\)</strong>'%username, profile_page,
  86. 'video count'))
  87. PAGE_SIZE = 25
  88. urls = []
  89. page_count = (video_count + PAGE_SIZE + 1) // PAGE_SIZE
  90. for n in range(1, page_count + 1):
  91. lpage_url = 'http://www.xtube.com/user_videos.php?page=%d&u=%s' % (n, username)
  92. lpage = self._download_webpage(
  93. lpage_url, username,
  94. note='Downloading page %d/%d' % (n, page_count))
  95. urls.extend(
  96. re.findall(r'addthis:url="([^"]+)"', lpage))
  97. return {
  98. '_type': 'playlist',
  99. 'id': username,
  100. 'entries': [{
  101. '_type': 'url',
  102. 'url': eurl,
  103. 'ie_key': 'XTube',
  104. } for eurl in urls]
  105. }