Live support parse

pull/171/head
FongMi 2 years ago
parent 2fda01a4a1
commit 4571fbb59e
  1. 2
      app/build.gradle
  2. 12
      app/src/main/java/com/fongmi/android/tv/api/LiveParser.java
  3. 36
      app/src/main/java/com/fongmi/android/tv/bean/Channel.java
  4. 4
      app/src/main/java/com/fongmi/android/tv/model/LiveViewModel.java
  5. 6
      app/src/main/java/com/fongmi/android/tv/player/Players.java
  6. 12
      app/src/main/java/com/fongmi/android/tv/player/extractor/TVBus.java

@ -11,7 +11,7 @@ android {
minSdk 21
targetSdk 28
versionCode 210
versionName "20231129#3"
versionName "20231129#4"
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]

@ -116,6 +116,7 @@ public class LiveParser {
private String key;
private String type;
private String referer;
private Integer parse;
private Integer player;
public static Setting create() {
@ -124,6 +125,7 @@ public class LiveParser {
public void check(String line) {
if (line.startsWith("ua")) ua(line);
if (line.startsWith("parse")) parse(line);
if (line.startsWith("player")) player(line);
if (line.startsWith("referer")) referer(line);
if (line.startsWith("#EXTVLCOPT:http-user-agent")) ua(line);
@ -135,6 +137,7 @@ public class LiveParser {
public Setting copy(Channel channel) {
if (ua != null) channel.setUa(ua);
if (parse != null) channel.setParse(parse);
if (referer != null) channel.setReferer(referer);
if (player != null) channel.setPlayerType(player);
if (key != null && type != null) channel.setDrm(Drm.create(key, type));
@ -157,6 +160,14 @@ public class LiveParser {
}
}
private void parse(String line) {
try {
parse = Integer.parseInt(line.split("=")[1].trim());
} catch (Exception e) {
parse = null;
}
}
private void player(String line) {
try {
player = Integer.parseInt(line.split("=")[1].trim());
@ -185,6 +196,7 @@ public class LiveParser {
ua = null;
key = null;
type = null;
parse = null;
player = null;
referer = null;
}

@ -39,12 +39,15 @@ public class Channel {
private JsonElement header;
@SerializedName("playerType")
private Integer playerType;
@SerializedName("parse")
private Integer parse;
@SerializedName("drm")
private Drm drm;
private boolean selected;
private Group group;
private String url;
private String msg;
private Epg data;
private int line;
@ -64,6 +67,12 @@ public class Channel {
return new Channel().copy(channel);
}
public static Channel error(String msg) {
Channel result = new Channel();
result.setMsg(msg);
return result;
}
public Channel() {
}
@ -143,6 +152,14 @@ public class Channel {
this.playerType = playerType;
}
public Integer getParse() {
return parse == null ? 0 : parse;
}
public void setParse(Integer parse) {
this.parse = parse;
}
public Drm getDrm() {
return drm;
}
@ -167,6 +184,18 @@ public class Channel {
this.url = url;
}
public String getMsg() {
return TextUtils.isEmpty(msg) ? "" : msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public boolean hasMsg() {
return getMsg().length() > 0;
}
public Epg getData() {
return data == null ? new Epg() : data;
}
@ -272,6 +301,13 @@ public class Channel {
return this;
}
public Result result() {
Result result = new Result();
result.setHeader(getHeader());
result.setUrl(Url.create().add(getUrl()));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;

@ -9,6 +9,7 @@ import com.fongmi.android.tv.bean.Channel;
import com.fongmi.android.tv.bean.Epg;
import com.fongmi.android.tv.bean.Group;
import com.fongmi.android.tv.bean.Live;
import com.fongmi.android.tv.exception.ExtractException;
import com.fongmi.android.tv.player.Source;
import com.github.catvod.net.OkHttp;
@ -119,7 +120,8 @@ public class LiveViewModel extends ViewModel {
if (type == URL) url.postValue((Channel) executor.submit(callable).get(Constant.TIMEOUT_PARSE_LIVE, TimeUnit.MILLISECONDS));
} catch (Throwable e) {
if (e instanceof InterruptedException || Thread.interrupted()) return;
if (type == URL) url.postValue(new Channel());
if (e.getCause() instanceof ExtractException) url.postValue(Channel.error(e.getCause().getMessage()));
else if (type == URL) url.postValue(new Channel());
if (type == LIVE) live.postValue(new Live());
if (type == EPG) epg.postValue(new Epg());
e.printStackTrace();

@ -397,7 +397,11 @@ public class Players implements Player.Listener, IMediaPlayer.Listener, Analytic
}
public void start(Channel channel, int timeout) {
if (isIllegal(channel.getUrl())) {
if (channel.hasMsg()) {
ErrorEvent.extract(channel.getMsg());
} else if (channel.getParse() == 1) {
startParse(channel.result(), false);
} else if (isIllegal(channel.getUrl())) {
ErrorEvent.url();
} else {
setMediaSource(channel, timeout);

@ -4,6 +4,7 @@ import com.fongmi.android.tv.App;
import com.fongmi.android.tv.Setting;
import com.fongmi.android.tv.api.LiveConfig;
import com.fongmi.android.tv.bean.Core;
import com.fongmi.android.tv.exception.ExtractException;
import com.fongmi.android.tv.player.Source;
import com.google.gson.JsonObject;
import com.tvbus.engine.Listener;
@ -36,9 +37,14 @@ public class TVBus implements Source.Extractor, Listener {
if (tvcore == null) init(core = LiveConfig.get().getHome().getCore());
tvcore.start(url);
onWait();
onCheck();
return hls;
}
private void onCheck() throws Exception {
if (hls.startsWith("-")) throw new ExtractException("Error Code : " + hls);
}
private void onWait() throws InterruptedException {
synchronized (this) {
wait();
@ -71,13 +77,15 @@ public class TVBus implements Source.Extractor, Listener {
@Override
public void onPrepared(String result) {
JsonObject json = App.gson().fromJson(result, JsonObject.class);
if (json.get("hls") == null) return;
hls = json.get("hls").getAsString();
hls = json.has("hls") ? json.get("hls").getAsString() : "-9999";
onNotify();
}
@Override
public void onStop(String result) {
JsonObject json = App.gson().fromJson(result, JsonObject.class);
hls = json.get("errno").getAsString();
onNotify();
}
@Override

Loading…
Cancel
Save