xvideos.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import re
  2. from .common import InfoExtractor
  3. from ..compat import compat_urllib_parse_unquote
  4. from ..utils import (
  5. clean_html,
  6. determine_ext,
  7. ExtractorError,
  8. int_or_none,
  9. parse_duration,
  10. )
  11. class XVideosIE(InfoExtractor):
  12. _VALID_URL = r'''(?x)
  13. https?://
  14. (?:
  15. (?:[^/]+\.)?xvideos2?\.com/video|
  16. (?:www\.)?xvideos\.es/video|
  17. (?:www|flashservice)\.xvideos\.com/embedframe/|
  18. static-hw\.xvideos\.com/swf/xv-player\.swf\?.*?\bid_video=
  19. )
  20. (?P<id>[0-9]+)
  21. '''
  22. _TESTS = [{
  23. 'url': 'https://www.xvideos.com/video4588838/motorcycle_guy_cucks_influencer_steals_his_gf',
  24. 'md5': '14cea69fcb84db54293b1e971466c2e1',
  25. 'info_dict': {
  26. 'id': '4588838',
  27. 'ext': 'mp4',
  28. 'title': 'Motorcycle Guy Cucks Influencer, Steals his GF',
  29. 'duration': 108,
  30. 'age_limit': 18,
  31. 'thumbnail': r're:^https://img-hw.xvideos-cdn.com/.+\.jpg',
  32. }
  33. }, {
  34. # Broken HLS formats
  35. 'url': 'https://www.xvideos.com/video65982001/what_s_her_name',
  36. 'md5': 'b82d7d7ef7d65a84b1fa6965f81f95a5',
  37. 'info_dict': {
  38. 'id': '65982001',
  39. 'ext': 'mp4',
  40. 'title': 'what\'s her name?',
  41. 'duration': 120,
  42. 'age_limit': 18,
  43. 'thumbnail': r're:^https://img-hw.xvideos-cdn.com/.+\.jpg',
  44. }
  45. }, {
  46. 'url': 'https://flashservice.xvideos.com/embedframe/4588838',
  47. 'only_matching': True,
  48. }, {
  49. 'url': 'https://www.xvideos.com/embedframe/4588838',
  50. 'only_matching': True,
  51. }, {
  52. 'url': 'http://static-hw.xvideos.com/swf/xv-player.swf?id_video=4588838',
  53. 'only_matching': True,
  54. }, {
  55. 'url': 'http://xvideos.com/video4588838/biker_takes_his_girl',
  56. 'only_matching': True
  57. }, {
  58. 'url': 'https://xvideos.com/video4588838/biker_takes_his_girl',
  59. 'only_matching': True
  60. }, {
  61. 'url': 'https://xvideos.es/video4588838/biker_takes_his_girl',
  62. 'only_matching': True
  63. }, {
  64. 'url': 'https://www.xvideos.es/video4588838/biker_takes_his_girl',
  65. 'only_matching': True
  66. }, {
  67. 'url': 'http://xvideos.es/video4588838/biker_takes_his_girl',
  68. 'only_matching': True
  69. }, {
  70. 'url': 'http://www.xvideos.es/video4588838/biker_takes_his_girl',
  71. 'only_matching': True
  72. }, {
  73. 'url': 'http://fr.xvideos.com/video4588838/biker_takes_his_girl',
  74. 'only_matching': True
  75. }, {
  76. 'url': 'https://fr.xvideos.com/video4588838/biker_takes_his_girl',
  77. 'only_matching': True
  78. }, {
  79. 'url': 'http://it.xvideos.com/video4588838/biker_takes_his_girl',
  80. 'only_matching': True
  81. }, {
  82. 'url': 'https://it.xvideos.com/video4588838/biker_takes_his_girl',
  83. 'only_matching': True
  84. }, {
  85. 'url': 'http://de.xvideos.com/video4588838/biker_takes_his_girl',
  86. 'only_matching': True
  87. }, {
  88. 'url': 'https://de.xvideos.com/video4588838/biker_takes_his_girl',
  89. 'only_matching': True
  90. }]
  91. def _real_extract(self, url):
  92. video_id = self._match_id(url)
  93. webpage = self._download_webpage(url, video_id)
  94. mobj = re.search(r'<h1 class="inlineError">(.+?)</h1>', webpage)
  95. if mobj:
  96. raise ExtractorError('%s said: %s' % (self.IE_NAME, clean_html(mobj.group(1))), expected=True)
  97. title = self._html_search_regex(
  98. (r'<title>(?P<title>.+?)\s+-\s+XVID',
  99. r'setVideoTitle\s*\(\s*(["\'])(?P<title>(?:(?!\1).)+)\1'),
  100. webpage, 'title', default=None,
  101. group='title') or self._og_search_title(webpage)
  102. thumbnails = []
  103. for preference, thumbnail in enumerate(('', '169')):
  104. thumbnail_url = self._search_regex(
  105. r'setThumbUrl%s\(\s*(["\'])(?P<thumbnail>(?:(?!\1).)+)\1' % thumbnail,
  106. webpage, 'thumbnail', default=None, group='thumbnail')
  107. if thumbnail_url:
  108. thumbnails.append({
  109. 'url': thumbnail_url,
  110. 'preference': preference,
  111. })
  112. duration = int_or_none(self._og_search_property(
  113. 'duration', webpage, default=None)) or parse_duration(
  114. self._search_regex(
  115. r'<span[^>]+class=["\']duration["\'][^>]*>.*?(\d[^<]+)',
  116. webpage, 'duration', fatal=False))
  117. formats = []
  118. video_url = compat_urllib_parse_unquote(self._search_regex(
  119. r'flv_url=(.+?)&', webpage, 'video URL', default=''))
  120. if video_url:
  121. formats.append({
  122. 'url': video_url,
  123. 'format_id': 'flv',
  124. })
  125. for kind, _, format_url in re.findall(
  126. r'setVideo([^(]+)\((["\'])(http.+?)\2\)', webpage):
  127. format_id = kind.lower()
  128. if format_id == 'hls':
  129. hls_formats = self._extract_m3u8_formats(
  130. format_url, video_id, 'mp4',
  131. entry_protocol='m3u8_native', m3u8_id='hls', fatal=False)
  132. self._check_formats(hls_formats, video_id)
  133. formats.extend(hls_formats)
  134. elif format_id in ('urllow', 'urlhigh'):
  135. formats.append({
  136. 'url': format_url,
  137. 'format_id': '%s-%s' % (determine_ext(format_url, 'mp4'), format_id[3:]),
  138. 'quality': -2 if format_id.endswith('low') else None,
  139. })
  140. return {
  141. 'id': video_id,
  142. 'formats': formats,
  143. 'title': title,
  144. 'duration': duration,
  145. 'thumbnails': thumbnails,
  146. 'age_limit': 18,
  147. }