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

Added timeout detection to media downloads as well.

This commit is contained in:
Fabian Schlenz 2017-02-18 12:56:56 +01:00
parent e0668926c9
commit 6738e20fe4

View File

@ -319,15 +319,26 @@ public class DownloadManager {
} }
logger.trace("offset before the loop is {}", offset); logger.trace("offset before the loop is {}", offset);
fos = new FileOutputStream(temp_filename, true); fos = new FileOutputStream(temp_filename, true);
TLFile response; TLFile response = null;
boolean try_again;
do { do {
try_again = false;
int block_size = size; int block_size = size;
logger.trace("offset: {} block_size: {} size: {}", offset, block_size, size); logger.trace("offset: {} block_size: {} size: {}", offset, block_size, size);
TLRequestUploadGetFile req = new TLRequestUploadGetFile(loc, offset, block_size); TLRequestUploadGetFile req = new TLRequestUploadGetFile(loc, offset, block_size);
if (dcID==null) { try {
response = (TLFile) download_client.executeRpcQuery(req); if (dcID==null) {
} else { response = (TLFile) download_client.executeRpcQuery(req);
response = (TLFile) download_client.executeRpcQuery(req, dcID); } else {
response = (TLFile) download_client.executeRpcQuery(req, dcID);
}
} catch (RpcErrorException e) {
if (e.getTag().startsWith("420: FLOOD_WAIT_")) {
try_again = true;
Utils.obeyFloodWaitException(e);
} else {
throw e;
}
} }
offset += response.getBytes().getData().length; offset += response.getBytes().getData().length;
@ -336,7 +347,7 @@ public class DownloadManager {
fos.write(response.getBytes().getData()); fos.write(response.getBytes().getData());
fos.flush(); fos.flush();
try { TimeUnit.MILLISECONDS.sleep(Config.DELAY_AFTER_GET_FILE); } catch(InterruptedException e) {} try { TimeUnit.MILLISECONDS.sleep(Config.DELAY_AFTER_GET_FILE); } catch(InterruptedException e) {}
} while(offset < size && response.getBytes().getData().length>0); } while(offset < size && (response.getBytes().getData().length>0 || try_again));
fos.close(); fos.close();
if (offset < size) { if (offset < size) {
System.out.println("Requested file " + target + " with " + size + " bytes, but got only " + offset + " bytes."); System.out.println("Requested file " + target + " with " + size + " bytes, but got only " + offset + " bytes.");