Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Weblate 2018-02-23 18:48:55 +01:00
commit c5d49016d4
3 changed files with 40 additions and 1 deletions

View File

@ -168,6 +168,7 @@ public class App extends Application {
return new ImageLoaderConfiguration.Builder(this)
.memoryCache(new LRULimitedMemoryCache(memoryCacheSizeMb * 1024 * 1024))
.diskCacheSize(diskCacheSizeMb * 1024 * 1024)
.imageDownloader(new ImageDownloader(getApplicationContext()))
.build();
}

View File

@ -6,6 +6,7 @@ import android.text.TextUtils;
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@ -98,6 +99,18 @@ public class Downloader implements org.schabi.newpipe.extractor.Downloader {
*/
@Override
public String download(String siteUrl, Map<String, String> customProperties) throws IOException, ReCaptchaException {
return getBody(siteUrl, customProperties).string();
}
public InputStream stream(String siteUrl) throws IOException {
try {
return getBody(siteUrl, Collections.emptyMap()).byteStream();
} catch (ReCaptchaException e) {
throw new IOException(e.getMessage(), e.getCause());
}
}
private ResponseBody getBody(String siteUrl, Map<String, String> customProperties) throws IOException, ReCaptchaException {
final Request.Builder requestBuilder = new Request.Builder()
.method("GET", null).url(siteUrl)
.addHeader("User-Agent", USER_AGENT);
@ -123,7 +136,7 @@ public class Downloader implements org.schabi.newpipe.extractor.Downloader {
return null;
}
return body.string();
return body;
}
/**

View File

@ -0,0 +1,25 @@
package org.schabi.newpipe;
import android.content.Context;
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
import org.schabi.newpipe.extractor.NewPipe;
import java.io.IOException;
import java.io.InputStream;
public class ImageDownloader extends BaseImageDownloader {
public ImageDownloader(Context context) {
super(context);
}
public ImageDownloader(Context context, int connectTimeout, int readTimeout) {
super(context, connectTimeout, readTimeout);
}
protected InputStream getStreamFromNetwork(String imageUri, Object extra) throws IOException {
Downloader downloader = (Downloader) NewPipe.getDownloader();
return downloader.stream(imageUri);
}
}