mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-25 17:40:33 +00:00
Use OkHttp with UIL
This commit is contained in:
parent
72a9940863
commit
a2373b817a
@ -168,6 +168,7 @@ public class App extends Application {
|
|||||||
return new ImageLoaderConfiguration.Builder(this)
|
return new ImageLoaderConfiguration.Builder(this)
|
||||||
.memoryCache(new LRULimitedMemoryCache(memoryCacheSizeMb * 1024 * 1024))
|
.memoryCache(new LRULimitedMemoryCache(memoryCacheSizeMb * 1024 * 1024))
|
||||||
.diskCacheSize(diskCacheSizeMb * 1024 * 1024)
|
.diskCacheSize(diskCacheSizeMb * 1024 * 1024)
|
||||||
|
.imageDownloader(new ImageDownloader(getApplicationContext()))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import android.text.TextUtils;
|
|||||||
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
|
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -98,6 +99,18 @@ public class Downloader implements org.schabi.newpipe.extractor.Downloader {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String download(String siteUrl, Map<String, String> customProperties) throws IOException, ReCaptchaException {
|
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()
|
final Request.Builder requestBuilder = new Request.Builder()
|
||||||
.method("GET", null).url(siteUrl)
|
.method("GET", null).url(siteUrl)
|
||||||
.addHeader("User-Agent", USER_AGENT);
|
.addHeader("User-Agent", USER_AGENT);
|
||||||
@ -123,7 +136,7 @@ public class Downloader implements org.schabi.newpipe.extractor.Downloader {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return body.string();
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
25
app/src/main/java/org/schabi/newpipe/ImageDownloader.java
Normal file
25
app/src/main/java/org/schabi/newpipe/ImageDownloader.java
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user