Fix home content some error problem

pull/1/head
FongMi 4 years ago
parent 61892f990f
commit 61ebf9be6a
  1. 4
      app/src/main/java/com/fongmi/bear/ApiConfig.java
  2. 3
      app/src/main/java/com/fongmi/bear/bean/Result.java
  3. 14
      app/src/main/java/com/fongmi/bear/model/SiteViewModel.java
  4. 16
      app/src/main/java/com/github/catvod/crawler/SpiderDebug.java

@ -79,13 +79,13 @@ public class ApiConfig {
loadJar();
handler.post(callback::success);
} catch (Exception e) {
handler.post(() -> callback.error("解析配置失敗"));
handler.post(() -> callback.error("配置解析失敗"));
}
}
@Override
public void onFailure(@NonNull Call call, @NonNull IOException e) {
handler.post(() -> callback.error("取得配置失敗"));
handler.post(() -> callback.error("配置取得失敗"));
}
});
}

@ -12,7 +12,8 @@ public class Result {
private List<Vod> list;
public static Result objectFrom(String str) {
return new Gson().fromJson(str, Result.class);
Result result = new Gson().fromJson(str, Result.class);
return result == null ? new Result() : result;
}
public List<Vod> getList() {

@ -7,6 +7,7 @@ import com.fongmi.bear.ApiConfig;
import com.fongmi.bear.bean.Result;
import com.fongmi.bear.bean.Site;
import com.github.catvod.crawler.Spider;
import com.github.catvod.crawler.SpiderDebug;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@ -22,12 +23,17 @@ public class SiteViewModel extends ViewModel {
public void homeContent(String key) {
Site site = ApiConfig.get().getSite(key);
int type = site.getType();
if (type == 3) {
if (site.getType() == 3) {
mService.execute(() -> {
Spider spider = ApiConfig.get().getCSP(site);
Result result = Result.objectFrom(spider.homeContent(false));
if (result.getList().isEmpty()) result = Result.objectFrom(spider.homeVideoContent());
String homeContent = spider.homeContent(false);
SpiderDebug.log(homeContent);
Result result = Result.objectFrom(homeContent);
if (result.getList().isEmpty()) {
String homeVideoContent = spider.homeVideoContent();
SpiderDebug.log(homeVideoContent);
result = Result.objectFrom(homeVideoContent);
}
mResult.postValue(result);
});
}

@ -0,0 +1,16 @@
package com.github.catvod.crawler;
import com.orhanobut.logger.Logger;
public class SpiderDebug {
private static final String TAG = SpiderDebug.class.getSimpleName();
public static void log(Throwable th) {
Logger.t(TAG).d(th.getMessage());
}
public static void log(String msg) {
Logger.t(TAG).d(msg);
}
}
Loading…
Cancel
Save