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.

177 lines
5.8 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. js_to_json,
  8. orderedSet,
  9. parse_duration,
  10. sanitized_Request,
  11. str_to_int,
  12. )
  13. class XTubeIE(InfoExtractor):
  14. _VALID_URL = r'''(?x)
  15. (?:
  16. xtube:|
  17. https?://(?:www\.)?xtube\.com/(?:watch\.php\?.*\bv=|video-watch/(?P<display_id>[^/]+)-)
  18. )
  19. (?P<id>[^/?&#]+)
  20. '''
  21. _TESTS = [{
  22. # old URL schema
  23. 'url': 'http://www.xtube.com/watch.php?v=kVTUy_G222_',
  24. 'md5': '092fbdd3cbe292c920ef6fc6a8a9cdab',
  25. 'info_dict': {
  26. 'id': 'kVTUy_G222_',
  27. 'ext': 'mp4',
  28. 'title': 'strange erotica',
  29. 'description': 'contains:an ET kind of thing',
  30. 'uploader': 'greenshowers',
  31. 'duration': 450,
  32. 'view_count': int,
  33. 'comment_count': int,
  34. 'age_limit': 18,
  35. }
  36. }, {
  37. # FLV videos with duplicated formats
  38. 'url': 'http://www.xtube.com/video-watch/A-Super-Run-Part-1-YT-9299752',
  39. 'md5': 'a406963eb349dd43692ec54631efd88b',
  40. 'info_dict': {
  41. 'id': '9299752',
  42. 'display_id': 'A-Super-Run-Part-1-YT',
  43. 'ext': 'flv',
  44. 'title': 'A Super Run - Part 1 (YT)',
  45. 'description': 'md5:ca0d47afff4a9b2942e4b41aa970fd93',
  46. 'uploader': 'tshirtguy59',
  47. 'duration': 579,
  48. 'view_count': int,
  49. 'comment_count': int,
  50. 'age_limit': 18,
  51. },
  52. }, {
  53. # new URL schema
  54. 'url': 'http://www.xtube.com/video-watch/strange-erotica-625837',
  55. 'only_matching': True,
  56. }, {
  57. 'url': 'xtube:625837',
  58. 'only_matching': True,
  59. }, {
  60. 'url': 'xtube:kVTUy_G222_',
  61. 'only_matching': True,
  62. }]
  63. def _real_extract(self, url):
  64. mobj = re.match(self._VALID_URL, url)
  65. video_id = mobj.group('id')
  66. display_id = mobj.group('display_id')
  67. if not display_id:
  68. display_id = video_id
  69. if video_id.isdigit() and len(video_id) < 11:
  70. url_pattern = 'http://www.xtube.com/video-watch/-%s'
  71. else:
  72. url_pattern = 'http://www.xtube.com/watch.php?v=%s'
  73. webpage = self._download_webpage(
  74. url_pattern % video_id, display_id, headers={
  75. 'Cookie': 'age_verified=1; cookiesAccepted=1',
  76. })
  77. sources = self._parse_json(self._search_regex(
  78. r'(["\'])?sources\1?\s*:\s*(?P<sources>{.+?}),',
  79. webpage, 'sources', group='sources'), video_id,
  80. transform_source=js_to_json)
  81. formats = []
  82. for format_id, format_url in sources.items():
  83. formats.append({
  84. 'url': format_url,
  85. 'format_id': format_id,
  86. 'height': int_or_none(format_id),
  87. })
  88. self._remove_duplicate_formats(formats)
  89. self._sort_formats(formats)
  90. title = self._search_regex(
  91. (r'<h1>\s*(?P<title>[^<]+?)\s*</h1>', r'videoTitle\s*:\s*(["\'])(?P<title>.+?)\1'),
  92. webpage, 'title', group='title')
  93. description = self._search_regex(
  94. r'</h1>\s*<p>([^<]+)', webpage, 'description', fatal=False)
  95. uploader = self._search_regex(
  96. (r'<input[^>]+name="contentOwnerId"[^>]+value="([^"]+)"',
  97. r'<span[^>]+class="nickname"[^>]*>([^<]+)'),
  98. webpage, 'uploader', fatal=False)
  99. duration = parse_duration(self._search_regex(
  100. r'<dt>Runtime:?</dt>\s*<dd>([^<]+)</dd>',
  101. webpage, 'duration', fatal=False))
  102. view_count = str_to_int(self._search_regex(
  103. r'<dt>Views:?</dt>\s*<dd>([\d,\.]+)</dd>',
  104. webpage, 'view count', fatal=False))
  105. comment_count = str_to_int(self._html_search_regex(
  106. r'>Comments? \(([\d,\.]+)\)<',
  107. webpage, 'comment count', fatal=False))
  108. return {
  109. 'id': video_id,
  110. 'display_id': display_id,
  111. 'title': title,
  112. 'description': description,
  113. 'uploader': uploader,
  114. 'duration': duration,
  115. 'view_count': view_count,
  116. 'comment_count': comment_count,
  117. 'age_limit': 18,
  118. 'formats': formats,
  119. }
  120. class XTubeUserIE(InfoExtractor):
  121. IE_DESC = 'XTube user profile'
  122. _VALID_URL = r'https?://(?:www\.)?xtube\.com/profile/(?P<id>[^/]+-\d+)'
  123. _TEST = {
  124. 'url': 'http://www.xtube.com/profile/greenshowers-4056496',
  125. 'info_dict': {
  126. 'id': 'greenshowers-4056496',
  127. 'age_limit': 18,
  128. },
  129. 'playlist_mincount': 155,
  130. }
  131. def _real_extract(self, url):
  132. user_id = self._match_id(url)
  133. entries = []
  134. for pagenum in itertools.count(1):
  135. request = sanitized_Request(
  136. 'http://www.xtube.com/profile/%s/videos/%d' % (user_id, pagenum),
  137. headers={
  138. 'Cookie': 'popunder=4',
  139. 'X-Requested-With': 'XMLHttpRequest',
  140. 'Referer': url,
  141. })
  142. page = self._download_json(
  143. request, user_id, 'Downloading videos JSON page %d' % pagenum)
  144. html = page.get('html')
  145. if not html:
  146. break
  147. for video_id in orderedSet([video_id for _, video_id in re.findall(
  148. r'data-plid=(["\'])(.+?)\1', html)]):
  149. entries.append(self.url_result('xtube:%s' % video_id, XTubeIE.ie_key()))
  150. page_count = int_or_none(page.get('pageCount'))
  151. if not page_count or pagenum == page_count:
  152. break
  153. playlist = self.playlist_result(entries, user_id)
  154. playlist['age_limit'] = 18
  155. return playlist