1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-08-13 17:03:45 -04:00

Support for GEOCODE APIKEY

This commit is contained in:
Reinhard Pointner 2019-02-22 22:41:10 +07:00
parent c91aad1eec
commit abf208c625
2 changed files with 12 additions and 2 deletions

View File

@ -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}

View File

@ -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<AddressComponent, String> address = new EnumMap<AddressComponent, String>(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;
}