|
|
|
|
@ -1,5 +1,7 @@ |
|
|
|
|
package com.fongmi.android.tv.model; |
|
|
|
|
|
|
|
|
|
import android.text.TextUtils; |
|
|
|
|
|
|
|
|
|
import androidx.lifecycle.MutableLiveData; |
|
|
|
|
import androidx.lifecycle.ViewModel; |
|
|
|
|
|
|
|
|
|
@ -12,6 +14,7 @@ import com.fongmi.android.tv.utils.Utils; |
|
|
|
|
import com.github.catvod.crawler.Spider; |
|
|
|
|
import com.github.catvod.crawler.SpiderDebug; |
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.concurrent.Callable; |
|
|
|
|
@ -19,8 +22,6 @@ import java.util.concurrent.ExecutorService; |
|
|
|
|
import java.util.concurrent.Executors; |
|
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
|
|
import okhttp3.HttpUrl; |
|
|
|
|
|
|
|
|
|
public class SiteViewModel extends ViewModel { |
|
|
|
|
|
|
|
|
|
public MutableLiveData<Result> result; |
|
|
|
|
@ -52,8 +53,17 @@ public class SiteViewModel extends ViewModel { |
|
|
|
|
} else { |
|
|
|
|
String body = OKHttp.newCall(home.getApi()).execute().body().string(); |
|
|
|
|
SpiderDebug.log(body); |
|
|
|
|
if (home.getType() == 0) return Result.fromXml(body); |
|
|
|
|
else return Result.fromJson(body); |
|
|
|
|
Result result = home.getType() == 0 ? Result.fromXml(body) : Result.fromJson(body); |
|
|
|
|
if (result.getList().isEmpty() || result.getList().get(0).getVodPic().length() > 0) return result; |
|
|
|
|
ArrayList<String> ids = new ArrayList<>(); |
|
|
|
|
for (Vod item : result.getList()) ids.add(item.getVodId()); |
|
|
|
|
HashMap<String, String> params = new HashMap<>(); |
|
|
|
|
params.put("ac", home.getType() == 0 ? "videolist" : "detail"); |
|
|
|
|
params.put("ids", TextUtils.join(",", ids)); |
|
|
|
|
body = OKHttp.newCall(home.getApi(), params).execute().body().string(); |
|
|
|
|
List<Vod> items = home.getType() == 0 ? Result.fromXml(body).getList() : Result.fromJson(body).getList(); |
|
|
|
|
result.setList(items); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
@ -67,11 +77,13 @@ public class SiteViewModel extends ViewModel { |
|
|
|
|
SpiderDebug.log(categoryContent); |
|
|
|
|
return Result.fromJson(categoryContent); |
|
|
|
|
} else { |
|
|
|
|
HttpUrl url = HttpUrl.parse(home.getApi()).newBuilder().addQueryParameter("ac", home.getType() == 0 ? "videolist" : "detail").addQueryParameter("t", tid).addQueryParameter("pg", page).build(); |
|
|
|
|
String body = OKHttp.newCall(url).execute().body().string(); |
|
|
|
|
HashMap<String, String> params = new HashMap<>(); |
|
|
|
|
params.put("ac", home.getType() == 0 ? "videolist" : "detail"); |
|
|
|
|
params.put("t", tid); |
|
|
|
|
params.put("pg", page); |
|
|
|
|
String body = OKHttp.newCall(home.getApi(), params).execute().body().string(); |
|
|
|
|
SpiderDebug.log(body); |
|
|
|
|
if (home.getType() == 0) return Result.fromXml(body); |
|
|
|
|
else return Result.fromJson(body); |
|
|
|
|
return home.getType() == 0 ? Result.fromXml(body) : Result.fromJson(body); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
@ -87,12 +99,12 @@ public class SiteViewModel extends ViewModel { |
|
|
|
|
if (!result.getList().isEmpty()) result.getList().get(0).setVodFlags(); |
|
|
|
|
return result; |
|
|
|
|
} else { |
|
|
|
|
HttpUrl url = HttpUrl.parse(site.getApi()).newBuilder().addQueryParameter("ac", site.getType() == 0 ? "videolist" : "detail").addQueryParameter("ids", id).build(); |
|
|
|
|
String body = OKHttp.newCall(url).execute().body().string(); |
|
|
|
|
HashMap<String, String> params = new HashMap<>(); |
|
|
|
|
params.put("ac", site.getType() == 0 ? "videolist" : "detail"); |
|
|
|
|
params.put("ids", id); |
|
|
|
|
String body = OKHttp.newCall(site.getApi(), params).execute().body().string(); |
|
|
|
|
SpiderDebug.log(body); |
|
|
|
|
Result result; |
|
|
|
|
if (site.getType() == 0) result = Result.fromXml(body); |
|
|
|
|
else result = Result.fromJson(body); |
|
|
|
|
Result result = site.getType() == 0 ? Result.fromXml(body) : Result.fromJson(body); |
|
|
|
|
if (!result.getList().isEmpty()) result.getList().get(0).setVodFlags(); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
@ -129,9 +141,10 @@ public class SiteViewModel extends ViewModel { |
|
|
|
|
SpiderDebug.log(searchContent); |
|
|
|
|
postSearch(site, Result.fromJson(searchContent)); |
|
|
|
|
} else { |
|
|
|
|
HttpUrl.Builder builder = HttpUrl.parse(site.getApi()).newBuilder().addQueryParameter("wd", keyword); |
|
|
|
|
if (site.getType() == 1) builder.addQueryParameter("ac", "detail"); |
|
|
|
|
String body = OKHttp.newCall(builder.build()).execute().body().string(); |
|
|
|
|
HashMap<String, String> params = new HashMap<>(); |
|
|
|
|
if (site.getType() == 1) params.put("ac", "detail"); |
|
|
|
|
params.put("wd", keyword); |
|
|
|
|
String body = OKHttp.newCall(site.getApi(), params).execute().body().string(); |
|
|
|
|
SpiderDebug.log(body); |
|
|
|
|
if (site.getType() == 0) postSearch(site, Result.fromXml(body)); |
|
|
|
|
else postSearch(site, Result.fromJson(body)); |
|
|
|
|
|