diff --git a/source/net/filebot/Settings.properties b/source/net/filebot/Settings.properties index 5fd23cc1..7fc43eda 100644 --- a/source/net/filebot/Settings.properties +++ b/source/net/filebot/Settings.properties @@ -28,5 +28,6 @@ apikey.thetvdb: @{apikey.thetvdb} apikey.themoviedb: @{apikey.themoviedb} apikey.omdb: @{apikey.omdb} apikey.acoustid: @{apikey.acoustid} +apikey.google.geocode: @{apikey.google.geocode} apikey.anidb: @{apikey.anidb} apikey.opensubtitles: @{apikey.opensubtitles} diff --git a/source/net/filebot/media/ImageMetadata.java b/source/net/filebot/media/ImageMetadata.java index 9ac6c332..651391f5 100644 --- a/source/net/filebot/media/ImageMetadata.java +++ b/source/net/filebot/media/ImageMetadata.java @@ -2,11 +2,13 @@ package net.filebot.media; import static java.util.Arrays.*; import static net.filebot.Logging.*; +import static net.filebot.Settings.*; import static net.filebot.util.JsonUtilities.*; import java.io.File; import java.io.FileFilter; import java.io.IOException; +import java.net.MalformedURLException; import java.net.URL; import java.time.ZoneOffset; import java.time.ZonedDateTime; @@ -109,8 +111,7 @@ public class ImageMetadata { try { // e.g. https://maps.googleapis.com/maps/api/geocode/json?latlng=40.7470444,-073.9411611 Cache cache = Cache.getCache("geocode", CacheType.Persistent); - - Object json = cache.json(location.getLatitude() + "," + location.getLongitude(), p -> new URL("https://maps.googleapis.com/maps/api/geocode/json?latlng=" + p)).get(); + Object json = cache.json(location.getLatitude() + "," + location.getLongitude(), this::getGeocodeRequest).get(); Map address = new EnumMap(AddressComponent.class); @@ -135,6 +136,14 @@ public class ImageMetadata { return null; } + protected URL getGeocodeRequest(String position) throws MalformedURLException { + return new URL("https://maps.googleapis.com/maps/api/geocode/json?latlng=" + position + "&key=" + getGeocodeKey()); + } + + protected String getGeocodeKey() { + return Optional.ofNullable(System.getenv("GEOCODE_APIKEY")).orElse(getApiKey("google.geocode")); + } + public enum AddressComponent { country, administrative_area_level_1, administrative_area_level_2, administrative_area_level_3, administrative_area_level_4, sublocality, neighborhood, route; }