1
0
mirror of https://github.com/fabianonline/telegram_backup.git synced 2024-11-23 01:06:17 +00:00

Added support for downloading Geolocation maps.

This commit is contained in:
Fabian Schlenz 2016-07-05 12:56:14 +02:00
parent c8e33fa319
commit bad165e97b
4 changed files with 28 additions and 3 deletions

View File

@ -16,8 +16,8 @@ class CommandLineDownloadProgress implements DownloadProgressInterface {
System.out.println("Checking and downloading media."); System.out.println("Checking and downloading media.");
System.out.println("Legend:"); System.out.println("Legend:");
System.out.println("'V' - Video 'P' - Photo 'D' - Document"); System.out.println("'V' - Video 'P' - Photo 'D' - Document");
System.out.println("'S' - Sticker 'A' - Audio 'e' - Empty file"); System.out.println("'S' - Sticker 'A' - Audio 'G' - Geolocation");
System.out.println("'.' - Previously downloaded file"); System.out.println("'.' - Previously downloaded file 'e' - Empty file");
System.out.println("' ' - Ignored media type (location or website, for example)"); System.out.println("' ' - Ignored media type (location or website, for example)");
System.out.println("" + count + " Files to check / download"); 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 onMediaDownloadedSticker(boolean n) { show(n, 'S'); }
public void onMediaDownloadedOther(boolean n) { show(n, ' '); } public void onMediaDownloadedOther(boolean n) { show(n, ' '); }
public void onMediaDownloadedAudio(boolean n) { show(n, 'A'); } 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 onMediaDownloadedEmpty(boolean n) { show(true, 'e'); }
public void onMediaDownloadFinished() { showNewLine(); System.out.println("Done."); } public void onMediaDownloadFinished() { showNewLine(); System.out.println("Done."); }

View File

@ -21,5 +21,7 @@ class Config {
public static final int DELAY_AFTER_GET_MESSAGES = 200; public static final int DELAY_AFTER_GET_MESSAGES = 200;
public static final int DELAY_AFTER_GET_FILE = 200; public static final int DELAY_AFTER_GET_FILE = 200;
public static final String SECRET_GMAPS = "AIzaSyBEtUDhCQKEH6i2Mn1GAiQ9M_tLN0vxHIs";
} }

View File

@ -125,9 +125,10 @@ class DownloadManager {
this.downloadMessageMediaVideo(msg, (TLMessageMediaVideo)media); this.downloadMessageMediaVideo(msg, (TLMessageMediaVideo)media);
} else if (media instanceof TLMessageMediaAudio) { } else if (media instanceof TLMessageMediaAudio) {
this.downloadMessageMediaAudio(msg, (TLMessageMediaAudio)media); this.downloadMessageMediaAudio(msg, (TLMessageMediaAudio)media);
} else if (media instanceof TLMessageMediaGeo) {
this.downloadMessageMediaGeo(msg, (TLMessageMediaGeo)media);
} else if (media instanceof TLMessageMediaEmpty || } else if (media instanceof TLMessageMediaEmpty ||
media instanceof TLMessageMediaUnsupported || media instanceof TLMessageMediaUnsupported ||
media instanceof TLMessageMediaGeo ||
media instanceof TLMessageMediaWebPage || media instanceof TLMessageMediaWebPage ||
media instanceof TLMessageMediaContact || media instanceof TLMessageMediaContact ||
media instanceof TLMessageMediaVenue) { 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<Integer> makeIdList(int start, int end) { private ArrayList<Integer> makeIdList(int start, int end) {
if (start > end) throw new RuntimeException("start and end reversed"); if (start > end) throw new RuntimeException("start and end reversed");
ArrayList<Integer> a = new ArrayList<Integer>(end - start + 1); ArrayList<Integer> a = new ArrayList<Integer>(end - start + 1);
@ -335,4 +350,10 @@ class DownloadManager {
throw ex; 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;
}
} }

View File

@ -12,6 +12,7 @@ interface DownloadProgressInterface {
public void onMediaDownloadedSticker(boolean n); public void onMediaDownloadedSticker(boolean n);
public void onMediaDownloadedOther(boolean n); public void onMediaDownloadedOther(boolean n);
public void onMediaDownloadedAudio(boolean n); public void onMediaDownloadedAudio(boolean n);
public void onMediaDownloadedGeo(boolean n);
public void onMediaDownloadedEmpty(boolean n); public void onMediaDownloadedEmpty(boolean n);
public void onMediaDownloadFinished(); public void onMediaDownloadFinished();
} }