diff --git a/src/main/java/de/fabianonline/telegram_backup/CommandLineDownloadProgress.java b/src/main/java/de/fabianonline/telegram_backup/CommandLineDownloadProgress.java index 6cb0a0f..6164a0a 100644 --- a/src/main/java/de/fabianonline/telegram_backup/CommandLineDownloadProgress.java +++ b/src/main/java/de/fabianonline/telegram_backup/CommandLineDownloadProgress.java @@ -16,8 +16,8 @@ class CommandLineDownloadProgress implements DownloadProgressInterface { System.out.println("Checking and downloading media."); System.out.println("Legend:"); System.out.println("'V' - Video 'P' - Photo 'D' - Document"); - System.out.println("'S' - Sticker 'A' - Audio 'e' - Empty file"); - System.out.println("'.' - Previously downloaded file"); + System.out.println("'S' - Sticker 'A' - Audio 'G' - Geolocation"); + System.out.println("'.' - Previously downloaded file 'e' - Empty file"); System.out.println("' ' - Ignored media type (location or website, for example)"); System.out.println("" + count + " Files to check / download"); } @@ -28,6 +28,7 @@ class CommandLineDownloadProgress implements DownloadProgressInterface { public void onMediaDownloadedSticker(boolean n) { show(n, 'S'); } public void onMediaDownloadedOther(boolean n) { show(n, ' '); } public void onMediaDownloadedAudio(boolean n) { show(n, 'A'); } + public void onMediaDownloadedGeo(boolean n) { show(n, 'G'); } public void onMediaDownloadedEmpty(boolean n) { show(true, 'e'); } public void onMediaDownloadFinished() { showNewLine(); System.out.println("Done."); } diff --git a/src/main/java/de/fabianonline/telegram_backup/Config.java b/src/main/java/de/fabianonline/telegram_backup/Config.java index 616bc1e..80577e9 100644 --- a/src/main/java/de/fabianonline/telegram_backup/Config.java +++ b/src/main/java/de/fabianonline/telegram_backup/Config.java @@ -21,5 +21,7 @@ class Config { public static final int DELAY_AFTER_GET_MESSAGES = 200; public static final int DELAY_AFTER_GET_FILE = 200; + + public static final String SECRET_GMAPS = "AIzaSyBEtUDhCQKEH6i2Mn1GAiQ9M_tLN0vxHIs"; } diff --git a/src/main/java/de/fabianonline/telegram_backup/DownloadManager.java b/src/main/java/de/fabianonline/telegram_backup/DownloadManager.java index e0e1822..0d0e6fc 100644 --- a/src/main/java/de/fabianonline/telegram_backup/DownloadManager.java +++ b/src/main/java/de/fabianonline/telegram_backup/DownloadManager.java @@ -125,9 +125,10 @@ class DownloadManager { this.downloadMessageMediaVideo(msg, (TLMessageMediaVideo)media); } else if (media instanceof TLMessageMediaAudio) { this.downloadMessageMediaAudio(msg, (TLMessageMediaAudio)media); + } else if (media instanceof TLMessageMediaGeo) { + this.downloadMessageMediaGeo(msg, (TLMessageMediaGeo)media); } else if (media instanceof TLMessageMediaEmpty || media instanceof TLMessageMediaUnsupported || - media instanceof TLMessageMediaGeo || media instanceof TLMessageMediaWebPage || media instanceof TLMessageMediaContact || media instanceof TLMessageMediaVenue) { @@ -242,6 +243,20 @@ class DownloadManager { } } + private void downloadMessageMediaGeo(TLMessage msg, TLMessageMediaGeo g) throws IOException { + if (g.getGeo() instanceof TLGeoPoint) { + TLGeoPoint geo = (TLGeoPoint)g.getGeo(); + String url = "https://maps.googleapis.com/maps/api/staticmap?center=" + + geo.getLat() + "," + geo.getLong() + "&zoom=14&size=300x150&scale=2&format=png&key=" + Config.SECRET_GMAPS; + boolean res = downloadExternalFile(this.makeFilename(msg.getId(), "png"), url); + prog.onMediaDownloadedGeo(res); + } else if (g.getGeo() instanceof TLGeoPointEmpty) { + downloadEmptyObject(g.getGeo()); + } else { + throw new RuntimeException("Got an unexpected " + g.getGeo().getClass().getName()); + } + } + private ArrayList makeIdList(int start, int end) { if (start > end) throw new RuntimeException("start and end reversed"); ArrayList a = new ArrayList(end - start + 1); @@ -335,4 +350,10 @@ class DownloadManager { throw ex; } } + + private boolean downloadExternalFile(String target, String url) throws IOException { + if (new File(target).isFile()) return false; + FileUtils.copyURLToFile(new URL(url), new File(target), 5000, 5000); + return true; + } } diff --git a/src/main/java/de/fabianonline/telegram_backup/DownloadProgressInterface.java b/src/main/java/de/fabianonline/telegram_backup/DownloadProgressInterface.java index ea979c1..cf31bea 100644 --- a/src/main/java/de/fabianonline/telegram_backup/DownloadProgressInterface.java +++ b/src/main/java/de/fabianonline/telegram_backup/DownloadProgressInterface.java @@ -12,6 +12,7 @@ interface DownloadProgressInterface { public void onMediaDownloadedSticker(boolean n); public void onMediaDownloadedOther(boolean n); public void onMediaDownloadedAudio(boolean n); + public void onMediaDownloadedGeo(boolean n); public void onMediaDownloadedEmpty(boolean n); public void onMediaDownloadFinished(); }