Merge pull request #465 from okcaptain/dev

Dev
pull/466/head
okcaptain 2 years ago committed by GitHub
commit 8c8aa0f339
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 14
      app/src/main/java/com/fongmi/android/tv/api/LiveParser.java
  2. 25
      app/src/main/java/com/fongmi/android/tv/bean/Catchup.java
  3. 15
      app/src/main/java/com/fongmi/android/tv/bean/Channel.java
  4. 2
      app/src/main/java/com/fongmi/android/tv/model/LiveViewModel.java

@ -26,8 +26,9 @@ public class LiveParser {
private static final Pattern CATCHUP_SOURCE = Pattern.compile(".*catchup-source=\"(.?|.+?)\".*");
private static final Pattern CATCHUP = Pattern.compile(".*catchup=\"(.?|.+?)\".*");
private static final Pattern TVG_NAME = Pattern.compile(".*tvg-name=\"(.?|.+?)\".*");
private static final Pattern TVG_LOGO = Pattern.compile(".*tvg-logo=\"(.?|.+?)\".*");
private static final Pattern GROUP = Pattern.compile(".*group-title=\"(.?|.+?)\".*");
private static final Pattern LOGO = Pattern.compile(".*tvg-logo=\"(.?|.+?)\".*");
private static final Pattern NAME = Pattern.compile(".*,(.+?)$");
private static String extract(String line, Pattern pattern) {
@ -46,6 +47,7 @@ public class LiveParser {
public static void text(Live live, String text) {
int number = 0;
if (live.getGroups().size() > 0) return;
text = text.replace("\r\n", "\n");
if (text.contains("#EXTM3U")) m3u(live, text);
else txt(live, text);
for (Group group : live.getGroups()) {
@ -79,8 +81,12 @@ public class LiveParser {
} else if (line.startsWith("#EXTINF:")) {
Group group = live.find(Group.create(extract(line, GROUP), live.isPass()));
channel = group.find(Channel.create(extract(line, NAME)));
channel.setLogo(extract(line, LOGO));
channel.setCatchup(catchup);
channel.setTvgName(extract(line, TVG_NAME));
channel.setLogo(extract(line, TVG_LOGO));
Catchup unknown = Catchup.create();
unknown.setType(extract(line, CATCHUP));
unknown.setSource(extract(line, CATCHUP_SOURCE));
channel.setCatchup(Catchup.decide(unknown, catchup));
} else if (!line.startsWith("#") && line.contains("://")) {
String[] split = line.split("\\|");
if (split.length > 1) setting.headers(Arrays.copyOfRange(split, 1, split.length));
@ -122,7 +128,7 @@ public class LiveParser {
}
private static String getText(Live live) {
return getText(live.getUrl(), live.getHeaders()).replace("\r\n", "\n");
return getText(live.getUrl(), live.getHeaders());
}
private static String getText(String url, Map<String, String> header) {

@ -1,5 +1,6 @@
package com.fongmi.android.tv.bean;
import android.net.Uri;
import android.text.TextUtils;
import com.google.gson.annotations.SerializedName;
@ -31,6 +32,12 @@ public class Catchup {
return new Catchup();
}
public static Catchup decide(Catchup major, Catchup minor) {
if (!major.isEmpty()) return major;
if (!minor.isEmpty()) return minor;
return null;
}
public String getType() {
return TextUtils.isEmpty(type) ? "" : type;
}
@ -71,10 +78,24 @@ public class Catchup {
return getSource().isEmpty();
}
public String format(EpgData data) {
private boolean isAppend() {
return getType().equals("append");
}
private boolean isDefault() {
return getType().equals("default");
}
private String format(String url, String result) {
if (!TextUtils.isEmpty(Uri.parse(url).getQuery())) result = result.replace("?", "&");
if (url.contains("/PLTV/")) url = url.replace("/PLTV/", "/TVOD/");
return url + result;
}
public String format(String url, EpgData data) {
String result = getSource();
Matcher matcher = Pattern.compile("(\\$\\{[^}]*\\})").matcher(result);
while (matcher.find()) result = result.replace(matcher.group(1), data.format(matcher.group(1)));
return result;
return isDefault() ? result : format(url, result);
}
}

@ -23,6 +23,8 @@ public class Channel {
@SerializedName("urls")
private List<String> urls;
@SerializedName("tvgName")
private String tvgName;
@SerializedName("number")
private String number;
@SerializedName("logo")
@ -88,6 +90,14 @@ public class Channel {
this.name = name;
}
public String getTvgName() {
return TextUtils.isEmpty(tvgName) ? getName() : tvgName;
}
public void setTvgName(String tvgName) {
this.tvgName = tvgName;
}
public List<String> getUrls() {
return urls = urls == null ? new ArrayList<>() : urls;
}
@ -326,8 +336,8 @@ public class Channel {
if (!live.getCatchup().isEmpty() && getCatchup().isEmpty()) setCatchup(live.getCatchup());
if (live.getReferer().length() > 0 && getReferer().isEmpty()) setReferer(live.getReferer());
if (live.getPlayerType() != -1 && getPlayerType() == -1) setPlayerType(live.getPlayerType());
if (!getEpg().startsWith("http")) setEpg(live.getEpg().replace("{name}", getName()).replace("{epg}", getEpg()));
if (!getLogo().startsWith("http")) setLogo(live.getLogo().replace("{name}", getName()).replace("{logo}", getLogo()));
if (!getEpg().startsWith("http")) setEpg(live.getEpg().replace("{name}", getTvgName()).replace("{epg}", getEpg()));
if (!getLogo().startsWith("http")) setLogo(live.getLogo().replace("{name}", getTvgName()).replace("{logo}", getLogo()));
}
public void setLine(String line) {
@ -346,6 +356,7 @@ public class Channel {
setPlayerType(item.getPlayerType());
setCatchup(item.getCatchup());
setReferer(item.getReferer());
setTvgName(item.getTvgName());
setHeader(item.getHeader());
setNumber(item.getNumber());
setOrigin(item.getOrigin());

@ -80,7 +80,7 @@ public class LiveViewModel extends ViewModel {
execute(URL, () -> {
item.setMsg(null);
Source.get().stop();
item.setUrl(item.getCurrent() + item.getCatchup().format(data));
item.setUrl(item.getCatchup().format(item.getCurrent(), data));
return item;
});
}

Loading…
Cancel
Save