File size: 6,436 Bytes
cf91b15 53203ae cf91b15 53203ae 7e297a8 98ee87c cf91b15 53203ae 7e297a8 53203ae cf91b15 53203ae 7e297a8 53203ae 7e297a8 53203ae cf91b15 53203ae 635c1e2 7e297a8 635c1e2 7e297a8 6eefec0 635c1e2 7e297a8 635c1e2 7e297a8 53203ae cf91b15 a925200 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
for (let sign of ['unhandledRejection', 'uncaughtException']) process.on(sign, console.error)
const os = require('os')
const util = require('util')
const uuid = require('uuid')
const logger = require('morgan')
const express = require('express')
const puppeteer = require('puppeteer').executablePath()
const rateLimit = require('express-rate-limit')
const { execSync } = require('child_process')
const axios = require('axios');
const cheerio = require('cheerio');
const { Eiyuu } = require('eiyuu');
const Booru = require('booru');
const search = new Eiyuu();
const app = express()
app.set('trust proxy', 1)
app.set('json spaces', 4)
app.use(logger('dev'))
app.use(express.urlencoded({ extended: true }))
const headers = {
'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'
};
async function searchBooru(query, site, counts) {
return new Promise(async (resolve, reject) => {
try {
var dan = Booru.forSite(site.toLowerCase());
var data = await dan.search(query, { limit: counts });
var result = data.map((obg) => {
return {
nsfw: obg.booru.site.nsfw,
domain: obg.booru.site.domain,
tag_copyright: obg.data.tag_string_copyright,
artist: obg.data.tag_string_artist,
pixiv_id: obg.data.pixiv_id,
source: obg.source,
HD_url: obg.fileUrl,
id: obg.id,
tags: obg.tags.join(", "),
};
});
resolve(result);
} catch (error) {
reject(error);
}
});
}
async function extractVideoUrl(url) {
try {
let res = await axios.get(url, {
headers
});
let result = res.data;
let $ = cheerio.load(result);
let liElement = $('li[data-id]'); // Pilih elemen <li> dengan atribut data-id
let dataIdValue = liElement.attr('data-id'); // Dapatkan nilai atribut data-id
let final = new URL(dataIdValue, 'https://nhplayer.com').toString();
const response = await axios.get(final);
const html = response.data;
const $2 = cheerio.load(html);
const scriptContent = $2('script:contains("file: ")').html();
const match = scriptContent.match(/file:\s*["']([^"']+)["']/);
if (match && match[1]) {
const videoUrl = match[1];
return {
url: videoUrl
};
} else {
console.log('Tidak dapat menemukan URL video.');
return null;
}
} catch (error) {
console.error('Error:', error);
return {
msg: error
}
}
}
async function findChromiumPath() {
let cmd = execSync('nix eval nixpkgs.chromium.outPath --raw').toString();
return `${cmd.trim()}/bin/chromium`;
}
async function scrapeAndFindIframeSrc(main_url) {
//const chromiumPath = await findChromiumPath();
const browser = await puppeteer.launch({
//executablePath: chromiumPath,
headless: false,
args: [
'--no-sandbox',
]
});
const page = await browser.newPage();
try {
await page.goto(main_url);
await page.click('button.btn.uppercase');
await page.waitForNavigation();
await page.waitForSelector('.aspect-video.-lg\\:-mx-2.order-first iframe');
const iframeSrc = await page.$eval('.aspect-video.-lg\\:-mx-2.order-first iframe', iframe => iframe.src);
return {
url: iframeSrc
}
} catch (error) {
return {
msg: error
}
} finally {
await browser.close();
}
}
async function hentaitv(url) {
try {
var data = await scrapeAndFindIframeSrc(url)
var result = await extractVideoUrl(data.url)
return {
file_url: result.url
}
} catch (error) {
return {
msg: error
}
}
}
// Fungsi untuk mendapatkan tags
async function getTags(query, site) {
const siteLower = site.toLowerCase();
if (siteLower === "danbooru") {
let anu = await search.danbooru(query);
return { tag: query, all_tags: anu };
} else if (siteLower === "safebooru") {
let anu = await search.safebooru(query);
return { tag: query, all_tags: anu };
} else if (siteLower === "hypnohub") {
let anu = await search.hypnohub(query);
return { tag: query, all_tags: anu };
} else if (siteLower === "yandere") {
let anu = await search.yandere(query);
return { tag: query, all_tags: anu };
} else if (siteLower === "konachan") {
let anu = await search.konachan(query);
return { tag: query, all_tags: anu };
} else if (siteLower === "gelbooru") {
let anu = await search.gelbooru(query);
return { tag: query, all_tags: anu };
}
}
app.all('/', (req, res) => {
const obj = {}
const used = process.memoryUsage()
for (let key in used) obj[key] = `${Math.round(used[key] / 1000 / 1000 * 100) / 100} MB`
const disk = execSync('du -sh').toString().split('M')[0]
obj.diskUsage = `${disk} MB`
const totalmem = os.totalmem()
const freemem = os.freemem()
obj.memoryUsage =
`${((totalmem - freemem) / Math.pow(1024, 3)).toFixed(1)} GB / ${(totalmem / Math.pow(1024, 3)).toFixed(1)} GB`
res.json({
success: true,
message: 'Hello World',
uptime: new Date(process.uptime() * 1000).toUTCString().split(' ')[4],
status: obj
})
})
app.get('/ip', (req, res) => res.send(req.ip))
app.get('/htv', async (req, res) => {
try {
const { url } = req.query;
if (!url) {
return res.json({ success: false, message: 'Input parameter url' });
}
let datas = await hentaitv(url)
res.json({ success: true, result : datas });
} catch (error) {
console.error('Error:', error);
res.json({ success: false, message: 'An error occurred ' + error });
}
});
app.get('/ping', (req, res) => {
res.send('Pong');
});
app.get('/gettags', async (req, res) => {
const { query, site } = req.query;
try {
const tags = await getTags(query, site);
res.json(tags);
} catch (error) {
console.error('Terjadi kesalahan:', error.message);
res.status(500).json({ error: 'Terjadi kesalahan', msg: error.message});
}
});
app.get('/booru', async (req, res) => {
const { query, site, counts } = req.query;
try {
const tags = await searchBooru(query, site, counts);
res.json(tags);
} catch (error) {
console.error('Terjadi kesalahan:', error.message);
res.status(500).json({ error: 'Terjadi kesalahan', msg: error.message});
}
});
const PORT = process.env.PORT || 7860
app.listen(PORT, () => console.log('App running on port', PORT))
setInterval(() => {
axios.head('https://nultx-hent-ai.hf.space/ping')
.catch(error => {
console.log('Error:', error);
});
}, 30 * 1000); |