Showing posts with label playwright. Show all posts
Showing posts with label playwright. Show all posts

Thursday, 18 December 2025

✅ 20 PROMPT – VERSI LEBIH AMAN (FINAL)

 ✅ 20 PROMPT – VERSI LEBIH AMAN (FINAL)
simple vector illustration of a traditional Ramadan lantern (fanous), single isolated object, flat design, solid gold color, simple shapes, no gradient, no shadow, transparent background
simple vector illustration of a jug of jallab drink with dates, single isolated object, flat design, solid glass color style, simple shapes, no gradient, no shadow, transparent background
simple vector illustration of a brass incense burner (mabkhara), single isolated object, flat design, solid brass color, simple shapes, no gradient, no shadow, transparent background
simple vector illustration of a Ramadan cannon (midfa), single isolated object, flat design, solid dark metal color, simple shapes, no gradient, no shadow, transparent background
simple vector illustration of a crescent moon and star ornament, single isolated object, flat design, solid gold color, simple shapes, no gradient, no shadow, transparent background
simple vector illustration of a mosque dome with crescent, single isolated object, flat design, solid green color, simple shapes, no gradient, no shadow, transparent background
simple vector illustration of a rolled prayer rug (sajadah), single isolated object, flat design, simple textile pattern, simple shapes, no gradient, no shadow, transparent background
simple vector illustration of tasbih prayer beads, single isolated object, flat design, solid color beads, simple shapes, no gradient, no shadow, transparent background
simple vector illustration of an open Quran on wooden stand (rehal), single isolated object, flat design, solid brown wood color, simple shapes, no gradient, no shadow, transparent background
simple vector illustration of a date palm branch with dates, single isolated object, flat design, solid natural colors, simple shapes, no gradient, no shadow, transparent background
simple vector illustration of an iftar meal tray, single isolated object, flat design, solid food colors, simple shapes, no gradient, no shadow, transparent background
simple vector illustration of a zamzam water bottle, single isolated object, flat design, solid white bottle, simple shapes, no gradient, no shadow, transparent background
simple vector illustration of an Islamic geometric star ornament, single isolated object, flat design, solid blue and gold colors, simple shapes, no gradient, no shadow, transparent background
simple vector illustration of a hanging Ramadan lantern, single isolated object, flat design, solid gold metal color, simple shapes, no gradient, no shadow, transparent background
simple vector illustration of a traditional drum (bedug), single isolated object, flat design, solid brown wood color, simple shapes, no gradient, no shadow, transparent background
simple vector illustration of a mosque minaret, single isolated object, flat design, solid light stone color, simple shapes, no gradient, no shadow, transparent background
simple vector illustration of an Arabic coffee dallah pot, single isolated object, flat design, solid gold metal color, simple shapes, no gradient, no shadow, transparent background
simple vector illustration of a bowl of dates for iftar, single isolated object, flat design, solid warm brown colors, simple shapes, no gradient, no shadow, transparent background
simple vector illustration of an Islamic arch window, single isolated object, flat design, simple ornamental frame, simple shapes, no gradient, no shadow, transparent background
simple vector illustration of a Ramadan greeting badge, single isolated object, flat design, simple decorative emblem, simple shapes, no gradient, no shadow, transparent background

Wednesday, 17 December 2025

Script code firefly_autodownload_firefox_blob_final.js

 const { firefox } = require('playwright');
const fs = require('fs');
const fsp = fs.promises;
const path = require('path');

const PROMPT_FILE = 'prompts.txt';
const USER_DATA_DIR = path.join(__dirname, 'firefox-profile');
const DOWNLOAD_DIR = path.join(__dirname, 'downloads');

const IMAGES_PER_PROMPT = 1;
const MAX_WAIT = 45000; // maksimal tunggu per prompt (ms)
const POLL_INTERVAL = 1000; // cek tiap 1 detik

const savedBlobs = new Set();

(async () => {
  // === Persiapan folder ===
  if (!fs.existsSync(DOWNLOAD_DIR)) fs.mkdirSync(DOWNLOAD_DIR);

  // === Launch Firefox persistent ===
  const context = await firefox.launchPersistentContext(USER_DATA_DIR, {
    headless: false
  });

  const page = context.pages()[0] || await context.newPage();

  await page.goto('https://firefly.adobe.com/generate/image', {
    waitUntil: 'domcontentloaded'
  });

  console.log('👉 Login Adobe Firefly MANUAL');
  console.log('👉 Atur Model & Aspect Ratio');
  console.log('👉 Tekan ENTER di terminal');
  await new Promise(r => process.stdin.once('data', r));

  // === Prompt box ===
  const promptBox = page.locator('textarea[aria-label="Prompt"]');
  await promptBox.waitFor({ state: 'visible', timeout: 60000 });

  // === Load prompts ===
  const prompts = fs.readFileSync(PROMPT_FILE, 'utf-8')
    .split(/\r?\n/)
    .map(l => l.trim())
    .filter(Boolean);

  console.log(`🔥 Total prompt: ${prompts.length}`);

  // === Loop prompt ===
  for (let i = 0; i < prompts.length; i++) {
    console.log(`\n▶ Prompt ${i + 1}/${prompts.length}`);
    console.log('⏳ Generating...');

    await promptBox.fill('');
    await promptBox.fill(prompts[i]);
    await page.keyboard.press('Enter');

    // ===== POLLING MANUAL (ANTI TIMEOUT) =====
    const start = Date.now();
    let foundNewBlob = false;

    while (Date.now() - start < MAX_WAIT) {
      const blobs = await page.$$eval(
        'img[src^="blob:"]',
        imgs => imgs.map(img => img.src)
      );

      for (const blob of blobs) {
        if (!savedBlobs.has(blob)) {
          foundNewBlob = true;
          break;
        }
      }

      if (foundNewBlob) break;
      await page.waitForTimeout(POLL_INTERVAL);
    }

    if (!foundNewBlob) {
      console.log('⚠️ Tidak ditemukan blob baru, skip prompt ini');
      continue;
    }

    // ===== DOWNLOAD BLOBS TERBARU =====
    const images = page.locator('img[src^="blob:"]');
    const total = await images.count();

    let saved = 0;

    // scan dari belakang (gambar terbaru)
    for (let j = total - 1; j >= 0 && saved < IMAGES_PER_PROMPT; j--) {
      const img = images.nth(j);
      const blobUrl = await img.getAttribute('src');
      if (!blobUrl || savedBlobs.has(blobUrl)) continue;

      const buffer = await page.evaluate(async (url) => {
        const res = await fetch(url);
        const blob = await res.blob();
        return new Uint8Array(await blob.arrayBuffer());
      }, blobUrl);

      savedBlobs.add(blobUrl);
      saved++;

      const safePrompt = prompts[i]
        .slice(0, 40)
        .replace(/[^a-z0-9]+/gi, '_')
        .toLowerCase();

      const filename = `firefly_${i + 1}_${safePrompt}.png`;
      await fsp.writeFile(
        path.join(DOWNLOAD_DIR, filename),
        Buffer.from(buffer)
      );

      console.log(`✅ Saved: ${filename}`);
    }

    await page.waitForTimeout(1000);
  }

  console.log('\n🎉 SEMUA PROMPT SELESAI');
})();

