1
0
mirror of https://github.com/fabianonline/telegram_backup.git synced 2024-07-05 06:35:49 +00:00

Better support for empty media types.

This commit is contained in:
Fabian Schlenz 2016-07-04 10:19:36 +02:00
parent 8c0bb8aa83
commit 83664b8fc0
3 changed files with 20 additions and 1 deletions

View File

@ -16,7 +16,7 @@ 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");
System.out.println("'S' - Sticker 'A' - Audio 'e' - Empty file");
System.out.println("'.' - Previously downloaded 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 onMediaDownloadedEmpty(boolean n) { show(true, 'e'); }
public void onMediaDownloadFinished() { showNewLine(); System.out.println("Done."); }
private void show(boolean n, char letter) { System.out.print(n ? letter : '.'); i++; if (i % 50 == 0) showNewLine();}

View File

@ -7,6 +7,7 @@ import de.fabianonline.telegram_backup.DownloadProgressInterface;
import com.github.badoualy.telegram.api.TelegramClient;
import com.github.badoualy.telegram.tl.core.TLIntVector;
import com.github.badoualy.telegram.tl.core.TLObject;
import com.github.badoualy.telegram.tl.api.messages.TLAbsMessages;
import com.github.badoualy.telegram.tl.api.messages.TLAbsDialogs;
import com.github.badoualy.telegram.tl.api.*;
@ -134,6 +135,8 @@ class DownloadManager {
boolean res = this.downloadPhoto(msg.getId(), (TLFileLocation)size.getLocation(), size.getSize());
prog.onMediaDownloadedPhoto(res);
}
} else if (p.getPhoto() instanceof TLPhotoEmpty) {
downloadEmptyObject(p.getPhoto());
} else {
throw new RuntimeException("Got an unexpected " + p.getPhoto().getClass().getName());
}
@ -180,6 +183,8 @@ class DownloadManager {
} else {
prog.onMediaDownloadedDocument(res);
}
} else if (d.getDocument() instanceof TLDocumentEmpty) {
downloadEmptyObject(d.getDocument());
} else {
throw new RuntimeException("Got an unexpected " + d.getDocument().getClass().getName());
}
@ -192,6 +197,10 @@ class DownloadManager {
String ext = vid.getMimeType().substring(i+1).toLowerCase();
boolean res = this.downloadVideo(this.makeFilename(msg.getId(), ext), vid);
prog.onMediaDownloadedVideo(res);
} else if (v.getVideo() instanceof TLVideoEmpty) {
downloadEmptyObject(v.getVideo());
} else {
throw new RuntimeException("Got an unexpected " + v.getVideo().getClass().getName());
}
}
@ -202,6 +211,10 @@ class DownloadManager {
String ext = audio.getMimeType().substring(i+1).toLowerCase();
boolean res = this.downloadAudio(this.makeFilename(msg.getId(), ext), audio);
prog.onMediaDownloadedAudio(res);
} else if (a.getAudio() instanceof TLAudioEmpty) {
downloadEmptyObject(a.getAudio());
} else {
throw new RuntimeException("Got an unexpected " + a.getAudio().getClass().getName());
}
}
@ -242,6 +255,10 @@ class DownloadManager {
return this.downloadFileFromDc(filename, loc, audio.getDcId(), audio.getSize());
}
private void downloadEmptyObject(TLObject obj) {
prog.onMediaDownloadedEmpty(true);
}
private String makeFilename(int id, String ext) {
String path = this.user.getFileBase() +
Config.FILE_FILES_BASE +

View File

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