R-Kentaren commited on
Commit
73f1cb7
·
verified ·
1 Parent(s): 684a698

Create xvideos.js

Browse files
Files changed (1) hide show
  1. nsfw/xvideos.js +129 -0
nsfw/xvideos.js ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const { fetch } = require('undici');
2
+
3
+ const cheerio = require('cheerio');
4
+
5
+
6
+
7
+ class Xvideos {
8
+
9
+ search = async function (q) {
10
+
11
+ try {
12
+
13
+ const page = Math.floor(3 * Math.random()) + 1;
14
+
15
+ const resp = await fetch(`https://www.xvideos.com/?k=${q}&p=${page}`)
16
+
17
+ const $ = cheerio.load(await resp.text())
18
+
19
+
20
+
21
+ const res = []
22
+
23
+ $('div[id*="video"]').each((_, bkp) => {
24
+
25
+ const title = $(bkp).find('.thumb-under p.title a').contents().not('span').text().trim()
26
+
27
+ const resolution = $(bkp).find('.thumb-inside .thumb span').text().trim()
28
+
29
+ const duration = $(bkp).find('.thumb-under p.metadata span.duration').text().trim()
30
+
31
+ const artist = $(bkp).find('.thumb-under p.metadata a span.name').text().trim()
32
+
33
+ const cover = $(bkp).find('.thumb-inside .thumb img').attr('data-src')
34
+
35
+ const url = $(bkp).find('.thumb-inside .thumb a').attr('href')
36
+
37
+
38
+
39
+ res.push({
40
+
41
+ title,
42
+
43
+ resolution,
44
+
45
+ duration,
46
+
47
+ artist,
48
+
49
+ cover,
50
+
51
+ url: 'https://www.xvideos.com' + url
52
+
53
+ })
54
+
55
+ })
56
+
57
+
58
+
59
+ return res
60
+
61
+ } catch (error) {
62
+
63
+ throw new Error(error.message);
64
+
65
+ }
66
+
67
+ }
68
+
69
+
70
+
71
+ download = async function (url) {
72
+
73
+ try {
74
+
75
+ const resp = await fetch(url);
76
+
77
+ const $ = cheerio.load(await resp.text());
78
+
79
+
80
+
81
+ const scriptContent = $('#video-player-bg > script:nth-child(6)').html();
82
+
83
+ const extractData = (regex) => (scriptContent.match(regex) || [])[1];
84
+
85
+
86
+
87
+ const videos = {
88
+
89
+ low: extractData(/html5player\.setVideoUrlLow\('(.*?)'\);/),
90
+
91
+ high: extractData(/html5player\.setVideoUrlHigh\('(.*?)'\);/),
92
+
93
+ HLS: extractData(/html5player\.setVideoHLS\('(.*?)'\);/)
94
+
95
+ }
96
+
97
+
98
+
99
+ const thumb = extractData(/html5player\.setThumbUrl\('(.*?)'\);/)
100
+
101
+
102
+
103
+ return {
104
+
105
+ videos,
106
+
107
+ thumb
108
+
109
+ };
110
+
111
+ } catch (error) {
112
+
113
+ throw new Error(error.message);
114
+
115
+ }
116
+
117
+ }
118
+
119
+ }
120
+
121
+
122
+
123
+ // Usage:
124
+
125
+ const xvid = new Xvideos();
126
+
127
+ const resp = await xvid.search('girl');
128
+
129
+ console.log(resp);