Workflow script autogenerate autodownload firefly_autodownload_firefox_blob_final.js

 

Ya 👍 BETUL SEKALI — dan susunannya sudah rapi & benar.
Saya ringkaskan ulang langkah demi langkah (versi final & clean) supaya bisa kamu jadikan catatan permanen.


✅ LANGKAH DEMI LANGKAH (FINAL WORKFLOW)


1️⃣ Install Playwright + Firefox

Dijalankan sekali saja:

npm install playwright
npx playwright install firefox

✔️ Mengunduh Firefox versi Playwright
✔️ Dipakai otomatis oleh script
✔️ Tidak mengganggu Firefox sistem


2️⃣ Struktur folder (SESUAI GAMBAR KAMU ✅)

fire-playwright/
├── downloads/                      ← hasil image tersimpan
├── firefox-profile/                ← profile login Firefly (persistent)
├── node_modules/
├── firefly_autodownload_firefox_blob_final.js
├── prompts.txt                     ← daftar prompt (1 baris = 1 prompt)
├── package.json
└── package-lock.json

📌 Ini struktur ideal & recommended


3️⃣ Isi prompts.txt

Contoh:

faceless child astronaut holding a flag, line art, coloring book style
faceless child baker baking bread in a kitchen, line art, coloring book
faceless child doctor checking a patient, line art illustration

📌 Satu baris = satu prompt
📌 Tidak perlu tanda kutip


4️⃣ Jalankan script

node firefly_autodownload_firefox_blob_final.js

Lalu:

  1. Firefox terbuka (1 window saja ✅)

  2. Login Adobe Firefly manual

  3. Atur:

    • Model

    • Aspect ratio

  4. Kembali ke terminal → tekan ENTER

  5. Biarkan script bekerja


5️⃣ Hasil akhir

  • Image muncul di folder downloads/

  • Nama file otomatis dari prompt

  • Tidak dobel

  • Tidak replace

  • Aman sampai ratusan prompt


🧠 KENAPA STRUKTUR INI BENAR?

KomponenFungsi
firefox-profile/Simpan login & setting Firefly
downloads/Output aman (bukan blob)
savedBlobs Set()Cegah duplikat
before/after countIsolasi hasil per prompt
Firefox PlaywrightLebih stabil untuk blob

⚠️ HAL YANG TIDAK PERLU LAGI

❌ Chrome
❌ acceptDownloads
❌ klik tombol Download
❌ rename manual file
❌ copy-paste blob


🏁 KESIMPULAN

✔️ Langkah kamu 100% benar
✔️ Struktur folder ideal
✔️ Workflow sudah matang
✔️ Siap dipakai rutin / skala besar


Ya 👍 BENAR — dari sisi file yang kamu BUAT manual, hanya dua itu.


✅ FILE YANG KAMU BUAT SENDIRI

1️⃣ Script utama

firefly_autodownload_firefox_blob_final.js

✔️ Ini inti semuanya
✔️ Berisi seluruh logic automation
✔️ Tidak perlu file JS lain


2️⃣ Daftar prompt

prompts.txt

✔️ 1 baris = 1 prompt
✔️ Bisa diedit kapan saja
✔️ Bisa ganti, tambah, kurangi tanpa ubah script


📁 FILE / FOLDER LAIN → DIBUAT OTOMATIS

ItemDibuat olehKeterangan
node_modules/npmLibrary Playwright
package.jsonnpmMetadata project
package-lock.jsonnpmLock dependency
firefox-profile/ScriptSimpan login Firefly
downloads/ScriptHasil image

👉 Tidak perlu kamu sentuh


🧠 RINGKASAN SUPER SINGKAT

  • ✍️ Kamu hanya bikin 2 file

  • ⚙️ Sisanya otomatis

  • 🔁 Ganti prompt → tinggal edit prompts.txt

  • ▶️ Jalankan ulang script


💡 Tips kecil (best practice)

  • Backup firefox-profile/ → supaya login aman

  • Jangan hapus downloads/ saat script jalan

  • Kalau ganti akun Adobe → hapus firefox-profile/ lalu login ulang