@sinedied/mini-scraper
Version:
Artwork scraper for handheld emulators.
43 lines (42 loc) • 1.64 kB
JavaScript
import path from 'node:path';
import fs from 'node:fs/promises';
import createDebug from 'debug';
import glob from 'fast-glob';
import { getArtTypes } from '../libretro.js';
import { composeImageTo, resizeImageTo } from '../image.js';
const debug = createDebug('nextui');
const mediaFolder = '.media';
export async function useSeparateArtworks(_options) {
return false;
}
export async function getArtPath(filePath, _machine, _type) {
const fileName = path.basename(filePath, path.extname(filePath));
return path.join(path.dirname(filePath), mediaFolder, `${fileName}.png`);
}
export async function exportArtwork(art1Url, art2Url, artPath, options) {
const artTypes = getArtTypes(options);
if (artTypes.art2 && (art1Url ?? art2Url)) {
debug(`Found art URL(s): "${art1Url}" / "${art2Url}"`);
await composeImageTo(art1Url, art2Url, artPath, { width: options.width, height: options.height });
}
else if (art1Url) {
debug(`Found art URL: "${art1Url}"`);
await resizeImageTo(art1Url, artPath, { width: options.width, height: options.height });
}
else {
return false;
}
return true;
}
export async function cleanupArtwork(targetPath, _romFolders, _options) {
const mediaFolders = await glob([`**/${mediaFolder}`], { onlyDirectories: true, cwd: targetPath });
await Promise.all(mediaFolders.map(async (mediaFolder) => fs.rm(mediaFolder, { recursive: true })));
console.info(`Removed ${mediaFolders.length} ${mediaFolder} folders`);
}
const nextui = {
useSeparateArtworks,
getArtPath,
exportArtwork,
cleanupArtwork
};
export default nextui;