Ayogiakbar

Text To Video & Text To Image

Aug 19th, 2025 (edited)
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Aritek API Wrapper
  3.  * Feature : Text To Video & Text To Image
  4.  * Author  : gienetic
  5.  * Base    : https://play.google.com/store/apps/details?id=ai.video.generator.text.video
  6.  */
  7.  
  8. const axios = require("axios")
  9. const { randomUUID } = require("crypto")
  10.  
  11. const AUTH_TOKEN = "eyJzdWIiwsdeOiIyMzQyZmczNHJ0MzR0weMzQiLCJuYW1lIjorwiSm9objMdf0NTM0NT"
  12. const SIGN_TOKEN = "e5fce0f8136217ad645df2a0cb1f1188dd2fbab8"
  13. const API_BASE = "https://t2v2.aritek.app"
  14.  
  15. function getRandomDeviceID() {
  16.   return randomUUID().replace(/-/g, "").slice(0, 16)
  17. }
  18.  
  19. async function translateToEnglish(text) {
  20.   try {
  21.     const url = "https://translate.googleapis.com/translate_a/single"
  22.     const params = { client: "gtx", sl: "auto", tl: "en", dt: "t", q: text }
  23.     const res = await axios.get(url, { params })
  24.     return res.data[0][0][0]
  25.   } catch {
  26.     return text
  27.   }
  28. }
  29.  
  30. async function generateVideo(prompt) {
  31.   const translatedPrompt = await translateToEnglish(prompt)
  32.   try {
  33.     let key = null
  34.     while (!key) {
  35.       try {
  36.         const submit = await axios.post(
  37.           `${API_BASE}/videos`,
  38.           {
  39.             deviceID: getRandomDeviceID(),
  40.             isPremium: 1,
  41.             prompt: translatedPrompt,
  42.             used: [],
  43.             versionCode: 6
  44.           },
  45.           {
  46.             headers: {
  47.               authorization: AUTH_TOKEN,
  48.               "content-type": "application/json; charset=utf-8",
  49.               "accept-encoding": "gzip",
  50.               "user-agent": "okhttp/5.1.0"
  51.             },
  52.             decompress: true
  53.           }
  54.         )
  55.         if (submit.data?.key) {
  56.           key = submit.data.key
  57.           console.log("✅ Video job submitted. Key:", key)
  58.         } else {
  59.           console.log("⚠️ Server busy, retrying in 5s...")
  60.           await new Promise(r => setTimeout(r, 5000))
  61.         }
  62.       } catch (err) {
  63.         if (err.response?.data?.error?.includes("No available slot")) {
  64.           console.log("⚠️ No slot available, retrying in 5s...")
  65.           await new Promise(r => setTimeout(r, 5000))
  66.         } else {
  67.           throw err
  68.         }
  69.       }
  70.     }
  71.     while (true) {
  72.       const res = await axios.post(
  73.         `${API_BASE}/videos/batch`,
  74.         { keys: [key] },
  75.         {
  76.           headers: {
  77.             authorization: AUTH_TOKEN,
  78.             "content-type": "application/json; charset=utf-8",
  79.             "accept-encoding": "gzip",
  80.             "user-agent": "okhttp/5.1.0"
  81.           },
  82.           decompress: true
  83.         }
  84.       )
  85.       const result = res.data?.datas?.[0]
  86.       if (result?.url) {
  87.         console.log("🎬 Video ready:", result.url)
  88.         return {
  89.           url: result.url,
  90.           video_id: result.id || key,
  91.           ...result
  92.         }
  93.       }
  94.       console.log("⏳ Belum siap, tunggu 5 detik...")
  95.       await new Promise(r => setTimeout(r, 5000))
  96.     }
  97.   } catch (err) {
  98.     console.error("❌ Video request failed:", err.response?.data || err.message)
  99.     throw err
  100.   }
  101. }
  102.  
  103. async function generateImage(prompt) {
  104.   try {
  105.     const res = await axios.post(
  106.       `${API_BASE}/images`,
  107.       {
  108.         ctry_target: "others",
  109.         prompt
  110.       },
  111.       {
  112.         headers: {
  113.           authorization: AUTH_TOKEN,
  114.           sign: SIGN_TOKEN,
  115.           pt: "",
  116.           "content-type": "application/json; charset=UTF-8",
  117.           "accept-encoding": "gzip",
  118.           "user-agent": "okhttp/5.1.0"
  119.         },
  120.         decompress: true
  121.       }
  122.     )
  123.     if (res.data?.code === 0 && res.data?.data) {
  124.       console.log("🖼️ Image ready:", res.data.data)
  125.       return { url: res.data.data }
  126.     } else {
  127.       throw new Error("Image generation failed (no URL returned)")
  128.     }
  129.   } catch (err) {
  130.     console.error("❌ Image request failed:", err.response?.data || err.message)
  131.     throw err
  132.   }
  133. }
  134.  
  135. module.exports = { generateVideo, generateImage }
  136.  
Advertisement
Add Comment
Please, Sign In to add comment