From ae71234079318bac4cc60f0780356f37153276ac Mon Sep 17 00:00:00 2001 From: TheGreatRambler Date: Wed, 22 May 2024 08:15:15 -0700 Subject: [PATCH] Fix endpoint changes --- .clang-format | 1 - .gitmodules | 4 ++++ CMakeLists.txt | 2 +- src/download.cpp | 34 +++++++++++++++++----------------- src/main.cpp | 46 +++++++++++++++++++++++++++++++++++----------- 5 files changed, 57 insertions(+), 30 deletions(-) diff --git a/.clang-format b/.clang-format index 18cf9cc..656f292 100644 --- a/.clang-format +++ b/.clang-format @@ -18,7 +18,6 @@ IncludeBlocks: Preserve NamespaceIndentation: All PointerAlignment: Left SortIncludes: "true" -AlwaysBreakAfterDefinitionReturnType: None SpaceBeforeAssignmentOperators: "true" SpaceBeforeParens: Never SpaceInEmptyParentheses: "false" diff --git a/.gitmodules b/.gitmodules index 2bc0abb..125f6df 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,12 +1,15 @@ [submodule "third_party/fmt"] path = third_party/fmt url = https://github.com/fmtlib/fmt + shallow = true [submodule "third_party/curl"] path = third_party/curl url = https://github.com/curl/curl + shallow = true [submodule "third_party/CLI11"] path = third_party/CLI11 url = https://github.com/CLIUtils/CLI11 + shallow = true [submodule "third_party/skia"] path = third_party/skia url = https://github.com/google/skia @@ -14,3 +17,4 @@ [submodule "third_party/rapidjson"] path = third_party/rapidjson url = https://github.com/Tencent/rapidjson + shallow = true diff --git a/CMakeLists.txt b/CMakeLists.txt index a4b5f50..5eaf72e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,7 +71,7 @@ add_executable(streetview_client ${APPLICATION_TYPE} ) set_target_properties(streetview_client PROPERTIES POSITION_INDEPENDENT_CODE ON) -target_compile_options(streetview_client PRIVATE -Wall -Wextra -Wno-unused-parameter -Wno-missing-braces) +target_compile_options(streetview_client PRIVATE -Wall -Wextra -Wno-unused-parameter -Wno-missing-braces -Wno-sign-conversion -Wno-deprecated-copy-with-user-provided-copy) set_target_properties(streetview_client PROPERTIES OUTPUT_NAME "streetview_client" diff --git a/src/download.cpp b/src/download.cpp index e5f5b02..d5ee356 100644 --- a/src/download.cpp +++ b/src/download.cpp @@ -32,7 +32,7 @@ std::string download_from_url( // added options that may be required curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1L); // redirects curl_easy_setopt(curl_handle, CURLOPT_HTTPPROXYTUNNEL, - 1L); // corp. proxies etc. + 1L); // corp. proxies etc. // curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L); // we want it all // curl_easy_setopt(curl_handle, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | // CURLPROTO_HTTPS); @@ -58,19 +58,19 @@ rapidjson::Document download_preview_document( CURL* curl_handle, std::string client_id, int num_previews, double lat, double lng, int range) { CURLcode res; auto photo_preview_download = download_from_url( - fmt::format("https://www.google.com/maps/preview/" - "photo?authuser=0&hl=en&gl=us&pb=!1e3!5m54!2m2!1i203!2i100!3m3!2i{}" - "!" - "3s{}!5b1!7m42!1m3!1e1!2b0!3e3!1m3!1e2!2b1!3e2!1m3!1e2!2b0!3e3!1m3!" - "1e8!" - "2b0!3e3!1m3!1e10!2b0!3e3!1m3!1e10!2b1!3e2!1m3!1e9!2b1!3e2!1m3!" - "1e10!" - "2b0!" - "3e3!1m3!1e10!2b1!3e2!1m3!1e10!2b0!3e4!2b1!4b1!8m0!9b0!11m1!4b1!" - "6m3!" - "1s{}" - "!" - "7e81!15i11021!9m2!2d{}!3d{}!10d{}", + fmt::format( + "https://www.google.com/maps/rpc/photo/listentityphotos?authuser=0&hl=en&gl=us&pb=!1e3!5m54!2m2!1i203!2i100!3m3!2i{}" + "!" + "3s{}!5b1!7m42!1m3!1e1!2b0!3e3!1m3!1e2!2b1!3e2!1m3!1e2!2b0!3e3!1m3!" + "1e8!" + "2b0!3e3!1m3!1e10!2b0!3e3!1m3!1e10!2b1!3e2!1m3!1e9!2b1!3e2!1m3!" + "1e10!" + "2b0!" + "3e3!1m3!1e10!2b1!3e2!1m3!1e10!2b0!3e4!2b1!4b1!8m0!9b0!11m1!4b1!" + "6m3!" + "1s{}" + "!" + "7e81!15i11021!9m2!2d{}!3d{}!10d{}", num_previews, MAPS_PREVIEW_ID, client_id, lng, lat, range), curl_handle, &res, NULL); @@ -118,9 +118,9 @@ sk_sp download_panorama(CURL* curl_handle, std::string panorama_id, int // Download the specific tile // Each tile takes around ~40ms to download CURLcode res; - auto tile_url = fmt::format("https://streetviewpixels-pa.googleapis.com/v1/" - "tile?cb_client=maps_sv.tactile&panoid={}&x={}&" - "y={}&zoom={}&nbt=1&fover=2", + auto tile_url = fmt::format( + "https://streetviewpixels-pa.googleapis.com/v1/tile?cb_client=maps_sv.tactile&panoid={}&x={}&" + "y={}&zoom={}&nbt=1&fover=2", panorama_id, x, y, streetview_zoom); auto tile_download = download_from_url(tile_url, curl_handle, &res, get_panorama_headers()); diff --git a/src/main.cpp b/src/main.cpp index b667abc..72458d8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -264,10 +264,10 @@ int main(int argc, char** argv) { auto photometa_document = download_photometa(curl_handle, client_id, panorama_id); // Get info - auto panorama_info = extract_info(photometa_document); + auto panorama = extract_info(photometa_document); // Check if it is within the range - if(is_within_date(year_start, year_end, month_start, month_end, panorama_info)) { + if(is_within_date(year_start, year_end, month_start, month_end, panorama)) { // Get panorama auto tile_surface = download_panorama( curl_handle, panorama_id, streetview_zoom, photometa_document); @@ -275,18 +275,42 @@ int main(int argc, char** argv) { // Location auto location = extract_location(photometa_document); - std::string filename = fmt::format(fmt::runtime(filepath_format + ".png"), - fmt::arg("id", panorama_id), fmt::arg("year", panorama_info.year), - fmt::arg("month", panorama_info.month), fmt::arg("street", location.street), - fmt::arg("city", location.city_and_state), - fmt::arg("lat", panorama_info.lat), fmt::arg("long", panorama_info.lng)); + std::string filename = fmt::format(fmt::runtime(filepath_format), + fmt::arg("id", panorama_id), fmt::arg("year", panorama.year), + fmt::arg("month", panorama.month), fmt::arg("street", location.street), + fmt::arg("city", location.city_and_state), fmt::arg("lat", panorama.lat), + fmt::arg("long", panorama.lng)); std::filesystem::create_directories( std::filesystem::path(filename).parent_path()); - auto tile_data = tile_surface->encodeToData(SkEncodedImageFormat::kPNG, 95); - std::ofstream outfile(filename, std::ios::out | std::ios::binary); - outfile.write((const char*)tile_data->bytes(), tile_data->size()); - outfile.close(); + if(!only_include_json_info) { + 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 || only_include_json_info) { + // Include JSON info alongside + rapidjson::Document infoJson(rapidjson::kObjectType); + infoJson.AddMember("id", panorama_id, infoJson.GetAllocator()); + infoJson.AddMember("year", panorama.year, infoJson.GetAllocator()); + infoJson.AddMember("month", panorama.month, infoJson.GetAllocator()); + infoJson.AddMember( + "location", location.city_and_state, infoJson.GetAllocator()); + infoJson.AddMember("lat", panorama.lat, infoJson.GetAllocator()); + infoJson.AddMember("long", panorama.lng, infoJson.GetAllocator()); + + rapidjson::StringBuffer infoSb; + rapidjson::PrettyWriter infoWriter(infoSb); + infoWriter.SetIndent('\t', 1); + infoJson.Accept(infoWriter); + + // Write to filesystem at the same location the panorama is + std::ofstream infoFile(filename + ".json", std::ios::out); + infoFile.write(infoSb.GetString(), infoSb.GetLength()); + infoFile.close(); + } stop = std::chrono::high_resolution_clock::now(); fmt::print("Downloading {} took {}ms\n", panorama_id,