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.

124 lines
4.4 KiB

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