webamp/packages/skinArchiveTools/lib
2020-05-17 22:24:35 -07:00
..
collectSkins.js Move skin stuff to their own packages 2020-05-17 22:24:35 -07:00
color.js Move skin stuff to their own packages 2020-05-17 22:24:35 -07:00
constants.js Move skin stuff to their own packages 2020-05-17 22:24:35 -07:00
index.js Move skin stuff to their own packages 2020-05-17 22:24:35 -07:00
readme.js Move skin stuff to their own packages 2020-05-17 22:24:35 -07:00
shooter.js Move skin stuff to their own packages 2020-05-17 22:24:35 -07:00
takeScreenshots.js Move skin stuff to their own packages 2020-05-17 22:24:35 -07:00
utils.js Move skin stuff to their own packages 2020-05-17 22:24:35 -07:00

const { exec } = require("child_process");

const reg = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/gi;
const extract = (value) => (value && value.match(reg)) || [];

async function extractTextData(skinPath) {
  const ignoreFiles = [
    "genex.txt",
    "genexinfo.txt",
    "gen_gslyrics.txt",
    "region.txt",
    "pledit.txt",
    "viscolor.txt",
    "winampmb.txt",
    "gen_ex help.txt",
    "mbinner.txt",
    // Skinning Updates.txt ?
  ];

  const ignoreArgs = ignoreFiles
    .map((file) => `-x "**/${file}" ${file}`)
    .join(" ");

  // Change -p to -c to get context of which file is missing
  const debug = false;
  const listFlag = debug ? "-c" : "-p";

  // TODO: Escape path
  const cmd = `unzip ${listFlag} -C "${skinPath}" "file_id.diz" "*.txt" ${ignoreArgs}`;

  const raw = await new Promise((resolve) => {
    exec(cmd, (error, stdout) => {
      if (error != null) {
        // reject(error);
        // return;
      }
      resolve(stdout);
    });
  });

  return { raw, emails: extract(raw) };
}

module.exports = {
  extractTextData,
};