mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-23 18:17:38 +00:00
Improve how we extract dat a from skins
This commit is contained in:
parent
82d0323f58
commit
37d97bb2da
6 changed files with 493 additions and 53 deletions
|
|
@ -1,11 +1,13 @@
|
|||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const Bluebird = require("bluebird");
|
||||
var { exec } = require("child_process");
|
||||
const Utils = require("./utils");
|
||||
|
||||
async function extractTextData(path) {
|
||||
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])?/g;
|
||||
const extract = value => (value && value.match(reg)) || [];
|
||||
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])?/g;
|
||||
const extract = value => (value && value.match(reg)) || [];
|
||||
|
||||
async function extractTextData(path) {
|
||||
const ignoreFiles = [
|
||||
"genex.txt",
|
||||
"genexinfo.txt",
|
||||
|
|
@ -33,8 +35,8 @@ async function extractTextData(path) {
|
|||
const raw = await new Promise((resolve, reject) => {
|
||||
exec(cmd, function(error, stdout, stderr) {
|
||||
if (error != null) {
|
||||
//reject(error);
|
||||
//return;
|
||||
// reject(error);
|
||||
// return;
|
||||
}
|
||||
resolve(stdout);
|
||||
});
|
||||
|
|
@ -43,15 +45,34 @@ async function extractTextData(path) {
|
|||
return { raw, emails: extract(raw) };
|
||||
}
|
||||
|
||||
async function writeTextData(skinPath) {
|
||||
const data = await extractTextData(skinPath);
|
||||
const md5 = await Utils.getFileMd5(skinPath);
|
||||
const skinMetadataPath = await Utils.writeSkinMetadata(
|
||||
md5,
|
||||
"extracted-data",
|
||||
data
|
||||
);
|
||||
console.log("Done", skinMetadataPath);
|
||||
async function writeTextData(skinPath, md5) {
|
||||
try {
|
||||
const data = await extractTextData(skinPath);
|
||||
const skinMetadataPath = await Utils.writeSkinMetadata(
|
||||
md5,
|
||||
"extracted-data",
|
||||
data
|
||||
);
|
||||
console.log("Done", skinMetadataPath);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
writeTextData(path.join(process.cwd(), process.argv[2]));
|
||||
function main() {
|
||||
const dir = process.argv[2];
|
||||
console.log("Reading dir");
|
||||
const files = fs.readdirSync(dir);
|
||||
console.log(`Found ${files.length} files`);
|
||||
return Bluebird.map(
|
||||
files,
|
||||
file => {
|
||||
const filePath = path.join(dir, file);
|
||||
const md5 = path.basename(file, ".wsz");
|
||||
return writeTextData(filePath, md5);
|
||||
},
|
||||
{ concurrency: 10 }
|
||||
);
|
||||
}
|
||||
|
||||
main();
|
||||
|
|
|
|||
|
|
@ -1,31 +1,21 @@
|
|||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const exec = require("child_process").exec;
|
||||
const Bluebird = require("bluebird");
|
||||
const shellescape = require("shell-escape");
|
||||
const https = require("https");
|
||||
|
||||
const FILENAME_URL =
|
||||
"https://s3-us-west-2.amazonaws.com/winamp2-js-skins/filenames.txt";
|
||||
|
||||
const getFileNames = async () => {
|
||||
const content = await new Promise(resolve =>
|
||||
https.get(FILENAME_URL, response => {
|
||||
var data = "";
|
||||
response.on("data", function(chunk) {
|
||||
data += chunk;
|
||||
});
|
||||
response.on("end", function() {
|
||||
resolve(data);
|
||||
});
|
||||
})
|
||||
const content = fs.readFileSync(
|
||||
"/Volumes/Mobile Backup/skins/pathnames.txt",
|
||||
"utf8"
|
||||
);
|
||||
const fileNames = {};
|
||||
content.split("\n").forEach(line => {
|
||||
if (!line.length) {
|
||||
return;
|
||||
}
|
||||
const [hash, fileName] = line.split(" ");
|
||||
fileNames[hash] = fileName;
|
||||
const [hash, pathName] = line.split(" ");
|
||||
fileNames[hash] = path.basename(pathName);
|
||||
});
|
||||
return fileNames;
|
||||
};
|
||||
|
|
@ -42,9 +32,9 @@ const getFavoriteCounts = () => {
|
|||
});
|
||||
return favorites;
|
||||
};
|
||||
const testFolder = path.join(
|
||||
const testFolder = path.resolve(
|
||||
__dirname,
|
||||
"../../webamp/experiments/automatedScreenshots/screenshots/"
|
||||
"/Volumes/Mobile Backup/skins/md5Screenshots"
|
||||
);
|
||||
const files = fs
|
||||
.readdirSync(testFolder)
|
||||
|
|
@ -69,22 +59,23 @@ const getFileData = async files => {
|
|||
const favortes = getFavoriteCounts();
|
||||
console.log(favortes);
|
||||
const fileData = {};
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
const file = files[i];
|
||||
const md5 = path.basename(file, ".png");
|
||||
const fileName = fileNames[md5];
|
||||
if (!fileName) {
|
||||
console.warn("no file name for ", md5);
|
||||
continue;
|
||||
}
|
||||
// Intentional blocking async loop so we don't use too many child
|
||||
// Processes
|
||||
fileData[md5] = {
|
||||
color: (await genAverage(file)).slice(1),
|
||||
favorites: favortes[md5],
|
||||
fileName
|
||||
};
|
||||
}
|
||||
await Bluebird.map(
|
||||
files,
|
||||
async file => {
|
||||
const md5 = path.basename(file, ".png");
|
||||
const fileName = fileNames[md5];
|
||||
if (!fileName) {
|
||||
console.warn("no file name for ", md5);
|
||||
return;
|
||||
}
|
||||
fileData[md5] = {
|
||||
color: (await genAverage(file)).slice(1),
|
||||
favorites: favortes[md5],
|
||||
fileName
|
||||
};
|
||||
},
|
||||
{ concurrency: 10 }
|
||||
);
|
||||
return fileData;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue