diff --git a/app/src/main/java/com/fongmi/android/tv/api/LiveParser.java b/app/src/main/java/com/fongmi/android/tv/api/LiveParser.java index 2de3fc0a8..b2cb37af1 100644 --- a/app/src/main/java/com/fongmi/android/tv/api/LiveParser.java +++ b/app/src/main/java/com/fongmi/android/tv/api/LiveParser.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); diff --git a/app/src/main/java/com/fongmi/android/tv/bean/Live.java b/app/src/main/java/com/fongmi/android/tv/bean/Live.java index 42f4123c3..498de139c 100644 --- a/app/src/main/java/com/fongmi/android/tv/bean/Live.java +++ b/app/src/main/java/com/fongmi/android/tv/bean/Live.java @@ -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 arrayFrom(String str) { + Type listType = new TypeToken>() {}.getType(); + List 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 getChannels() { + public List 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);