Support proxy live

pull/123/head
FongMi 3 years ago
parent 658ba63d6c
commit 9c0905fa95
  1. 13
      app/src/main/java/com/fongmi/android/tv/api/LiveParser.java
  2. 23
      app/src/main/java/com/fongmi/android/tv/bean/Live.java

@ -29,6 +29,7 @@ public class LiveParser {
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()));
}
public static void text(Live live, String text) {
@ -79,6 +80,18 @@ public class LiveParser {
}
}
private static void proxy(Live live, String text) {
int number = 0;
for (Live item : Live.arrayFrom(text)) {
Group group = live.find(Group.create(item.getGroup()));
for (Channel channel : item.getChannels()) {
channel.setNumber(++number);
channel.live(live);
group.add(channel);
}
}
}
private static String getText(String url) {
try {
if (url.startsWith("file")) return FileUtil.read(url);

@ -3,11 +3,15 @@ package com.fongmi.android.tv.bean;
import android.net.Uri;
import android.text.TextUtils;
import com.fongmi.android.tv.utils.Utils;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Live {
@ -43,6 +47,12 @@ public class Live {
return new Gson().fromJson(element, Live.class);
}
public static List<Live> arrayFrom(String str) {
Type listType = new TypeToken<List<Live>>() {}.getType();
List<Live> items = new Gson().fromJson(str, listType);
return items == null ? Collections.emptyList() : items;
}
public Live() {
}
@ -92,7 +102,7 @@ public class Live {
return playerType == null ? -1 : playerType == 1 ? 1 : 0;
}
private List<Channel> getChannels() {
public List<Channel> getChannels() {
return channels = channels == null ? new ArrayList<>() : channels;
}
@ -117,12 +127,17 @@ public class Live {
}
public Live check() {
boolean proxy = getGroup().equals("redirect") && getChannels().size() > 0 && getChannels().get(0).getUrls().size() > 0 && getChannels().get(0).getUrls().get(0).startsWith("proxy") && getChannels().get(0).getUrls().get(0).contains("ext=");
if (proxy) this.url = getChannels().get(0).getUrls().get(0).split("ext=")[1];
if (proxy) this.name = getChannels().get(0).getName();
boolean proxy = getGroup().equals("redirect") && getChannels().size() > 0 && getChannels().get(0).getUrls().size() > 0 && getChannels().get(0).getUrls().get(0).startsWith("proxy");
if (proxy) setProxy();
return this;
}
private void setProxy() {
this.url = Utils.checkProxy(getChannels().get(0).getUrls().get(0));
this.name = getChannels().get(0).getName();
this.type = 2;
}
public Group find(Group item) {
for (Group group : getGroups()) if (group.getName().equals(item.getName())) return group;
getGroups().add(item);

Loading…
Cancel
Save