修正部分图片不显示的问题;

pull/97/head
21561 3 years ago
parent fdc44e2ce8
commit 3e6c42200a
  1. 34
      app/src/main/java/com/github/tvbox/osc/picasso/MyOkhttpDownLoader.java
  2. 6
      app/src/main/java/com/github/tvbox/osc/ui/fragment/GridFragment.java
  3. 144
      app/src/main/java/com/github/tvbox/osc/util/thunder/Thunder.java
  4. 8
      app/src/main/java/com/github/tvbox/osc/viewmodel/SourceViewModel.java

@ -20,11 +20,13 @@ import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import com.github.tvbox.osc.util.UA;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.squareup.picasso.Downloader;
import java.io.IOException;
import java.net.URL;
import java.net.URLDecoder;
import okhttp3.Cache;
@ -63,14 +65,16 @@ public final class MyOkhttpDownLoader implements Downloader {
@Override
public Response load(@NonNull Request request) throws IOException {
String url = request.url().toString();
url= URLDecoder.decode(url);
String header = null;
String cookie = null;
String ua = null;
String referer = null;
//检查链接里面是否有自定义header
if (url.contains("@Headers=")) header =url.split("@Headers=")[1].split("@")[0];
if (url.contains("@Headers=")){
header =url.split("@Headers=")[1].split("@")[0];
header =URLDecoder.decode(header,"UTF-8");
}
if (url.contains("@Cookie=")) cookie= url.split("@Cookie=")[1].split("@")[0];
if (url.contains("@User-Agent=")) ua =url.split("@User-Agent=")[1].split("@")[0];
if (url.contains("@Referer=")) referer= url.split("@Referer=")[1].split("@")[0];
@ -81,17 +85,33 @@ public final class MyOkhttpDownLoader implements Downloader {
JsonObject jsonInfo = new Gson().fromJson(header, JsonObject.class);
for (String key : jsonInfo.keySet()) {
String val = jsonInfo.get(key).getAsString();
mRequestBuilder.addHeader(key, val);
mRequestBuilder.addHeader(key.toUpperCase(), removeDuplicateSlashes(val));
}
}else {
if(!TextUtils.isEmpty(cookie))mRequestBuilder.addHeader("Cookie", cookie);
if(!TextUtils.isEmpty(ua))mRequestBuilder.addHeader("User-Agent", ua);
if(!TextUtils.isEmpty(referer))mRequestBuilder.addHeader("Referer", referer);
if(!TextUtils.isEmpty(cookie)) {
assert cookie != null;
mRequestBuilder.addHeader("Cookie", cookie);
}
if(!TextUtils.isEmpty(ua)){
assert ua != null;
mRequestBuilder.addHeader("User-Agent", ua);
}else {
mRequestBuilder.addHeader("User-Agent", UA.randomOne());
}
if(!TextUtils.isEmpty(referer)){
assert referer != null;
mRequestBuilder.addHeader("Referer", referer);
}
}
URL imgUrl = new URL(url);
String host = imgUrl.getHost();
mRequestBuilder.addHeader("Host", host);
return client.newCall(mRequestBuilder.build()).execute();
}
private static String removeDuplicateSlashes(String paramValue) {
return paramValue.replaceAll("//", "/");
}
@Override
public void shutdown() {
if (!sharedClient && cache != null) {

@ -261,10 +261,10 @@ public class GridFragment extends BaseLazyFragment {
page++;
maxPage = absXml.movie.pagecount;
if (page > maxPage) {
if (maxPage>0 && page > maxPage) {
gridAdapter.loadMoreEnd();
gridAdapter.setEnableLoadMore(false);
if(page>2)Toast.makeText(getContext(), "没有更多了", Toast.LENGTH_SHORT).show();
if(page>2)Toast.makeText(getContext(), "到底啦", Toast.LENGTH_SHORT).show();
} else {
gridAdapter.loadMoreComplete();
gridAdapter.setEnableLoadMore(true);
@ -273,7 +273,7 @@ public class GridFragment extends BaseLazyFragment {
if(page == 1){
showEmpty();
}else{
Toast.makeText(getContext(), "没有更多了", Toast.LENGTH_SHORT).show();
Toast.makeText(getContext(), "到底啦", Toast.LENGTH_SHORT).show();
gridAdapter.loadMoreEnd();
}
gridAdapter.setEnableLoadMore(false);

@ -15,6 +15,7 @@ import com.xunlei.downloadlib.parameter.XLTaskInfo;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@ -89,93 +90,86 @@ public class Thunder {
void play(String url);
}
public static void parse(Context context, String url, ThunderCallback callback) {
public static void parse(Context context, List<String> urlList, ThunderCallback callback) {
init(context);
stop(true);
threadPool = Executors.newSingleThreadExecutor();
if (isMagnet(url) || isThunder(url)) {
String link = isThunder(url) ? XLDownloadManager.getInstance().parserThunderUrl(url) : url;
Uri p = Uri.parse(link);
if (p == null) {
callback.status(-1, "链接错误");
return;
}
String fileName = XLTaskHelper.instance().getFileName(link);
File cache = new File(cacheRoot + File.separator + fileName);
threadPool.execute(new Runnable() {
@Override
public void run() {
try {
currentTask = isMagnet(url) ?
XLTaskHelper.instance().addMagentTask(url, cacheRoot, fileName) :
XLTaskHelper.instance().addThunderTask(url, cacheRoot, fileName);
} catch (Exception exception) {
exception.printStackTrace();
currentTask = 0;
}
if (currentTask <= 0) {
callback.status(-1, "链接错误");
return;
}
int count = 30;
while (true) {
count--;
if (count <= 0) {
callback.status(-1, "解析超时");
break;
ArrayList<String> playList = new ArrayList<>();
torrentFileInfoArrayList=new ArrayList<>();
threadPool.execute(new Runnable() {
@Override
public void run() {
for (String url : urlList) {
if (isMagnet(url) || isThunder(url) || isTorrent(url)) {
String link = isThunder(url) ? XLDownloadManager.getInstance().parserThunderUrl(url) : url;
Uri p = Uri.parse(link);
if (p == null) {
continue;
}
XLTaskInfo taskInfo = XLTaskHelper.instance().getTaskInfo(currentTask);
switch (taskInfo.mTaskStatus) {
case 2: {
callback.status(0, "正在获取文件列表...");
try {
TorrentInfo torrentInfo = XLTaskHelper.instance().getTorrentInfo(cache.getAbsolutePath());
if (torrentInfo == null || TextUtils.isEmpty(torrentInfo.mInfoHash)) {
callback.status(-1, "解析失败");
} else {
TorrentFileInfo[] mSubFileInfo = torrentInfo.mSubFileInfo;
ArrayList<String> playList = new ArrayList<>();
ArrayList<TorrentFileInfo> list = new ArrayList<>();
if (mSubFileInfo != null && mSubFileInfo.length >= 0) {
for (TorrentFileInfo sub : mSubFileInfo) {
if (isMedia(sub.mFileName)) {
sub.torrentPath = cache.getAbsolutePath();
playList.add(sub.mFileName + "$tvbox-torrent:" + list.size());
list.add(sub);
String fileName = XLTaskHelper.instance().getFileName(link);
File cache = new File(cacheRoot + File.separator + fileName);
try {
currentTask = isMagnet(url) ?
XLTaskHelper.instance().addMagentTask(url, cacheRoot, fileName) :
XLTaskHelper.instance().addThunderTask(url, cacheRoot, fileName);
} catch (Exception exception) {
exception.printStackTrace();
currentTask = 0;
}
if (currentTask <= 0) {
continue;
}
int count = 20;
Boolean conti=true;
while (conti) {
count--;
if (count <= 0) {
conti=false;
}
XLTaskInfo taskInfo = XLTaskHelper.instance().getTaskInfo(currentTask);
switch (taskInfo.mTaskStatus) {
case 2: {
try {
TorrentInfo torrentInfo = XLTaskHelper.instance().getTorrentInfo(cache.getAbsolutePath());
if (torrentInfo == null || TextUtils.isEmpty(torrentInfo.mInfoHash)) {
} else {
TorrentFileInfo[] mSubFileInfo = torrentInfo.mSubFileInfo;
if (mSubFileInfo != null && mSubFileInfo.length >= 0) {
for (TorrentFileInfo sub : mSubFileInfo) {
if (isMedia(sub.mFileName)) {
sub.torrentPath = cache.getAbsolutePath();
playList.add(sub.mFileName + "$tvbox-torrent:" + torrentFileInfoArrayList.size());
torrentFileInfoArrayList.add(sub);
}
}
conti=false;
}
}
if (list.size() > 0) {
torrentFileInfoArrayList = list;
callback.list(TextUtils.join("#", playList));
} else {
callback.status(-1, "文件列表为空!");
}
} catch (Throwable throwable) {
throwable.printStackTrace();
}
} catch (Throwable throwable) {
throwable.printStackTrace();
callback.status(-1, "解析失败");
}
return;
}
case 3: {
callback.status(-1, "解析失败");
return;
default: {
}
}
default: {
callback.status(0, "解析中...");
break;
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
});
}
if (playList.size() > 0) {
callback.list(TextUtils.join("#", playList));
} else {
callback.status(-1, "文件列表为空!");
}
}});
// if(isEd2k(url) || isFtp(url)){
// task_url= url;
// System.out.println("startTask:");
@ -333,7 +327,7 @@ public class Thunder {
public static boolean isSupportUrl(String url) {
// return isMagnet(url) || isThunder(url) || isEd2k(url) || isFtp(url);
return isMagnet(url) || isThunder(url);
return isMagnet(url) || isThunder(url) || isTorrent(url);
}
private static boolean isMagnet(String url) {
@ -415,7 +409,7 @@ public class Thunder {
public static boolean isNetworkDownloadTask(String url){
if(TextUtils.isEmpty(url)) return false;
if(isThunder(url)|| isFtp(url) || isEd2k(url)){
if(isFtp(url) || isEd2k(url)){
return true;
}else{
return false;

@ -845,9 +845,13 @@ public class SourceViewModel extends ViewModel {
Movie.Video video = data.movie.videoList.get(0);
if (video != null && video.urlBean != null && video.urlBean.infoList != null && video.urlBean.infoList.size() == 1) {
Movie.Video.UrlBean.UrlInfo urlInfo = video.urlBean.infoList.get(0);
if (urlInfo != null && urlInfo.beanList.size() == 1 && Thunder.isSupportUrl(urlInfo.beanList.get(0).url)) {
if (urlInfo != null && Thunder.isSupportUrl(urlInfo.beanList.get(0).url)) {
thunderParse = true;
Thunder.parse(App.getInstance(), urlInfo.beanList.get(0).url, new Thunder.ThunderCallback() {
List<String> urlList = new ArrayList<>();
for (Movie.Video.UrlBean.UrlInfo.InfoBean infoBean : urlInfo.beanList) {
urlList.add(infoBean.url);
}
Thunder.parse(App.getInstance(), urlList, new Thunder.ThunderCallback() {
@Override
public void status(int code, String info) {
if (code >= 0) {

Loading…
Cancel
Save