Streetside-Scripts/download.js
Alexander Bass b80ccd6c6d Init
2023-04-30 20:13:07 -04:00

42 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use strict";
import { writeFile } from 'fs/promises';
import fetch from 'node-fetch';
async function main() {
// SET BASE-10 ID HERE
const id10 = 1248148552;
// Convert Decimal ID to Quaternary
const id4 = toBase(id10, 4);
for (let face = 1; face <= 6; face++) {
// Convert cube face number into quaternary and ensure it's two digits
const face4 = toBase(face, 4).padStart(2, "0");
// Loop though all 8×8=64 tiles.
for (let position = 0; position < 64; position++) {
// Convert position into quaternary and ensure it's three digits
const position4 = toBase(position, 4).padStart(3, "0");
// Format url with Image ID, Cube Face, and Tile Position, all in quaternary
const url = `https://t.ssl.ak.tiles.virtualearth.net/tiles/`
+ `hs${id4}${face4}${position4}.jpg?g=0`;
// Download tile
const response = await fetch(url);
const imageData = response.body;
console.log("downloaded: ", url);
// Save tile into out directory
const filename = `out/${face4}${position4}.jpg`;
await writeFile(filename, imageData);
}
}
}
// Function to clarify when base conversions are happening as JavaScript's way of doing this is unintuitive
function toBase(number, base) {
return number.toString(base);
}
main();