Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * HD Media (Image & Video)
- * Author : gienetic
- * Base : imgupscaler.ai / unblurimage.ai
- */
- const axios = require("axios");
- const FormData = require("form-data");
- const fs = require("fs");
- const { v4: uuidv4 } = require("uuid");
- /**
- * Upscale Image menggunakan imgupscaler.ai (serial random tiap request)
- * @param {string} imagePath - path ke file image
- * @param {string} authorization - optional, default kosong
- * @returns {Promise<string>} - URL hasil upscale
- */
- async function imageHD(imagePath, authorization = "") {
- const serial = uuidv4();
- const form = new FormData();
- form.append("original_image_file", fs.createReadStream(imagePath));
- const uploadRes = await axios.post(
- "https://api.imgupscaler.ai/api/image-upscaler/v2/upscale/create-job",
- form,
- {
- headers: {
- ...form.getHeaders(),
- "Host": "api.imgupscaler.ai",
- "sec-ch-ua-platform": "\"Android\"",
- "authorization": authorization,
- "product-serial": serial,
- "user-agent": "Mozilla/5.0 (SymbianOS/9.4; Series60/5.0 NokiaN97-1/20.0.019; Profile/MIDP-2.1 Configuration/CLDC-1.1) AppleWebKit/525 (KHTML, like Gecko) BrowserNG/7.1.18124",
- "sec-ch-ua": "\"Chromium\";v=\"140\", \"Not=A?Brand\";v=\"24\", \"Android WebView\";v=\"140\"",
- "sec-ch-ua-mobile": "?1",
- "accept": "*/*",
- "origin": "https://imgupscaler.ai",
- "x-requested-with": "com.chromasterZ.vn",
- "sec-fetch-site": "same-site",
- "sec-fetch-mode": "cors",
- "sec-fetch-dest": "empty",
- "referer": "https://imgupscaler.ai/",
- "accept-encoding": "gzip, deflate",
- "accept-language": "id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7",
- "priority": "u=1, i"
- },
- maxBodyLength: Infinity
- }
- );
- const jobId = uploadRes.data.result?.job_id;
- if (!jobId) throw new Error("Gagal membuat job image HD");
- // Polling status job
- while (true) {
- const statusRes = await axios.get(
- `https://api.imgupscaler.ai/api/image-upscaler/v1/universal_upscale/get-job/${jobId}`,
- {
- headers: {
- "Host": "api.imgupscaler.ai",
- "sec-ch-ua-platform": "\"Android\"",
- "authorization": authorization,
- "product-serial": serial,
- "user-agent": "Mozilla/5.0 (SymbianOS/9.4; Series60/5.0 NokiaN97-1/20.0.019; Profile/MIDP-2.1 Configuration/CLDC-1.1) AppleWebKit/525 (KHTML, like Gecko) BrowserNG/7.1.18124",
- "sec-ch-ua": "\"Chromium\";v=\"140\", \"Not=A?Brand\";v=\"24\", \"Android WebView\";v=\"140\"",
- "sec-ch-ua-mobile": "?1",
- "accept": "*/*",
- "origin": "https://imgupscaler.ai",
- "x-requested-with": "com.chromasterZ.vn",
- "sec-fetch-site": "same-site",
- "sec-fetch-mode": "cors",
- "sec-fetch-dest": "empty",
- "referer": "https://imgupscaler.ai/",
- "accept-encoding": "gzip, deflate",
- "accept-language": "id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7",
- "priority": "u=1, i"
- }
- }
- );
- const result = statusRes.data.result;
- if (result && result.output_url?.length) return result.output_url[0];
- await new Promise(r => setTimeout(r, 3000));
- }
- }
- /**
- * Upscale Video menggunakan unblurimage.ai (tidak perlu serial)
- * @param {string} filePath - path ke file video
- * @param {string} authorization - optional
- * @returns {Promise<string>} - URL hasil upscale
- */
- async function videoHD(filePath, authorization = "") {
- const fileName = filePath.split("/").pop();
- const formSlot = new FormData();
- formSlot.append("video_file_name", fileName);
- const slotRes = await axios.post(
- "https://api.unblurimage.ai/api/upscaler/v1/ai-video-enhancer/upload-video",
- formSlot,
- {
- headers: {
- ...formSlot.getHeaders(),
- "origin": "https://imgupscaler.ai",
- "user-agent": "Gienetic/1.2.0 Mobile",
- "accept": "*/*",
- },
- }
- );
- const slot = slotRes.data.result;
- const stats = fs.statSync(filePath);
- const stream = fs.createReadStream(filePath);
- await axios.put(slot.url, stream, {
- headers: {
- "Content-Type": "video/mp4",
- "Content-Length": stats.size,
- },
- maxBodyLength: Infinity,
- maxContentLength: Infinity,
- });
- const videoUrl = `https://cdn.unwatermark.ai/${slot.object_name}`;
- const formJob = new FormData();
- formJob.append("original_video_file", videoUrl);
- formJob.append("is_preview", "false");
- const jobRes = await axios.post(
- "https://api.unblurimage.ai/api/upscaler/v2/ai-video-enhancer/create-job",
- formJob,
- {
- headers: {
- ...formJob.getHeaders(),
- "origin": "https://imgupscaler.ai",
- "user-agent": "Gienetic/1.2.0 Mobile",
- "accept": "*/*",
- "authorization": authorization,
- },
- }
- );
- const jobId = jobRes.data.result?.job_id;
- if (!jobId) throw new Error("Gagal membuat job video HD");
- // Polling status job
- while (true) {
- const statusRes = await axios.get(
- `https://api.unblurimage.ai/api/upscaler/v2/ai-video-enhancer/get-job/${jobId}`,
- {
- headers: {
- "origin": "https://imgupscaler.ai",
- "user-agent": "Gienetic/1.2.0 Mobile",
- "accept": "*/*",
- },
- }
- );
- const result = statusRes.data.result;
- if (result && result.output_url) return result.output_url;
- await new Promise(r => setTimeout(r, 5000));
- }
- }
- module.exports = { imageHD, videoHD };
Advertisement
Add Comment
Please, Sign In to add comment