Skip to content

Commit

Permalink
Add --only-json flag
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGreatRambler committed Jul 24, 2023
1 parent 9f28842 commit b78219f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build
.vscode
.vscode
cesiumtest
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ set(SKIA_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/third_party/skia)
execute_process(
COMMAND python tools/git-sync-deps
WORKING_DIRECTORY ${SKIA_DIR})
execute_process(
COMMAND python bin/fetch-gn
WORKING_DIRECTORY ${SKIA_DIR})
if(ANDROID)

elseif(WIN32)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Options:
-n,--num-panoramas INT Number of panoramas to attempt to download
-z,--zoom INT Dimensions of street view images, higher numbers increase resolution. Usually 1=832x416, 2=1664x832, 3=3328x1664, 4=6656x3328, 5=13312x6656 (glitched at the poles)
-j,--json Include JSON info alongside panorama
--only-json Only include JSON info alongside panorama
Subcommands:
recursive Recursively attempt to download nearby panoramas
Expand Down
28 changes: 18 additions & 10 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ int main(int argc, char** argv) {
"increase resolution. Usually 1=832x416, 2=1664x832, 3=3328x1664, 4=6656x3328, 5=13312x6656 (glitched at the poles)");
bool include_json_info = false;
download_sub.add_flag("-j,--json", include_json_info, "Include JSON info alongside panorama");
bool only_include_json_info = false;
download_sub.add_flag(
"--only-json", only_include_json_info, "Only include JSON info alongside panorama");

auto& download_recursive_sub = *download_sub.add_subcommand(
"recursive", "Recursively attempt to download nearby panoramas");
Expand Down Expand Up @@ -179,15 +182,14 @@ int main(int argc, char** argv) {
month_start, month_end, panorama)) {
auto start = std::chrono::high_resolution_clock::now();

// Obtain photometa for tiles dimensions
// Obtain photometa for tiles dimensions and date
auto photometa_document
= download_photometa(curl_handle, client_id, panorama.id);
if(!valid_photometa(photometa_document)) {
continue;
}
panorama = extract_info(photometa_document);

// Get panorama
auto tile_surface = download_panorama(
curl_handle, panorama.id, streetview_zoom, photometa_document);

// Location
auto location = extract_location(photometa_document);

Expand All @@ -199,12 +201,18 @@ int main(int argc, char** argv) {
std::filesystem::create_directories(
std::filesystem::path(filename).parent_path());

auto tile_data = tile_surface->encodeToData(SkEncodedImageFormat::kPNG, 95);
std::ofstream outfile(filename + ".png", std::ios::out | std::ios::binary);
outfile.write((const char*)tile_data->bytes(), tile_data->size());
outfile.close();
if(!only_include_json_info) {
// Get panorama image
auto tile_surface = download_panorama(
curl_handle, panorama.id, streetview_zoom, photometa_document);

auto tile_data = tile_surface->encodeToData(SkEncodedImageFormat::kPNG, 95);
std::ofstream outfile(filename + ".png", std::ios::out | std::ios::binary);
outfile.write((const char*)tile_data->bytes(), tile_data->size());
outfile.close();
}

if(include_json_info) {
if(include_json_info || only_include_json_info) {
// Include JSON info alongside
rapidjson::Document infoJson(rapidjson::kObjectType);
infoJson.AddMember("id", panorama.id, infoJson.GetAllocator());
Expand Down

0 comments on commit b78219f

Please sign in to comment.