1
0
mirror of https://github.com/fabianonline/telegram_backup.git synced 2025-07-11 16:56:25 +00:00

Completely reworked the file download part and made it much, much more object oriented.

This commit is contained in:
2016-07-07 17:10:00 +02:00
parent ecbca30a10
commit 2e43ad90a6
15 changed files with 791 additions and 219 deletions

View File

@ -23,6 +23,8 @@ import com.github.badoualy.telegram.tl.core.TLVector;
import de.fabianonline.telegram_backup.Database;
import de.fabianonline.telegram_backup.UserManager;
import de.fabianonline.telegram_backup.mediafilemanager.AbstractMediaFileManager;
import de.fabianonline.telegram_backup.mediafilemanager.FileManagerFactory;
class TelegramUpdateHandler implements UpdateCallback {
private UserManager user = null;
@ -131,13 +133,16 @@ class TelegramUpdateHandler implements UpdateCallback {
vector.add(abs_msg);
db.saveMessages(vector);
System.out.print('.');
if (abs_msg instanceof TLMessage && ((TLMessage)abs_msg).getMedia()!=null) {
try {
new DownloadManager(user, client, new CommandLineDownloadProgress()).downloadSingleMessageMedia((TLMessage)abs_msg, ((TLMessage)abs_msg).getMedia());
} catch (Exception e) {
System.out.println("We got an exception while downloading media, but we're going to ignore it.");
System.out.println("Here it is anyway:");
e.printStackTrace();
if (abs_msg instanceof TLMessage) {
AbstractMediaFileManager fm = FileManagerFactory.getFileManager((TLMessage)abs_msg, user, client);
if (fm != null && !fm.isEmpty() && !fm.isDownloaded()) {
try {
fm.download();
} catch (Exception e) {
System.out.println("We got an exception while downloading media, but we're going to ignore it.");
System.out.println("Here it is anyway:");
e.printStackTrace();
}
}
}
} else {