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.

158 lines
5.1 KiB

Switch codebase to use sanitized_Request instead of compat_urllib_request.Request [downloader/dash] Use sanitized_Request [downloader/http] Use sanitized_Request [atresplayer] Use sanitized_Request [bambuser] Use sanitized_Request [bliptv] Use sanitized_Request [brightcove] Use sanitized_Request [cbs] Use sanitized_Request [ceskatelevize] Use sanitized_Request [collegerama] Use sanitized_Request [extractor/common] Use sanitized_Request [crunchyroll] Use sanitized_Request [dailymotion] Use sanitized_Request [dcn] Use sanitized_Request [dramafever] Use sanitized_Request [dumpert] Use sanitized_Request [eitb] Use sanitized_Request [escapist] Use sanitized_Request [everyonesmixtape] Use sanitized_Request [extremetube] Use sanitized_Request [facebook] Use sanitized_Request [fc2] Use sanitized_Request [flickr] Use sanitized_Request [4tube] Use sanitized_Request [gdcvault] Use sanitized_Request [extractor/generic] Use sanitized_Request [hearthisat] Use sanitized_Request [hotnewhiphop] Use sanitized_Request [hypem] Use sanitized_Request [iprima] Use sanitized_Request [ivi] Use sanitized_Request [keezmovies] Use sanitized_Request [letv] Use sanitized_Request [lynda] Use sanitized_Request [metacafe] Use sanitized_Request [minhateca] Use sanitized_Request [miomio] Use sanitized_Request [meovideo] Use sanitized_Request [mofosex] Use sanitized_Request [moniker] Use sanitized_Request [mooshare] Use sanitized_Request [movieclips] Use sanitized_Request [mtv] Use sanitized_Request [myvideo] Use sanitized_Request [neteasemusic] Use sanitized_Request [nfb] Use sanitized_Request [niconico] Use sanitized_Request [noco] Use sanitized_Request [nosvideo] Use sanitized_Request [novamov] Use sanitized_Request [nowness] Use sanitized_Request [nuvid] Use sanitized_Request [played] Use sanitized_Request [pluralsight] Use sanitized_Request [pornhub] Use sanitized_Request [pornotube] Use sanitized_Request [primesharetv] Use sanitized_Request [promptfile] Use sanitized_Request [qqmusic] Use sanitized_Request [rtve] Use sanitized_Request [safari] Use sanitized_Request [sandia] Use sanitized_Request [shared] Use sanitized_Request [sharesix] Use sanitized_Request [sina] Use sanitized_Request [smotri] Use sanitized_Request [sohu] Use sanitized_Request [spankwire] Use sanitized_Request [sportdeutschland] Use sanitized_Request [streamcloud] Use sanitized_Request [streamcz] Use sanitized_Request [tapely] Use sanitized_Request [tube8] Use sanitized_Request [tubitv] Use sanitized_Request [twitch] Use sanitized_Request [twitter] Use sanitized_Request [udemy] Use sanitized_Request [vbox7] Use sanitized_Request [veoh] Use sanitized_Request [vessel] Use sanitized_Request [vevo] Use sanitized_Request [viddler] Use sanitized_Request [videomega] Use sanitized_Request [viewvster] Use sanitized_Request [viki] Use sanitized_Request [vk] Use sanitized_Request [vodlocker] Use sanitized_Request [voicerepublic] Use sanitized_Request [wistia] Use sanitized_Request [xfileshare] Use sanitized_Request [xtube] Use sanitized_Request [xvideos] Use sanitized_Request [yandexmusic] Use sanitized_Request [youku] Use sanitized_Request [youporn] Use sanitized_Request [youtube] Use sanitized_Request [patreon] Use sanitized_Request [extractor/common] Remove unused import [nfb] PEP 8
9 years ago
  1. from __future__ import unicode_literals
  2. import itertools
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. int_or_none,
  7. orderedSet,
  8. parse_duration,
  9. sanitized_Request,
  10. str_to_int,
  11. )
  12. class XTubeIE(InfoExtractor):
  13. _VALID_URL = r'''(?x)
  14. (?:
  15. xtube:|
  16. https?://(?:www\.)?xtube\.com/(?:watch\.php\?.*\bv=|video-watch/(?P<display_id>[^/]+)-)
  17. )
  18. (?P<id>[^/?&#]+)
  19. '''
  20. _TESTS = [{
  21. # old URL schema
  22. 'url': 'http://www.xtube.com/watch.php?v=kVTUy_G222_',
  23. 'md5': '092fbdd3cbe292c920ef6fc6a8a9cdab',
  24. 'info_dict': {
  25. 'id': 'kVTUy_G222_',
  26. 'ext': 'mp4',
  27. 'title': 'strange erotica',
  28. 'description': 'contains:an ET kind of thing',
  29. 'uploader': 'greenshowers',
  30. 'duration': 450,
  31. 'view_count': int,
  32. 'comment_count': int,
  33. 'age_limit': 18,
  34. }
  35. }, {
  36. # new URL schema
  37. 'url': 'http://www.xtube.com/video-watch/strange-erotica-625837',
  38. 'only_matching': True,
  39. }, {
  40. 'url': 'xtube:625837',
  41. 'only_matching': True,
  42. }, {
  43. 'url': 'xtube:kVTUy_G222_',
  44. 'only_matching': True,
  45. }]
  46. def _real_extract(self, url):
  47. mobj = re.match(self._VALID_URL, url)
  48. video_id = mobj.group('id')
  49. display_id = mobj.group('display_id')
  50. if not display_id:
  51. display_id = video_id
  52. if video_id.isdigit() and len(video_id) < 11:
  53. url_pattern = 'http://www.xtube.com/video-watch/-%s'
  54. else:
  55. url_pattern = 'http://www.xtube.com/watch.php?v=%s'
  56. webpage = self._download_webpage(
  57. url_pattern % video_id, display_id, headers={
  58. 'Cookie': 'age_verified=1; cookiesAccepted=1',
  59. })
  60. sources = self._parse_json(self._search_regex(
  61. r'(["\'])sources\1\s*:\s*(?P<sources>{.+?}),',
  62. webpage, 'sources', group='sources'), video_id)
  63. formats = []
  64. for format_id, format_url in sources.items():
  65. formats.append({
  66. 'url': format_url,
  67. 'format_id': format_id,
  68. 'height': int_or_none(format_id),
  69. })
  70. self._sort_formats(formats)
  71. title = self._search_regex(
  72. (r'<h1>\s*(?P<title>[^<]+?)\s*</h1>', r'videoTitle\s*:\s*(["\'])(?P<title>.+?)\1'),
  73. webpage, 'title', group='title')
  74. description = self._search_regex(
  75. r'</h1>\s*<p>([^<]+)', webpage, 'description', fatal=False)
  76. uploader = self._search_regex(
  77. (r'<input[^>]+name="contentOwnerId"[^>]+value="([^"]+)"',
  78. r'<span[^>]+class="nickname"[^>]*>([^<]+)'),
  79. webpage, 'uploader', fatal=False)
  80. duration = parse_duration(self._search_regex(
  81. r'<dt>Runtime:?</dt>\s*<dd>([^<]+)</dd>',
  82. webpage, 'duration', fatal=False))
  83. view_count = str_to_int(self._search_regex(
  84. r'<dt>Views:?</dt>\s*<dd>([\d,\.]+)</dd>',
  85. webpage, 'view count', fatal=False))
  86. comment_count = str_to_int(self._html_search_regex(
  87. r'>Comments? \(([\d,\.]+)\)<',
  88. webpage, 'comment count', fatal=False))
  89. return {
  90. 'id': video_id,
  91. 'display_id': display_id,
  92. 'title': title,
  93. 'description': description,
  94. 'uploader': uploader,
  95. 'duration': duration,
  96. 'view_count': view_count,
  97. 'comment_count': comment_count,
  98. 'age_limit': 18,
  99. 'formats': formats,
  100. }
  101. class XTubeUserIE(InfoExtractor):
  102. IE_DESC = 'XTube user profile'
  103. _VALID_URL = r'https?://(?:www\.)?xtube\.com/profile/(?P<id>[^/]+-\d+)'
  104. _TEST = {
  105. 'url': 'http://www.xtube.com/profile/greenshowers-4056496',
  106. 'info_dict': {
  107. 'id': 'greenshowers-4056496',
  108. 'age_limit': 18,
  109. },
  110. 'playlist_mincount': 155,
  111. }
  112. def _real_extract(self, url):
  113. user_id = self._match_id(url)
  114. entries = []
  115. for pagenum in itertools.count(1):
  116. request = sanitized_Request(
  117. 'http://www.xtube.com/profile/%s/videos/%d' % (user_id, pagenum),
  118. headers={
  119. 'Cookie': 'popunder=4',
  120. 'X-Requested-With': 'XMLHttpRequest',
  121. 'Referer': url,
  122. })
  123. page = self._download_json(
  124. request, user_id, 'Downloading videos JSON page %d' % pagenum)
  125. html = page.get('html')
  126. if not html:
  127. break
  128. for video_id in orderedSet([video_id for _, video_id in re.findall(
  129. r'data-plid=(["\'])(.+?)\1', html)]):
  130. entries.append(self.url_result('xtube:%s' % video_id, XTubeIE.ie_key()))
  131. page_count = int_or_none(page.get('pageCount'))
  132. if not page_count or pagenum == page_count:
  133. break
  134. playlist = self.playlist_result(entries, user_id)
  135. playlist['age_limit'] = 18
  136. return playlist