Support header for get live list

pull/451/head
FongMi 2 years ago
parent 9baec21cb2
commit 24c7f615db
  1. 14
      app/src/main/java/com/fongmi/android/tv/api/LiveParser.java
  2. 11
      app/src/main/java/com/fongmi/android/tv/bean/Live.java
  3. 9
      catvod/src/main/java/com/github/catvod/net/OkHttp.java

@ -33,9 +33,9 @@ public class LiveParser {
public static void start(Live live) {
if (live.getGroups().size() > 0) return;
if (live.getType() == 0) text(live, getText(live.getUrl()));
if (live.getType() == 1) json(live, getText(live.getUrl()));
if (live.getType() == 2) proxy(live, getText(live.getUrl()));
if (live.getType() == 0) text(live, getText(live.getUrl(), live.getHeaders()));
if (live.getType() == 1) json(live, getText(live.getUrl(), live.getHeaders()));
if (live.getType() == 2) proxy(live, getText(live.getUrl(), live.getHeaders()));
}
public static void text(Live live, String text) {
@ -110,11 +110,11 @@ public class LiveParser {
}
}
private static String getText(String url) {
private static String getText(String url, Map<String, String> header) {
if (url.startsWith("file")) return Path.read(url);
if (url.startsWith("http")) return OkHttp.string(url);
if (url.startsWith("assets") || url.startsWith("clan") || url.startsWith("proxy")) return getText(UrlUtil.convert(url));
if (url.length() > 0 && url.length() % 4 == 0) return getText(new String(Base64.decode(url, Base64.DEFAULT)));
if (url.startsWith("http")) return OkHttp.string(url, header);
if (url.startsWith("assets") || url.startsWith("clan") || url.startsWith("proxy")) return getText(UrlUtil.convert(url), header);
if (url.length() > 0 && url.length() % 4 == 0) return getText(new String(Base64.decode(url, Base64.DEFAULT)), header);
return "";
}

@ -12,6 +12,8 @@ import com.fongmi.android.tv.App;
import com.fongmi.android.tv.Constant;
import com.fongmi.android.tv.R;
import com.fongmi.android.tv.db.AppDatabase;
import com.github.catvod.utils.Json;
import com.google.common.net.HttpHeaders;
import com.google.gson.JsonElement;
import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;
@ -21,6 +23,7 @@ import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@Entity
public class Live {
@ -286,6 +289,14 @@ public class Live {
return this;
}
public Map<String, String> getHeaders() {
Map<String, String> headers = Json.toMap(getHeader());
if (!getUa().isEmpty()) headers.put(HttpHeaders.USER_AGENT, getUa());
if (!getOrigin().isEmpty()) headers.put(HttpHeaders.ORIGIN, getOrigin());
if (!getReferer().isEmpty()) headers.put(HttpHeaders.REFERER, getReferer());
return headers;
}
public static Live find(String name) {
return AppDatabase.get().getLiveDao().find(name);
}

@ -96,6 +96,15 @@ public class OkHttp {
}
}
public static String string(String url, Map<String, String> headers) {
try {
return newCall(url, Headers.of(headers)).execute().body().string();
} catch (Exception e) {
e.printStackTrace();
return "";
}
}
public static Call newCall(String url) {
return client().newCall(new Request.Builder().url(url).build());
}

Loading…
Cancel
Save