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.

134 lines
4.5 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. compat_urllib_parse,
  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. video_id = self._match_id(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(
  33. r'<p class="title">([^<]+)', webpage, 'title')
  34. video_uploader = self._html_search_regex(
  35. [r"var\s+contentOwnerId\s*=\s*'([^']+)",
  36. r'By:\s*<a href="/community/profile\.php\?user=([^"]+)'],
  37. webpage, 'uploader', fatal=False)
  38. video_description = self._html_search_regex(
  39. r'<p class="fieldsDesc">([^<]+)',
  40. webpage, 'description', fatal=False)
  41. duration = parse_duration(self._html_search_regex(
  42. r'<span class="bold">Runtime:</span> ([^<]+)</p>',
  43. webpage, 'duration', fatal=False))
  44. view_count = str_to_int(self._html_search_regex(
  45. r'<span class="bold">Views:</span> ([\d,\.]+)</p>',
  46. webpage, 'view count', fatal=False))
  47. comment_count = str_to_int(self._html_search_regex(
  48. r'<div id="commentBar">([\d,\.]+) Comments</div>',
  49. webpage, 'comment count', fatal=False))
  50. formats = []
  51. for format_id, video_url in re.findall(
  52. r'flashvars\.quality_(.+?)\s*=\s*"([^"]+)"', webpage):
  53. fmt = {
  54. 'url': compat_urllib_parse.unquote(video_url),
  55. 'format_id': format_id,
  56. }
  57. m = re.search(r'^(?P<height>\d+)[pP]', format_id)
  58. if m:
  59. fmt['height'] = int(m.group('height'))
  60. formats.append(fmt)
  61. if not formats:
  62. video_url = compat_urllib_parse.unquote(self._search_regex(
  63. r'flashvars\.video_url\s*=\s*"([^"]+)"',
  64. webpage, 'video URL'))
  65. formats.append({'url': video_url})
  66. self._sort_formats(formats)
  67. return {
  68. 'id': video_id,
  69. 'title': video_title,
  70. 'uploader': video_uploader,
  71. 'description': video_description,
  72. 'duration': duration,
  73. 'view_count': view_count,
  74. 'comment_count': comment_count,
  75. 'formats': formats,
  76. 'age_limit': 18,
  77. }
  78. class XTubeUserIE(InfoExtractor):
  79. IE_DESC = 'XTube user profile'
  80. _VALID_URL = r'https?://(?:www\.)?xtube\.com/community/profile\.php\?(.*?)user=(?P<username>[^&#]+)(?:$|[&#])'
  81. _TEST = {
  82. 'url': 'http://www.xtube.com/community/profile.php?user=greenshowers',
  83. 'info_dict': {
  84. 'id': 'greenshowers',
  85. 'age_limit': 18,
  86. },
  87. 'playlist_mincount': 155,
  88. }
  89. def _real_extract(self, url):
  90. mobj = re.match(self._VALID_URL, url)
  91. username = mobj.group('username')
  92. profile_page = self._download_webpage(
  93. url, username, note='Retrieving profile page')
  94. video_count = int(self._search_regex(
  95. r'<strong>%s\'s Videos \(([0-9]+)\)</strong>' % username, profile_page,
  96. 'video count'))
  97. PAGE_SIZE = 25
  98. urls = []
  99. page_count = (video_count + PAGE_SIZE + 1) // PAGE_SIZE
  100. for n in range(1, page_count + 1):
  101. lpage_url = 'http://www.xtube.com/user_videos.php?page=%d&u=%s' % (n, username)
  102. lpage = self._download_webpage(
  103. lpage_url, username,
  104. note='Downloading page %d/%d' % (n, page_count))
  105. urls.extend(
  106. re.findall(r'addthis:url="([^"]+)"', lpage))
  107. return {
  108. '_type': 'playlist',
  109. 'id': username,
  110. 'age_limit': 18,
  111. 'entries': [{
  112. '_type': 'url',
  113. 'url': eurl,
  114. 'ie_key': 'XTube',
  115. } for eurl in urls]
  116. }