Support catchup - part 1

pull/362/head
FongMi 2 years ago
parent e72d35e17a
commit 77d31d8963
  1. 57
      app/src/main/java/com/fongmi/android/tv/bean/Catchup.java
  2. 15
      app/src/main/java/com/fongmi/android/tv/bean/Channel.java
  3. 10
      app/src/main/java/com/fongmi/android/tv/bean/EpgData.java
  4. 3
      app/src/main/java/com/fongmi/android/tv/model/LiveViewModel.java
  5. 5
      app/src/mobile/java/com/fongmi/android/tv/ui/activity/LiveActivity.java

@ -0,0 +1,57 @@
package com.fongmi.android.tv.bean;
import android.text.TextUtils;
import com.google.gson.annotations.SerializedName;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Catchup {
@SerializedName("type")
private String type;
@SerializedName("days")
private String days;
@SerializedName("source")
private String source;
public static Catchup PLTV() {
Catchup item = new Catchup();
item.setDays("7");
item.setType("append");
item.setSource("?playseek=${(b)yyyyMMddHHmmss}-${(e)yyyyMMddHHmmss}");
return item;
}
public String getType() {
return TextUtils.isEmpty(type) ? "" : type;
}
public void setType(String type) {
this.type = type;
}
public String getDays() {
return TextUtils.isEmpty(days) ? "" : days;
}
public void setDays(String days) {
this.days = days;
}
public String getSource() {
return TextUtils.isEmpty(source) ? "" : source;
}
public void setSource(String source) {
this.source = source;
}
public String format(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;
}
}

@ -39,6 +39,8 @@ public class Channel {
private String origin;
@SerializedName("referer")
private String referer;
@SerializedName("catchup")
private Catchup catchup;
@SerializedName("header")
private JsonElement header;
@SerializedName("playerType")
@ -156,6 +158,14 @@ public class Channel {
this.referer = referer;
}
public Catchup getCatchup() {
return catchup;
}
public void setCatchup(Catchup catchup) {
this.catchup = catchup;
}
public JsonElement getHeader() {
return header;
}
@ -276,6 +286,11 @@ public class Channel {
return getUrls().isEmpty() || getLine() == getUrls().size() - 1;
}
public boolean hasCatchup() {
if (getCatchup() == null && getCurrent().contains("/PLTV/")) setCatchup(Catchup.PLTV());
return getCatchup() != null;
}
public String getLineText() {
if (getUrls().size() <= 1) return "";
if (getCurrent().contains("$")) return getCurrent().split("\\$")[1];

@ -8,6 +8,9 @@ import com.fongmi.android.tv.R;
import com.fongmi.android.tv.utils.ResUtil;
import com.google.gson.annotations.SerializedName;
import java.text.SimpleDateFormat;
import java.util.Locale;
public class EpgData {
@SerializedName("title")
@ -65,6 +68,13 @@ public class EpgData {
return getStartTime() <= System.currentTimeMillis() && System.currentTimeMillis() <= getEndTime();
}
public String format(String group) {
String pattern = group.split("\\)")[1].split("\\}")[0];
if (group.contains("(b)")) return new SimpleDateFormat(pattern, Locale.getDefault()).format(getStartTime());
if (group.contains("(e)")) return new SimpleDateFormat(pattern, Locale.getDefault()).format(getEndTime());
return "";
}
public String format() {
if (getTitle().isEmpty()) return "";
if (getStart().isEmpty() && getEnd().isEmpty()) return ResUtil.getString(R.string.play_now, getTitle());

@ -82,8 +82,7 @@ public class LiveViewModel extends ViewModel {
execute(URL, () -> {
item.setMsg(null);
Source.get().stop();
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss", Locale.getDefault());
item.setUrl(item.getCurrent() + "?playseek=" + format.format(new Date(data.getStartTime())) + "-" + format.format(new Date(data.getEndTime())));
item.setUrl(item.getCurrent() + item.getCatchup().format(data));
return item;
});
}

@ -639,8 +639,9 @@ public class LiveActivity extends BaseActivity implements CustomKeyDownLive.List
@Override
public void onItemClick(EpgData item) {
mEpgDataAdapter.setSelected(item);
mViewModel.getUrl(mChannel, item);
if (!mChannel.hasCatchup()) return;
//mEpgDataAdapter.setSelected(item);
//mViewModel.getUrl(mChannel, item);
}
private void addKeep(Channel item) {

Loading…
Cancel
Save