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.

149 lines
4.9 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. def _real_extract(self, url):
  44. mobj = re.match(self._VALID_URL, url)
  45. video_id = mobj.group('id')
  46. display_id = mobj.group('display_id')
  47. if not display_id:
  48. display_id = video_id
  49. url = 'http://www.xtube.com/watch.php?v=%s' % video_id
  50. req = sanitized_Request(url)
  51. req.add_header('Cookie', 'age_verified=1; cookiesAccepted=1')
  52. webpage = self._download_webpage(req, display_id)
  53. sources = self._parse_json(self._search_regex(
  54. r'sources\s*:\s*({.+?}),', webpage, 'sources'), video_id)
  55. formats = []
  56. for format_id, format_url in sources.items():
  57. formats.append({
  58. 'url': format_url,
  59. 'format_id': format_id,
  60. 'height': int_or_none(format_id),
  61. })
  62. self._sort_formats(formats)
  63. title = self._search_regex(
  64. (r'<h1>(?P<title>[^<]+)</h1>', r'videoTitle\s*:\s*(["\'])(?P<title>.+?)\1'),
  65. webpage, 'title', group='title')
  66. description = self._search_regex(
  67. r'</h1>\s*<p>([^<]+)', webpage, 'description', fatal=False)
  68. uploader = self._search_regex(
  69. (r'<input[^>]+name="contentOwnerId"[^>]+value="([^"]+)"',
  70. r'<span[^>]+class="nickname"[^>]*>([^<]+)'),
  71. webpage, 'uploader', fatal=False)
  72. duration = parse_duration(self._search_regex(
  73. r'<dt>Runtime:</dt>\s*<dd>([^<]+)</dd>',
  74. webpage, 'duration', fatal=False))
  75. view_count = str_to_int(self._search_regex(
  76. r'<dt>Views:</dt>\s*<dd>([\d,\.]+)</dd>',
  77. webpage, 'view count', fatal=False))
  78. comment_count = str_to_int(self._html_search_regex(
  79. r'>Comments? \(([\d,\.]+)\)<',
  80. webpage, 'comment count', fatal=False))
  81. return {
  82. 'id': video_id,
  83. 'display_id': display_id,
  84. 'title': title,
  85. 'description': description,
  86. 'uploader': uploader,
  87. 'duration': duration,
  88. 'view_count': view_count,
  89. 'comment_count': comment_count,
  90. 'age_limit': 18,
  91. 'formats': formats,
  92. }
  93. class XTubeUserIE(InfoExtractor):
  94. IE_DESC = 'XTube user profile'
  95. _VALID_URL = r'https?://(?:www\.)?xtube\.com/profile/(?P<id>[^/]+-\d+)'
  96. _TEST = {
  97. 'url': 'http://www.xtube.com/profile/greenshowers-4056496',
  98. 'info_dict': {
  99. 'id': 'greenshowers-4056496',
  100. 'age_limit': 18,
  101. },
  102. 'playlist_mincount': 155,
  103. }
  104. def _real_extract(self, url):
  105. user_id = self._match_id(url)
  106. entries = []
  107. for pagenum in itertools.count(1):
  108. request = sanitized_Request(
  109. 'http://www.xtube.com/profile/%s/videos/%d' % (user_id, pagenum),
  110. headers={
  111. 'Cookie': 'popunder=4',
  112. 'X-Requested-With': 'XMLHttpRequest',
  113. 'Referer': url,
  114. })
  115. page = self._download_json(
  116. request, user_id, 'Downloading videos JSON page %d' % pagenum)
  117. html = page.get('html')
  118. if not html:
  119. break
  120. for video_id in orderedSet([video_id for _, video_id in re.findall(
  121. r'data-plid=(["\'])(.+?)\1', html)]):
  122. entries.append(self.url_result('xtube:%s' % video_id, XTubeIE.ie_key()))
  123. page_count = int_or_none(page.get('pageCount'))
  124. if not page_count or pagenum == page_count:
  125. break
  126. playlist = self.playlist_result(entries, user_id)
  127. playlist['age_limit'] = 18
  128. return playlist