mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-24 09:00:31 +00:00
misc changes
* implement socket timeout error * use 128k buffer size for copy * use NewPipe HTTP user agent in the downloads * automatically recover downloads with network errors that are queued
This commit is contained in:
parent
16d6bda85d
commit
d1573a0a6e
@ -28,7 +28,7 @@ public class DownloadInitializer extends Thread {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (mMission.current > 0) mMission.resetState(false,true, DownloadMission.ERROR_NOTHING);
|
if (mMission.current > 0) mMission.resetState(false, true, DownloadMission.ERROR_NOTHING);
|
||||||
|
|
||||||
int retryCount = 0;
|
int retryCount = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -4,11 +4,14 @@ import android.os.Handler;
|
|||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import org.schabi.newpipe.Downloader;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.ConnectException;
|
import java.net.ConnectException;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.SocketTimeoutException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -45,6 +48,7 @@ public class DownloadMission extends Mission {
|
|||||||
public static final int ERROR_POSTPROCESSING_HOLD = 1009;
|
public static final int ERROR_POSTPROCESSING_HOLD = 1009;
|
||||||
public static final int ERROR_INSUFFICIENT_STORAGE = 1010;
|
public static final int ERROR_INSUFFICIENT_STORAGE = 1010;
|
||||||
public static final int ERROR_PROGRESS_LOST = 1011;
|
public static final int ERROR_PROGRESS_LOST = 1011;
|
||||||
|
public static final int ERROR_TIMEOUT = 1012;
|
||||||
public static final int ERROR_HTTP_NO_CONTENT = 204;
|
public static final int ERROR_HTTP_NO_CONTENT = 204;
|
||||||
public static final int ERROR_HTTP_UNSUPPORTED_RANGE = 206;
|
public static final int ERROR_HTTP_UNSUPPORTED_RANGE = 206;
|
||||||
|
|
||||||
@ -232,10 +236,9 @@ public class DownloadMission extends Mission {
|
|||||||
URL url = new URL(urls[current]);
|
URL url = new URL(urls[current]);
|
||||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||||
conn.setInstanceFollowRedirects(true);
|
conn.setInstanceFollowRedirects(true);
|
||||||
|
conn.setRequestProperty("User-Agent", Downloader.USER_AGENT);
|
||||||
|
|
||||||
// BUG workaround: switching between networks can freeze the download forever
|
// BUG workaround: switching between networks can freeze the download forever
|
||||||
|
|
||||||
//conn.setRequestProperty("Connection", "close");
|
|
||||||
conn.setConnectTimeout(30000);
|
conn.setConnectTimeout(30000);
|
||||||
conn.setReadTimeout(10000);
|
conn.setReadTimeout(10000);
|
||||||
|
|
||||||
@ -329,6 +332,8 @@ public class DownloadMission extends Mission {
|
|||||||
notifyError(ERROR_CONNECT_HOST, null);
|
notifyError(ERROR_CONNECT_HOST, null);
|
||||||
} else if (err instanceof UnknownHostException) {
|
} else if (err instanceof UnknownHostException) {
|
||||||
notifyError(ERROR_UNKNOWN_HOST, null);
|
notifyError(ERROR_UNKNOWN_HOST, null);
|
||||||
|
} else if (err instanceof SocketTimeoutException) {
|
||||||
|
notifyError(ERROR_TIMEOUT, null);
|
||||||
} else {
|
} else {
|
||||||
notifyError(ERROR_UNKNOWN_EXCEPTION, err);
|
notifyError(ERROR_UNKNOWN_EXCEPTION, err);
|
||||||
}
|
}
|
||||||
@ -338,7 +343,7 @@ public class DownloadMission extends Mission {
|
|||||||
Log.e(TAG, "notifyError() code = " + code, err);
|
Log.e(TAG, "notifyError() code = " + code, err);
|
||||||
|
|
||||||
if (err instanceof IOException) {
|
if (err instanceof IOException) {
|
||||||
if (storage.canWrite() || err.getMessage().contains("Permission denied")) {
|
if (!storage.canWrite() || err.getMessage().contains("Permission denied")) {
|
||||||
code = ERROR_PERMISSION_DENIED;
|
code = ERROR_PERMISSION_DENIED;
|
||||||
err = null;
|
err = null;
|
||||||
} else if (err.getMessage().contains("ENOSPC")) {
|
} else if (err.getMessage().contains("ENOSPC")) {
|
||||||
@ -349,7 +354,19 @@ public class DownloadMission extends Mission {
|
|||||||
|
|
||||||
errCode = code;
|
errCode = code;
|
||||||
errObject = err;
|
errObject = err;
|
||||||
enqueued = false;
|
|
||||||
|
switch (code) {
|
||||||
|
case ERROR_SSL_EXCEPTION:
|
||||||
|
case ERROR_UNKNOWN_HOST:
|
||||||
|
case ERROR_CONNECT_HOST:
|
||||||
|
case ERROR_TIMEOUT:
|
||||||
|
// do not change the queue flag for network errors, can be
|
||||||
|
// recovered silently without the user interaction
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// also checks for server errors
|
||||||
|
if (code < 500 || code > 599) enqueued = false;
|
||||||
|
}
|
||||||
|
|
||||||
pause();
|
pause();
|
||||||
|
|
||||||
|
@ -27,7 +27,6 @@ public class DownloadRunnable extends Thread {
|
|||||||
if (mission == null) throw new NullPointerException("mission is null");
|
if (mission == null) throw new NullPointerException("mission is null");
|
||||||
mMission = mission;
|
mMission = mission;
|
||||||
mId = id;
|
mId = id;
|
||||||
mConn = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package us.shandian.giga.get;
|
package us.shandian.giga.get;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@ -19,7 +18,7 @@ import static org.schabi.newpipe.BuildConfig.DEBUG;
|
|||||||
* Single-threaded fallback mode
|
* Single-threaded fallback mode
|
||||||
*/
|
*/
|
||||||
public class DownloadRunnableFallback extends Thread {
|
public class DownloadRunnableFallback extends Thread {
|
||||||
private static final String TAG = "DownloadRunnableFallback";
|
private static final String TAG = "DownloadRunnableFallbac";
|
||||||
|
|
||||||
private final DownloadMission mMission;
|
private final DownloadMission mMission;
|
||||||
|
|
||||||
@ -30,9 +29,6 @@ public class DownloadRunnableFallback extends Thread {
|
|||||||
|
|
||||||
DownloadRunnableFallback(@NonNull DownloadMission mission) {
|
DownloadRunnableFallback(@NonNull DownloadMission mission) {
|
||||||
mMission = mission;
|
mMission = mission;
|
||||||
mIs = null;
|
|
||||||
mF = null;
|
|
||||||
mConn = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dispose() {
|
private void dispose() {
|
||||||
@ -46,7 +42,6 @@ public class DownloadRunnableFallback extends Thread {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressLint("LongLogTag")
|
|
||||||
public void run() {
|
public void run() {
|
||||||
boolean done;
|
boolean done;
|
||||||
|
|
||||||
@ -106,6 +101,10 @@ public class DownloadRunnableFallback extends Thread {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (DEBUG) {
|
||||||
|
Log.e(TAG, "got exception, retrying...", e);
|
||||||
|
}
|
||||||
|
|
||||||
run();// try again
|
run();// try again
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import java.io.IOException;
|
|||||||
public class CircularFileWriter extends SharpStream {
|
public class CircularFileWriter extends SharpStream {
|
||||||
|
|
||||||
private final static int QUEUE_BUFFER_SIZE = 8 * 1024;// 8 KiB
|
private final static int QUEUE_BUFFER_SIZE = 8 * 1024;// 8 KiB
|
||||||
|
private final static int COPY_BUFFER_SIZE = 128 * 1024; // 128 KiB
|
||||||
private final static int NOTIFY_BYTES_INTERVAL = 64 * 1024;// 64 KiB
|
private final static int NOTIFY_BYTES_INTERVAL = 64 * 1024;// 64 KiB
|
||||||
private final static int THRESHOLD_AUX_LENGTH = 15 * 1024 * 1024;// 15 MiB
|
private final static int THRESHOLD_AUX_LENGTH = 15 * 1024 * 1024;// 15 MiB
|
||||||
|
|
||||||
@ -53,6 +54,7 @@ public class CircularFileWriter extends SharpStream {
|
|||||||
aux.flush();
|
aux.flush();
|
||||||
|
|
||||||
boolean underflow = aux.offset < aux.length || out.offset < out.length;
|
boolean underflow = aux.offset < aux.length || out.offset < out.length;
|
||||||
|
byte[] buffer = new byte[COPY_BUFFER_SIZE];
|
||||||
|
|
||||||
aux.target.seek(0);
|
aux.target.seek(0);
|
||||||
out.target.seek(out.length);
|
out.target.seek(out.length);
|
||||||
@ -60,14 +62,14 @@ public class CircularFileWriter extends SharpStream {
|
|||||||
long length = amount;
|
long length = amount;
|
||||||
while (length > 0) {
|
while (length > 0) {
|
||||||
int read = (int) Math.min(length, Integer.MAX_VALUE);
|
int read = (int) Math.min(length, Integer.MAX_VALUE);
|
||||||
read = aux.target.read(aux.queue, 0, Math.min(read, aux.queue.length));
|
read = aux.target.read(buffer, 0, Math.min(read, buffer.length));
|
||||||
|
|
||||||
if (read < 1) {
|
if (read < 1) {
|
||||||
amount -= length;
|
amount -= length;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
out.writeProof(aux.queue, read);
|
out.writeProof(buffer, read);
|
||||||
length -= read;
|
length -= read;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +102,6 @@ public class CircularFileWriter extends SharpStream {
|
|||||||
// move the excess data to the beginning of the file
|
// move the excess data to the beginning of the file
|
||||||
long readOffset = amount;
|
long readOffset = amount;
|
||||||
long writeOffset = 0;
|
long writeOffset = 0;
|
||||||
byte[] buffer = new byte[128 * 1024]; // 128 KiB
|
|
||||||
|
|
||||||
aux.length -= amount;
|
aux.length -= amount;
|
||||||
length = aux.length;
|
length = aux.length;
|
||||||
|
@ -73,6 +73,7 @@ import static us.shandian.giga.get.DownloadMission.ERROR_POSTPROCESSING_HOLD;
|
|||||||
import static us.shandian.giga.get.DownloadMission.ERROR_POSTPROCESSING_STOPPED;
|
import static us.shandian.giga.get.DownloadMission.ERROR_POSTPROCESSING_STOPPED;
|
||||||
import static us.shandian.giga.get.DownloadMission.ERROR_PROGRESS_LOST;
|
import static us.shandian.giga.get.DownloadMission.ERROR_PROGRESS_LOST;
|
||||||
import static us.shandian.giga.get.DownloadMission.ERROR_SSL_EXCEPTION;
|
import static us.shandian.giga.get.DownloadMission.ERROR_SSL_EXCEPTION;
|
||||||
|
import static us.shandian.giga.get.DownloadMission.ERROR_TIMEOUT;
|
||||||
import static us.shandian.giga.get.DownloadMission.ERROR_UNKNOWN_EXCEPTION;
|
import static us.shandian.giga.get.DownloadMission.ERROR_UNKNOWN_EXCEPTION;
|
||||||
import static us.shandian.giga.get.DownloadMission.ERROR_UNKNOWN_HOST;
|
import static us.shandian.giga.get.DownloadMission.ERROR_UNKNOWN_HOST;
|
||||||
|
|
||||||
@ -487,6 +488,9 @@ public class MissionAdapter extends Adapter<ViewHolder> {
|
|||||||
case ERROR_PROGRESS_LOST:
|
case ERROR_PROGRESS_LOST:
|
||||||
msg = R.string.error_progress_lost;
|
msg = R.string.error_progress_lost;
|
||||||
break;
|
break;
|
||||||
|
case ERROR_TIMEOUT:
|
||||||
|
msg = R.string.error_timeout;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
if (mission.errCode >= 100 && mission.errCode < 600) {
|
if (mission.errCode >= 100 && mission.errCode < 600) {
|
||||||
msgEx = "HTTP " + mission.errCode;
|
msgEx = "HTTP " + mission.errCode;
|
||||||
|
@ -472,4 +472,5 @@
|
|||||||
<string name="pause_downloads_on_mobile_desc">Downloads, die nicht pausiert werden können, werden wiederholt</string>
|
<string name="pause_downloads_on_mobile_desc">Downloads, die nicht pausiert werden können, werden wiederholt</string>
|
||||||
<string name="conferences">Konferenzen</string>
|
<string name="conferences">Konferenzen</string>
|
||||||
<string name="events">Ereignisse</string>
|
<string name="events">Ereignisse</string>
|
||||||
|
<string name="error_timeout">Verbindungszeitüberschreitung</string>
|
||||||
</resources>
|
</resources>
|
@ -457,6 +457,7 @@ abrir en modo popup</string>
|
|||||||
<string name="error_postprocessing_stopped">NewPipe se cerro mientras se trabajaba en el archivo</string>
|
<string name="error_postprocessing_stopped">NewPipe se cerro mientras se trabajaba en el archivo</string>
|
||||||
<string name="error_insufficient_storage">No hay suficiente espacio disponible en el dispositivo</string>
|
<string name="error_insufficient_storage">No hay suficiente espacio disponible en el dispositivo</string>
|
||||||
<string name="error_progress_lost">Se perdió el progreso porque el archivo fue eliminado</string>
|
<string name="error_progress_lost">Se perdió el progreso porque el archivo fue eliminado</string>
|
||||||
|
<string name="error_timeout">Tiempo de espera excedido</string>
|
||||||
|
|
||||||
<string name="downloads_storage">API de almacenamiento</string>
|
<string name="downloads_storage">API de almacenamiento</string>
|
||||||
<string name="downloads_storage_desc">Seleccione que API utilizar para almacenar las descargas</string>
|
<string name="downloads_storage_desc">Seleccione que API utilizar para almacenar las descargas</string>
|
||||||
|
@ -468,4 +468,5 @@
|
|||||||
<string name="max_retry_desc">Deskarga ezeztatu aurretik saiatu beharreko aldi kopurua</string>
|
<string name="max_retry_desc">Deskarga ezeztatu aurretik saiatu beharreko aldi kopurua</string>
|
||||||
<string name="pause_downloads_on_mobile">Pausatu datu mugikorretara aldatzean</string>
|
<string name="pause_downloads_on_mobile">Pausatu datu mugikorretara aldatzean</string>
|
||||||
<string name="pause_downloads_on_mobile_desc">Pausatu ezin daitezkeen deskargak berrekingo dira</string>
|
<string name="pause_downloads_on_mobile_desc">Pausatu ezin daitezkeen deskargak berrekingo dira</string>
|
||||||
|
<string name="error_timeout">Konexioaren denbora muga</string>
|
||||||
</resources>
|
</resources>
|
@ -440,6 +440,7 @@
|
|||||||
<string name="missions_header_pending">Dans la file d\'attente</string>
|
<string name="missions_header_pending">Dans la file d\'attente</string>
|
||||||
<string name="paused">En pause</string>
|
<string name="paused">En pause</string>
|
||||||
<string name="download_failed">Téléchargement échoué</string>
|
<string name="download_failed">Téléchargement échoué</string>
|
||||||
|
<string name="error_timeout">Délai de connection dépassé</string>
|
||||||
<string name="conferences">Conférences</string>
|
<string name="conferences">Conférences</string>
|
||||||
<string name="download_finished">Téléchargement terminé</string>
|
<string name="download_finished">Téléchargement terminé</string>
|
||||||
<string name="download_finished_more">%s téléchargements terminés</string>
|
<string name="download_finished_more">%s téléchargements terminés</string>
|
||||||
|
@ -473,4 +473,5 @@
|
|||||||
<string name="pause_downloads_on_mobile_desc">I download che non possono essere messi in pausa verranno riavviati</string>
|
<string name="pause_downloads_on_mobile_desc">I download che non possono essere messi in pausa verranno riavviati</string>
|
||||||
<string name="events">Eventi</string>
|
<string name="events">Eventi</string>
|
||||||
<string name="conferences">Conferenze</string>
|
<string name="conferences">Conferenze</string>
|
||||||
|
<string name="error_timeout">Connesione finita</string>
|
||||||
</resources>
|
</resources>
|
@ -464,4 +464,6 @@
|
|||||||
<string name="msg_pending_downloads">ダウンロードから %s の保留中の転送を続行します</string>
|
<string name="msg_pending_downloads">ダウンロードから %s の保留中の転送を続行します</string>
|
||||||
<string name="pause_downloads_on_mobile">モバイルデータ通信に切り替え時に休止</string>
|
<string name="pause_downloads_on_mobile">モバイルデータ通信に切り替え時に休止</string>
|
||||||
<string name="pause_downloads_on_mobile_desc">休止できないダウンロードが再開されます</string>
|
<string name="pause_downloads_on_mobile_desc">休止できないダウンロードが再開されます</string>
|
||||||
|
<string name="missions_header_pending">保留中</string>
|
||||||
|
<string name="error_timeout">接続タイムアウト</string>
|
||||||
</resources>
|
</resources>
|
@ -473,4 +473,5 @@
|
|||||||
<string name="pause_downloads_on_mobile_desc">Downloads die niet kunnen worden gepauzeerd zullen worden herstart</string>
|
<string name="pause_downloads_on_mobile_desc">Downloads die niet kunnen worden gepauzeerd zullen worden herstart</string>
|
||||||
<string name="events">Gebeurtenissen</string>
|
<string name="events">Gebeurtenissen</string>
|
||||||
<string name="conferences">Conferenties</string>
|
<string name="conferences">Conferenties</string>
|
||||||
|
<string name="error_timeout">Time-out van verbinding</string>
|
||||||
</resources>
|
</resources>
|
@ -473,4 +473,5 @@
|
|||||||
<string name="pause_downloads_on_mobile">Останавливать скачивание при переходе на мобильную сеть</string>
|
<string name="pause_downloads_on_mobile">Останавливать скачивание при переходе на мобильную сеть</string>
|
||||||
<string name="close">Закрыть</string>
|
<string name="close">Закрыть</string>
|
||||||
<string name="missions_header_pending">в ожидании</string>
|
<string name="missions_header_pending">в ожидании</string>
|
||||||
|
<string name="error_timeout">Время соединения вышло</string>
|
||||||
</resources>
|
</resources>
|
@ -469,4 +469,5 @@
|
|||||||
<string name="pause_downloads_on_mobile_desc">無法暫停的下載將會重新開始</string>
|
<string name="pause_downloads_on_mobile_desc">無法暫停的下載將會重新開始</string>
|
||||||
<string name="events">事件</string>
|
<string name="events">事件</string>
|
||||||
<string name="conferences">會議</string>
|
<string name="conferences">會議</string>
|
||||||
|
<string name="error_timeout">連接超時</string>
|
||||||
</resources>
|
</resources>
|
@ -534,6 +534,7 @@
|
|||||||
<string name="error_postprocessing_stopped">NewPipe was closed while working on the file</string>
|
<string name="error_postprocessing_stopped">NewPipe was closed while working on the file</string>
|
||||||
<string name="error_insufficient_storage">No space left on device</string>
|
<string name="error_insufficient_storage">No space left on device</string>
|
||||||
<string name="error_progress_lost">Progress lost, because the file was deleted</string>
|
<string name="error_progress_lost">Progress lost, because the file was deleted</string>
|
||||||
|
<string name="error_timeout">Connection timeout</string>
|
||||||
|
|
||||||
<string name="clear_finished_download">Clear finished downloads</string>
|
<string name="clear_finished_download">Clear finished downloads</string>
|
||||||
<string name="confirm_prompt">Are you sure?</string>
|
<string name="confirm_prompt">Are you sure?</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user