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.

114 lines
4.2 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. def _real_extract(self, url):
  73. mobj = re.match(self._VALID_URL, url)
  74. username = mobj.group('username')
  75. profile_page = self._download_webpage(
  76. url, username, note='Retrieving profile page')
  77. video_count = int(self._search_regex(
  78. r'<strong>%s\'s Videos \(([0-9]+)\)</strong>'%username, profile_page,
  79. 'video count'))
  80. PAGE_SIZE = 25
  81. urls = []
  82. page_count = (video_count + PAGE_SIZE + 1) // PAGE_SIZE
  83. for n in range(1, page_count + 1):
  84. lpage_url = 'http://www.xtube.com/user_videos.php?page=%d&u=%s' % (n, username)
  85. lpage = self._download_webpage(
  86. lpage_url, username,
  87. note='Downloading page %d/%d' % (n, page_count))
  88. urls.extend(
  89. re.findall(r'addthis:url="([^"]+)"', lpage))
  90. return {
  91. '_type': 'playlist',
  92. 'id': username,
  93. 'entries': [{
  94. '_type': 'url',
  95. 'url': eurl,
  96. 'ie_key': 'XTube',
  97. } for eurl in urls]
  98. }