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

Catching TimeoutExceptions during mediaDownload() should now skip the file.

This commit is contained in:
Fabian Schlenz 2017-02-21 13:41:55 +01:00
parent 50ba11a86c
commit 1d8724ecb7
5 changed files with 13 additions and 13 deletions

View File

@ -234,7 +234,7 @@ public class DownloadManager {
} else { } else {
throw e; throw e;
} }
} catch (TimeoutException e) { } /*catch (TimeoutException e) {
completed = false; completed = false;
System.out.println(""); System.out.println("");
System.out.println("Telegram took too long to respond to our request."); System.out.println("Telegram took too long to respond to our request.");
@ -242,11 +242,11 @@ public class DownloadManager {
logger.warn("TimeoutException caught", e); logger.warn("TimeoutException caught", e);
try { TimeUnit.MINUTES.sleep(1); } catch(InterruptedException e2) {} try { TimeUnit.MINUTES.sleep(1); } catch(InterruptedException e2) {}
System.out.println(""); System.out.println("");
} }*/
} while (!completed); } while (!completed);
} }
private void _downloadMedia() throws RpcErrorException, IOException, TimeoutException { private void _downloadMedia() throws RpcErrorException, IOException {
logger.info("This is _downloadMedia"); logger.info("This is _downloadMedia");
logger.info("Checking if there are messages in the DB with a too old API layer"); logger.info("Checking if there are messages in the DB with a too old API layer");
LinkedList<Integer> ids = db.getIdsFromQuery("SELECT id FROM messages WHERE has_media=1 AND api_layer<" + Kotlogram.API_LAYER); LinkedList<Integer> ids = db.getIdsFromQuery("SELECT id FROM messages WHERE has_media=1 AND api_layer<" + Kotlogram.API_LAYER);
@ -272,13 +272,13 @@ public class DownloadManager {
} else if (m.isDownloaded()) { } else if (m.isDownloaded()) {
prog.onMediaAlreadyPresent(m); prog.onMediaAlreadyPresent(m);
} else { } else {
/*try {*/ try {
m.download(); m.download();
prog.onMediaDownloaded(m); prog.onMediaDownloaded(m);
/*} catch (TimeoutException e) { } catch (TimeoutException e) {
// do nothing - skip this file // do nothing - skip this file
prog.onMediaSkipped(); prog.onMediaSkipped();
}*/ }
} }
} }
prog.onMediaDownloadFinished(); prog.onMediaDownloadFinished();
@ -290,17 +290,17 @@ public class DownloadManager {
return a; return a;
} }
public static void downloadFile(TelegramClient client, String targetFilename, int size, int dcId, long volumeId, int localId, long secret) throws RpcErrorException, IOException { public static void downloadFile(TelegramClient client, String targetFilename, int size, int dcId, long volumeId, int localId, long secret) throws RpcErrorException, IOException, TimeoutException {
TLInputFileLocation loc = new TLInputFileLocation(volumeId, localId, secret); TLInputFileLocation loc = new TLInputFileLocation(volumeId, localId, secret);
downloadFileFromDc(client, targetFilename, loc, dcId, size); downloadFileFromDc(client, targetFilename, loc, dcId, size);
} }
public static void downloadFile(TelegramClient client, String targetFilename, int size, int dcId, long id, long accessHash) throws RpcErrorException, IOException { public static void downloadFile(TelegramClient client, String targetFilename, int size, int dcId, long id, long accessHash) throws RpcErrorException, IOException, TimeoutException {
TLInputDocumentFileLocation loc = new TLInputDocumentFileLocation(id, accessHash); TLInputDocumentFileLocation loc = new TLInputDocumentFileLocation(id, accessHash);
downloadFileFromDc(client, targetFilename, loc, dcId, size); downloadFileFromDc(client, targetFilename, loc, dcId, size);
} }
private static boolean downloadFileFromDc(TelegramClient client, String target, TLAbsInputFileLocation loc, Integer dcID, int size) throws RpcErrorException, IOException { private static boolean downloadFileFromDc(TelegramClient client, String target, TLAbsInputFileLocation loc, Integer dcID, int size) throws RpcErrorException, IOException, TimeoutException {
FileOutputStream fos = null; FileOutputStream fos = null;
try { try {
String temp_filename = target + ".downloading"; String temp_filename = target + ".downloading";

View File

@ -55,7 +55,7 @@ public abstract class AbstractMediaFileManager {
public boolean isEmpty() { return isEmpty; } public boolean isEmpty() { return isEmpty; }
public boolean isDownloaded() { return new File(getTargetPathAndFilename()).isFile(); } public boolean isDownloaded() { return new File(getTargetPathAndFilename()).isFile(); }
public boolean isDownloading() { return new File(getTargetPathAndFilename() + ".downloading").isFile(); } public boolean isDownloading() { return new File(getTargetPathAndFilename() + ".downloading").isFile(); }
public abstract void download() throws RpcErrorException, IOException; public abstract void download() throws RpcErrorException, IOException, TimeoutException;
public static void throwUnexpectedObjectError(Object o) { public static void throwUnexpectedObjectError(Object o) {
throw new RuntimeException("Unexpected " + o.getClass().getName()); throw new RuntimeException("Unexpected " + o.getClass().getName());
} }

View File

@ -100,7 +100,7 @@ public class DocumentFileManager extends AbstractMediaFileManager {
return ext; return ext;
} }
public void download() throws RpcErrorException, IOException { public void download() throws RpcErrorException, IOException, TimeoutException {
if (doc!=null) { if (doc!=null) {
DownloadManager.downloadFile(client, getTargetPathAndFilename(), getSize(), doc.getDcId(), doc.getId(), doc.getAccessHash()); DownloadManager.downloadFile(client, getTargetPathAndFilename(), getSize(), doc.getDcId(), doc.getId(), doc.getAccessHash());
} }

View File

@ -76,7 +76,7 @@ public class PhotoFileManager extends AbstractMediaFileManager {
public String getExtension() { return "jpg"; } public String getExtension() { return "jpg"; }
public void download() throws RpcErrorException, IOException { public void download() throws RpcErrorException, IOException, TimeoutException {
if (isEmpty) return; if (isEmpty) return;
TLFileLocation loc = (TLFileLocation) size.getLocation(); TLFileLocation loc = (TLFileLocation) size.getLocation();
DownloadManager.downloadFile(client, getTargetPathAndFilename(), getSize(), loc.getDcId(), loc.getVolumeId(), loc.getLocalId(), loc.getSecret()); DownloadManager.downloadFile(client, getTargetPathAndFilename(), getSize(), loc.getDcId(), loc.getVolumeId(), loc.getLocalId(), loc.getSecret());

View File

@ -88,7 +88,7 @@ public class StickerFileManager extends DocumentFileManager {
return path; return path;
} }
public void download() throws RpcErrorException, IOException { public void download() throws RpcErrorException, IOException, TimeoutException {
String old_file = Config.FILE_BASE + File.separatorChar + Config.FILE_STICKER_BASE + File.separatorChar + getTargetFilename(); String old_file = Config.FILE_BASE + File.separatorChar + Config.FILE_STICKER_BASE + File.separatorChar + getTargetFilename();
logger.trace("Old filename exists: {}", new File(old_file).exists()); logger.trace("Old filename exists: {}", new File(old_file).exists());