Skip to content

Commit

Permalink
Fix endpoint changes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGreatRambler committed May 22, 2024
1 parent b78219f commit ae71234
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 30 deletions.
1 change: 0 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ IncludeBlocks: Preserve
NamespaceIndentation: All
PointerAlignment: Left
SortIncludes: "true"
AlwaysBreakAfterDefinitionReturnType: None
SpaceBeforeAssignmentOperators: "true"
SpaceBeforeParens: Never
SpaceInEmptyParentheses: "false"
Expand Down
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
[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
shallow = true
[submodule "third_party/rapidjson"]
path = third_party/rapidjson
url = https://github.com/Tencent/rapidjson
shallow = true
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
34 changes: 17 additions & 17 deletions src/download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand Down Expand Up @@ -118,9 +118,9 @@ sk_sp<SkImage> 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());
Expand Down
46 changes: 35 additions & 11 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,29 +264,53 @@ 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);

// 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<rapidjson::StringBuffer> 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,
Expand Down

0 comments on commit ae71234

Please sign in to comment.