|
|
|
|
@ -6,7 +6,6 @@ import androidx.lifecycle.ViewModel; |
|
|
|
|
import com.fongmi.bear.ApiConfig; |
|
|
|
|
import com.fongmi.bear.bean.Result; |
|
|
|
|
import com.fongmi.bear.bean.Site; |
|
|
|
|
import com.fongmi.bear.bean.Vod; |
|
|
|
|
import com.fongmi.bear.net.OKHttp; |
|
|
|
|
import com.fongmi.bear.utils.Utils; |
|
|
|
|
import com.github.catvod.crawler.Spider; |
|
|
|
|
@ -14,7 +13,6 @@ import com.github.catvod.crawler.SpiderDebug; |
|
|
|
|
import com.google.gson.JsonObject; |
|
|
|
|
import com.google.gson.JsonParser; |
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.concurrent.Callable; |
|
|
|
|
@ -42,7 +40,7 @@ public class SiteViewModel extends ViewModel { |
|
|
|
|
|
|
|
|
|
public void homeContent() { |
|
|
|
|
Site home = ApiConfig.get().getHome(); |
|
|
|
|
postResult(() -> { |
|
|
|
|
execute(result, () -> { |
|
|
|
|
if (home.getType() == 3) { |
|
|
|
|
Spider spider = ApiConfig.get().getCSP(home); |
|
|
|
|
String homeContent = spider.homeContent(false); |
|
|
|
|
@ -67,7 +65,7 @@ public class SiteViewModel extends ViewModel { |
|
|
|
|
|
|
|
|
|
public void categoryContent(String tid, String page, boolean filter, HashMap<String, String> extend) { |
|
|
|
|
Site home = ApiConfig.get().getHome(); |
|
|
|
|
postResult(() -> { |
|
|
|
|
execute(result, () -> { |
|
|
|
|
if (home.getType() == 3) { |
|
|
|
|
Spider spider = ApiConfig.get().getCSP(home); |
|
|
|
|
String categoryContent = spider.categoryContent(tid, page, filter, extend); |
|
|
|
|
@ -88,15 +86,13 @@ public class SiteViewModel extends ViewModel { |
|
|
|
|
|
|
|
|
|
public void detailContent(String id) { |
|
|
|
|
Site home = ApiConfig.get().getHome(); |
|
|
|
|
postResult(() -> { |
|
|
|
|
execute(result, () -> { |
|
|
|
|
if (home.getType() == 3) { |
|
|
|
|
Spider spider = ApiConfig.get().getCSP(home); |
|
|
|
|
String detailContent = spider.detailContent(List.of(id)); |
|
|
|
|
SpiderDebug.json(detailContent); |
|
|
|
|
Result result = Result.objectFrom(detailContent); |
|
|
|
|
if (result.getList().isEmpty()) return result; |
|
|
|
|
Vod vod = result.getList().get(0); |
|
|
|
|
vod.setVodFlags(getVodFlags(vod)); |
|
|
|
|
if (!result.getList().isEmpty()) result.getList().get(0).setVodFlags(); |
|
|
|
|
return result; |
|
|
|
|
} else { |
|
|
|
|
HttpUrl url = HttpUrl.parse(home.getApi()).newBuilder().addQueryParameter("ac", home.getType() == 0 ? "videolist" : "detail").addQueryParameter("ids", id).build(); |
|
|
|
|
@ -105,9 +101,7 @@ public class SiteViewModel extends ViewModel { |
|
|
|
|
String detailContent = response.body().string(); |
|
|
|
|
SpiderDebug.json(detailContent); |
|
|
|
|
Result result = Result.objectFrom(detailContent); |
|
|
|
|
if (result.getList().isEmpty()) return result; |
|
|
|
|
Vod vod = result.getList().get(0); |
|
|
|
|
vod.setVodFlags(getVodFlags(vod)); |
|
|
|
|
if (!result.getList().isEmpty()) result.getList().get(0).setVodFlags(); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -117,7 +111,7 @@ public class SiteViewModel extends ViewModel { |
|
|
|
|
|
|
|
|
|
public void playerContent(String flag, String id) { |
|
|
|
|
Site home = ApiConfig.get().getHome(); |
|
|
|
|
postPlayer(() -> { |
|
|
|
|
execute(player, () -> { |
|
|
|
|
if (home.getType() == 3) { |
|
|
|
|
Spider spider = ApiConfig.get().getCSP(home); |
|
|
|
|
String playerContent = spider.playerContent(flag, id, ApiConfig.get().getFlags()); |
|
|
|
|
@ -136,50 +130,18 @@ public class SiteViewModel extends ViewModel { |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void initService(boolean close) { |
|
|
|
|
if (service != null && close) service.shutdownNow(); |
|
|
|
|
private <T> void execute(MutableLiveData<T> result, Callable<T> callable) { |
|
|
|
|
if (service != null) service.shutdownNow(); |
|
|
|
|
service = Executors.newFixedThreadPool(2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void postResult(Callable<Result> callable) { |
|
|
|
|
initService(false); |
|
|
|
|
service.execute(() -> { |
|
|
|
|
try { |
|
|
|
|
if (!Thread.interrupted()) result.postValue(service.submit(callable).get(10, TimeUnit.SECONDS)); |
|
|
|
|
if (!Thread.interrupted()) result.postValue(service.submit(callable).get(5, TimeUnit.SECONDS)); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
if (!Thread.interrupted()) result.postValue(new Result()); |
|
|
|
|
if (!Thread.interrupted()) result.postValue(null); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void postPlayer(Callable<JsonObject> callable) { |
|
|
|
|
initService(true); |
|
|
|
|
service.execute(() -> { |
|
|
|
|
try { |
|
|
|
|
if (!Thread.interrupted()) player.postValue(service.submit(callable).get(10, TimeUnit.SECONDS)); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
if (!Thread.interrupted()) player.postValue(null); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private List<Vod.Flag> getVodFlags(Vod vod) { |
|
|
|
|
List<Vod.Flag> items = new ArrayList<>(); |
|
|
|
|
String[] playFlags = vod.getVodPlayFrom().split("\\$\\$\\$"); |
|
|
|
|
String[] playUrls = vod.getVodPlayUrl().split("\\$\\$\\$"); |
|
|
|
|
for (int i = 0; i < playFlags.length; i++) { |
|
|
|
|
Vod.Flag item = new Vod.Flag(playFlags[i]); |
|
|
|
|
String[] urls = playUrls[i].contains("#") ? playUrls[i].split("#") : new String[]{playUrls[i]}; |
|
|
|
|
for (String url : urls) { |
|
|
|
|
if (!url.contains("$")) continue; |
|
|
|
|
String[] split = url.split("\\$"); |
|
|
|
|
if (split.length >= 2) item.getEpisodes().add(new Vod.Flag.Episode(split[0], split[1])); |
|
|
|
|
} |
|
|
|
|
items.add(item); |
|
|
|
|
} |
|
|
|
|
return items; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void onCleared() { |
|
|
|
|
if (service != null) service.shutdownNow(); |
|
|
|
|
|