Skip to content

Instantly share code, notes, and snippets.

@kacpak
Last active July 16, 2018 16:18
Show Gist options
  • Save kacpak/0b47100453d8f82012fd11817dbb451e to your computer and use it in GitHub Desktop.
Save kacpak/0b47100453d8f82012fd11817dbb451e to your computer and use it in GitHub Desktop.
Saves Bing spotlight images from lockscreen
node spotlight-images-save.js
const fs = require('fs');
const os = require('os');
const path = require('path');
const FILE_SIZE_THRESHOLD = 200 * 1000;
const OUTPUT_DIR = path.resolve(__dirname, 'spotlight');
const INPUT_DIR = path.resolve(
os.homedir(),
'AppData/Local/Packages/Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy/LocalState/Assets'
);
const getDistFileName = originalPath => path.join(OUTPUT_DIR, `${path.basename(originalPath)}.jpg`);
const bigImages = fs
.readdirSync(INPUT_DIR, { encoding: 'utf8' })
.map(name => path.join(INPUT_DIR, name))
.filter(path => fs.statSync(path).size > FILE_SIZE_THRESHOLD)
.filter(path => !fs.existsSync(getDistFileName(path)));
if (!fs.existsSync(OUTPUT_DIR)) {
fs.mkdirSync(OUTPUT_DIR);
}
bigImages.forEach(filePath => {
const dest = getDistFileName(filePath);
fs.copyFileSync(filePath, dest);
});
console.log(`Copied ${bigImages.length} files to ${OUTPUT_DIR}`);
@maja-m
Copy link

maja-m commented Jun 24, 2018

Naisu! 🍶

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment