xvideos.py 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. import re
  2. import urllib.parse
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. clean_html,
  7. determine_ext,
  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-9a-z]+)
  21. '''
  22. _TESTS = [{
  23. 'url': 'http://xvideos.com/video.ucuvbkfda4e/a_beautiful_red-haired_stranger_was_refused_but_still_came_to_my_room_for_sex',
  24. 'md5': '396255a900a6bddb3e98985f0b86c3fd',
  25. 'info_dict': {
  26. 'id': 'ucuvbkfda4e',
  27. 'ext': 'mp4',
  28. 'title': 'A Beautiful Red-Haired Stranger Was Refused, But Still Came To My Room For Sex',
  29. 'duration': 1238,
  30. 'age_limit': 18,
  31. 'thumbnail': r're:^https://cdn\d+-pic.xvideos-cdn.com/.+\.jpg',
  32. },
  33. }, {
  34. # Broken HLS formats
  35. 'url': 'https://www.xvideos.com/video65982001/what_s_her_name',
  36. 'md5': '56742808292c8fa1418e4538c262c58b',
  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://cdn\d+-pic.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. 'url': 'https://flashservice.xvideos.com/embedframe/ucuvbkfda4e',
  92. 'only_matching': True,
  93. }, {
  94. 'url': 'https://www.xvideos.com/embedframe/ucuvbkfda4e',
  95. 'only_matching': True,
  96. }, {
  97. 'url': 'http://static-hw.xvideos.com/swf/xv-player.swf?id_video=ucuvbkfda4e',
  98. 'only_matching': True,
  99. }, {
  100. 'url': 'https://xvideos.es/video.ucuvbkfda4e/a_beautiful_red-haired_stranger_was_refused_but_still_came_to_my_room_for_sex',
  101. 'only_matching': True,
  102. }]
  103. def _real_extract(self, url):
  104. video_id = self._match_id(url)
  105. webpage = self._download_webpage(url, video_id)
  106. mobj = re.search(r'<h1 class="inlineError">(.+?)</h1>', webpage)
  107. if mobj:
  108. raise ExtractorError(f'{self.IE_NAME} said: {clean_html(mobj.group(1))}', expected=True)
  109. title = self._html_search_regex(
  110. (r'<title>(?P<title>.+?)\s+-\s+XVID',
  111. r'setVideoTitle\s*\(\s*(["\'])(?P<title>(?:(?!\1).)+)\1'),
  112. webpage, 'title', default=None,
  113. group='title') or self._og_search_title(webpage)
  114. thumbnails = []
  115. for preference, thumbnail in enumerate(('', '169')):
  116. thumbnail_url = self._search_regex(
  117. rf'setThumbUrl{thumbnail}\(\s*(["\'])(?P<thumbnail>(?:(?!\1).)+)\1',
  118. webpage, 'thumbnail', default=None, group='thumbnail')
  119. if thumbnail_url:
  120. thumbnails.append({
  121. 'url': thumbnail_url,
  122. 'preference': preference,
  123. })
  124. duration = int_or_none(self._og_search_property(
  125. 'duration', webpage, default=None)) or parse_duration(
  126. self._search_regex(
  127. r'<span[^>]+class=["\']duration["\'][^>]*>.*?(\d[^<]+)',
  128. webpage, 'duration', fatal=False))
  129. formats = []
  130. video_url = urllib.parse.unquote(self._search_regex(
  131. r'flv_url=(.+?)&', webpage, 'video URL', default=''))
  132. if video_url:
  133. formats.append({
  134. 'url': video_url,
  135. 'format_id': 'flv',
  136. })
  137. for kind, _, format_url in re.findall(
  138. r'setVideo([^(]+)\((["\'])(http.+?)\2\)', webpage):
  139. format_id = kind.lower()
  140. if format_id == 'hls':
  141. hls_formats = self._extract_m3u8_formats(
  142. format_url, video_id, 'mp4',
  143. entry_protocol='m3u8_native', m3u8_id='hls', fatal=False)
  144. self._check_formats(hls_formats, video_id)
  145. formats.extend(hls_formats)
  146. elif format_id in ('urllow', 'urlhigh'):
  147. formats.append({
  148. 'url': format_url,
  149. 'format_id': '{}-{}'.format(determine_ext(format_url, 'mp4'), format_id[3:]),
  150. 'quality': -2 if format_id.endswith('low') else None,
  151. })
  152. return {
  153. 'id': video_id,
  154. 'formats': formats,
  155. 'title': title,
  156. 'duration': duration,
  157. 'thumbnails': thumbnails,
  158. 'age_limit': 18,
  159. }
  160. class XVideosQuickiesIE(InfoExtractor):
  161. IE_NAME = 'xvideos:quickies'
  162. _VALID_URL = r'https?://(?P<domain>(?:[^/?#]+\.)?xvideos2?\.com)/(?:profiles/|amateur-channels/)?[^/?#]+#quickies/a/(?P<id>\w+)'
  163. _TESTS = [{
  164. 'url': 'https://www.xvideos.com/lili_love#quickies/a/ipdtikh1a4c',
  165. 'md5': 'f9e4f518ff1de14b99a400bbd0fc5ee0',
  166. 'info_dict': {
  167. 'id': 'ipdtikh1a4c',
  168. 'ext': 'mp4',
  169. 'title': 'Mexican chichóna putisima',
  170. 'age_limit': 18,
  171. 'duration': 81,
  172. 'thumbnail': r're:^https://cdn.*-pic.xvideos-cdn.com/.+\.jpg',
  173. },
  174. }, {
  175. 'url': 'https://www.xvideos.com/profiles/lili_love#quickies/a/ipphaob6fd1',
  176. 'md5': '5340938aac6b46e19ebdd1d84535862e',
  177. 'info_dict': {
  178. 'id': 'ipphaob6fd1',
  179. 'ext': 'mp4',
  180. 'title': 'Puta chichona mexicana squirting',
  181. 'age_limit': 18,
  182. 'duration': 56,
  183. 'thumbnail': r're:^https://cdn.*-pic.xvideos-cdn.com/.+\.jpg',
  184. },
  185. }, {
  186. 'url': 'https://www.xvideos.com/amateur-channels/lili_love#quickies/a/hfmffmd7661',
  187. 'md5': '92428518bbabcb4c513e55922e022491',
  188. 'info_dict': {
  189. 'id': 'hfmffmd7661',
  190. 'ext': 'mp4',
  191. 'title': 'Chichona mexican slut',
  192. 'age_limit': 18,
  193. 'duration': 9,
  194. 'thumbnail': r're:^https://cdn.*-pic.xvideos-cdn.com/.+\.jpg',
  195. },
  196. }, {
  197. 'url': 'https://www.xvideos.com/amateur-channels/wifeluna#quickies/a/47258683',
  198. 'md5': '16e322a93282667f1963915568f782c1',
  199. 'info_dict': {
  200. 'id': '47258683',
  201. 'ext': 'mp4',
  202. 'title': 'Verification video',
  203. 'age_limit': 18,
  204. 'duration': 16,
  205. 'thumbnail': r're:^https://cdn.*-pic.xvideos-cdn.com/.+\.jpg',
  206. },
  207. }]
  208. def _real_extract(self, url):
  209. domain, id_ = self._match_valid_url(url).group('domain', 'id')
  210. return self.url_result(f'https://{domain}/video{"" if id_.isdecimal() else "."}{id_}/_', XVideosIE, id_)