Update to 1.3.9

pull/137/head
FongMi 4 years ago
parent b40f860cf4
commit d09cfbdb77
  1. 4
      app/build.gradle
  2. 59
      app/src/main/java/com/fongmi/android/tv/api/LiveParser.java

@ -10,8 +10,8 @@ android {
applicationId "com.fongmi.android.tv"
minSdk 21
targetSdk 33
versionCode 38
versionName "1.3.8"
versionCode 39
versionName "1.3.9"
resValue "string", "url", ""
ndk { abiFilters "armeabi-v7a" }
}

@ -0,0 +1,59 @@
package com.fongmi.android.tv.api;
import com.fongmi.android.tv.bean.Channel;
import com.fongmi.android.tv.bean.Group;
import com.fongmi.android.tv.bean.Live;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class LiveParser {
private static final Pattern GROUP = Pattern.compile(".*group-title=\"(.?|.+?)\".*", Pattern.CASE_INSENSITIVE);
private static final Pattern LOGO = Pattern.compile(".*tvg-logo=\"(.?|.+?)\".*", Pattern.CASE_INSENSITIVE);
private static final Pattern NAME = Pattern.compile(".*,(.+?)$", Pattern.CASE_INSENSITIVE);
private static String extract(String line, Pattern pattern) {
Matcher matcher = pattern.matcher(line);
if (matcher.matches()) return matcher.group(1);
return "";
}
public static void start(Live live, String text) {
int number = 0;
if (text.startsWith("#EXTM3U")) m3u(live, text); else txt(live, text);
for (Group group : live.getGroups()) {
for (Channel channel : group.getChannel()) {
channel.setNumber(++number);
}
}
}
private static void m3u(Live live, String text) {
Channel channel = new Channel("");
for (String line : text.split("\n")) {
if (line.startsWith("#EXTINF:")) {
Group group = live.find(new Group(extract(line, GROUP)));
channel = group.find(new Channel(extract(line, NAME)));
channel.setLogo(extract(line, LOGO));
} else if (line.contains("://")) {
channel.getUrls().add(line);
}
}
}
private static void txt(Live live, String text) {
for (String line : text.split("\n")) {
String[] split = line.split(",");
if (split.length < 2) continue;
if (line.contains("#genre#")) {
live.getGroups().add(new Group(split[0]));
}
if (split[1].contains("://")) {
Group group = live.getGroups().get(live.getGroups().size() - 1);
Channel channel = group.find(new Channel(split[0]));
channel.addUrls(split[1].split("#"));
}
}
}
}
Loading…
Cancel
Save