Update src/index.js
Browse files- src/index.js +117 -66
src/index.js
CHANGED
@@ -5,28 +5,112 @@ const util = require('util')
|
|
5 |
const uuid = require('uuid')
|
6 |
const logger = require('morgan')
|
7 |
const express = require('express')
|
8 |
-
const puppeteer = require('puppeteer')
|
9 |
const rateLimit = require('express-rate-limit')
|
10 |
-
const CharacterAI = require('node_characterai')
|
11 |
const { execSync } = require('child_process')
|
|
|
|
|
12 |
|
13 |
-
const sessions = new Map()
|
14 |
|
15 |
const app = express()
|
16 |
app.set('trust proxy', 1)
|
17 |
app.set('json spaces', 4)
|
18 |
app.use(logger('dev'))
|
19 |
app.use(express.urlencoded({ extended: true }))
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
}
|
27 |
}
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
app.all('/', (req, res) => {
|
32 |
const obj = {}
|
@@ -51,62 +135,29 @@ app.all('/', (req, res) => {
|
|
51 |
|
52 |
app.get('/ip', (req, res) => res.send(req.ip))
|
53 |
|
54 |
-
app.get('/sessions', (_, res) => res.send(eval(Array.from(sessions))))
|
55 |
|
56 |
-
app.
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
message: 'sessionId will be deleted in 10 minutes if not used',
|
76 |
-
result: { ...response, urlAvatar, sessionId }
|
77 |
-
})
|
78 |
-
return
|
79 |
-
}
|
80 |
-
|
81 |
-
const id = uuid.v4()
|
82 |
-
const characterAI = new CharacterAI()
|
83 |
-
characterAI.requester.puppeteerPath = puppeteer.executablePath()
|
84 |
-
await characterAI.authenticateAsGuest()
|
85 |
-
sessions.set(id, Object.assign(characterAI, { lastFetch: Date.now() }))
|
86 |
-
|
87 |
-
const chat = await characterAI.createOrContinueChat(characterId)
|
88 |
-
const response = await chat.sendAndAwaitResponse(text, true)
|
89 |
-
const urlAvatar = `https://characterai.io/i/80/static/avatars/${response.srcAvatarFileName}`
|
90 |
-
|
91 |
-
delete response.chat
|
92 |
-
res.json({
|
93 |
-
success: true,
|
94 |
-
message: 'sessionId will be deleted in 10 minutes if not used',
|
95 |
-
result: { ...response, urlAvatar, sessionId: id }
|
96 |
-
})
|
97 |
-
} catch (e) {
|
98 |
-
console.log(e)
|
99 |
-
e = String(e)
|
100 |
-
res.json({
|
101 |
-
error: true,
|
102 |
-
message: e === '[object Object]' ? 'Internal Server Error' : e
|
103 |
-
})
|
104 |
-
}
|
105 |
-
})
|
106 |
|
107 |
const PORT = process.env.PORT || 7860
|
108 |
app.listen(PORT, () => console.log('App running on port', PORT))
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
setInterval(() => fetch(`https://c-ai.team-skizo.repl.co`, { method: 'head' }).catch(console.log), 20 * 1000)
|
|
|
5 |
const uuid = require('uuid')
|
6 |
const logger = require('morgan')
|
7 |
const express = require('express')
|
8 |
+
const puppeteer = require('puppeteer').executablePath()
|
9 |
const rateLimit = require('express-rate-limit')
|
|
|
10 |
const { execSync } = require('child_process')
|
11 |
+
const axios = require('axios');
|
12 |
+
const cheerio = require('cheerio');
|
13 |
|
|
|
14 |
|
15 |
const app = express()
|
16 |
app.set('trust proxy', 1)
|
17 |
app.set('json spaces', 4)
|
18 |
app.use(logger('dev'))
|
19 |
app.use(express.urlencoded({ extended: true }))
|
20 |
+
|
21 |
+
const headers = {
|
22 |
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36'
|
23 |
+
};
|
24 |
+
|
25 |
+
async function extractVideoUrl(url) {
|
26 |
+
try {
|
27 |
+
let res = await axios.get(url, {
|
28 |
+
headers
|
29 |
+
});
|
30 |
+
let result = res.data;
|
31 |
+
let $ = cheerio.load(result);
|
32 |
+
let liElement = $('li[data-id]'); // Pilih elemen <li> dengan atribut data-id
|
33 |
+
let dataIdValue = liElement.attr('data-id'); // Dapatkan nilai atribut data-id
|
34 |
+
|
35 |
+
let final = new URL(dataIdValue, 'https://nhplayer.com').toString();
|
36 |
+
const response = await axios.get(final);
|
37 |
+
const html = response.data;
|
38 |
+
const $2 = cheerio.load(html);
|
39 |
+
|
40 |
+
const scriptContent = $2('script:contains("file: ")').html();
|
41 |
+
const match = scriptContent.match(/file:\s*["']([^"']+)["']/);
|
42 |
+
|
43 |
+
if (match && match[1]) {
|
44 |
+
const videoUrl = match[1];
|
45 |
+
return {
|
46 |
+
url: videoUrl
|
47 |
+
};
|
48 |
+
} else {
|
49 |
+
console.log('Tidak dapat menemukan URL video.');
|
50 |
+
return null;
|
51 |
+
}
|
52 |
+
} catch (error) {
|
53 |
+
console.error('Error:', error);
|
54 |
+
return {
|
55 |
+
msg: error
|
56 |
}
|
57 |
}
|
58 |
+
}
|
59 |
+
|
60 |
+
async function findChromiumPath() {
|
61 |
+
let cmd = execSync('nix eval nixpkgs.chromium.outPath --raw').toString();
|
62 |
+
return `${cmd.trim()}/bin/chromium`;
|
63 |
+
}
|
64 |
+
|
65 |
+
async function scrapeAndFindIframeSrc(main_url) {
|
66 |
+
//const chromiumPath = await findChromiumPath();
|
67 |
+
|
68 |
+
const browser = await puppeteer.launch({
|
69 |
+
//executablePath: chromiumPath,
|
70 |
+
headless: true,
|
71 |
+
args: [
|
72 |
+
'--no-sandbox',
|
73 |
+
]
|
74 |
+
});
|
75 |
+
|
76 |
+
const page = await browser.newPage();
|
77 |
+
|
78 |
+
try {
|
79 |
+
await page.goto(main_url);
|
80 |
+
await page.click('button.btn.uppercase');
|
81 |
+
await page.waitForNavigation();
|
82 |
+
await page.waitForSelector('.aspect-video.-lg\\:-mx-2.order-first iframe');
|
83 |
+
|
84 |
+
const iframeSrc = await page.$eval('.aspect-video.-lg\\:-mx-2.order-first iframe', iframe => iframe.src);
|
85 |
+
|
86 |
+
return {
|
87 |
+
url: iframeSrc
|
88 |
+
}
|
89 |
+
} catch (error) {
|
90 |
+
return {
|
91 |
+
msg: error
|
92 |
+
}
|
93 |
+
} finally {
|
94 |
+
await browser.close();
|
95 |
+
}
|
96 |
+
}
|
97 |
+
|
98 |
+
async function hentaitv(url) {
|
99 |
+
try {
|
100 |
+
var data = await scrapeAndFindIframeSrc(url)
|
101 |
+
var result = await extractVideoUrl(data.url)
|
102 |
+
return {
|
103 |
+
file_url: result.url
|
104 |
+
}
|
105 |
+
} catch (error) {
|
106 |
+
return {
|
107 |
+
msg: error
|
108 |
+
}
|
109 |
+
}
|
110 |
+
}
|
111 |
+
|
112 |
+
|
113 |
+
|
114 |
|
115 |
app.all('/', (req, res) => {
|
116 |
const obj = {}
|
|
|
135 |
|
136 |
app.get('/ip', (req, res) => res.send(req.ip))
|
137 |
|
|
|
138 |
|
139 |
+
app.get('/htv', async (req, res) => {
|
140 |
+
try {
|
141 |
+
const { url } = req.query;
|
142 |
+
if (!url) {
|
143 |
+
return res.json({ success: false, message: 'Input parameter url' });
|
144 |
+
}
|
145 |
+
let datas = await hentaitv(url)
|
146 |
+
res.json({ success: true, result : datas });
|
147 |
+
} catch (error) {
|
148 |
+
console.error('Error:', error);
|
149 |
+
res.json({ success: false, message: 'An error occurred ' + error });
|
150 |
+
}
|
151 |
+
});
|
152 |
+
|
153 |
+
app.get('/ping', (req, res) => {
|
154 |
+
res.send('Pong');
|
155 |
+
});
|
156 |
+
|
157 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
|
159 |
const PORT = process.env.PORT || 7860
|
160 |
app.listen(PORT, () => console.log('App running on port', PORT))
|
161 |
+
setInterval(() => fetch(`https://nultx-hent-ai.hf.space/ping`, { method: 'head' }).catch(console.log), 30 * 1000)
|
162 |
+
|
163 |
+
|
|