mirror of https://github.com/FongMi/TV.git
commit
41cbebf69c
@ -0,0 +1,10 @@ |
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:width="24dp" |
||||
android:height="24dp" |
||||
android:tint="#FFFFFF" |
||||
android:viewportWidth="960" |
||||
android:viewportHeight="960"> |
||||
<path |
||||
android:fillColor="@android:color/white" |
||||
android:pathData="M496.35,480L312.35,296L376,232.35L623.65,480L376,727.65L312.35,664L496.35,480Z" /> |
||||
</vector> |
||||
@ -0,0 +1,89 @@ |
||||
package com.fongmi.android.tv.api; |
||||
|
||||
import android.net.Uri; |
||||
|
||||
import com.fongmi.android.tv.bean.Channel; |
||||
import com.fongmi.android.tv.bean.Epg; |
||||
import com.fongmi.android.tv.bean.EpgData; |
||||
import com.fongmi.android.tv.bean.Group; |
||||
import com.fongmi.android.tv.bean.Live; |
||||
import com.fongmi.android.tv.bean.Tv; |
||||
import com.fongmi.android.tv.utils.Download; |
||||
import com.github.catvod.utils.Path; |
||||
import com.github.catvod.utils.Trans; |
||||
|
||||
import org.simpleframework.xml.core.Persister; |
||||
|
||||
import java.io.File; |
||||
import java.text.SimpleDateFormat; |
||||
import java.util.Calendar; |
||||
import java.util.Date; |
||||
import java.util.HashMap; |
||||
import java.util.HashSet; |
||||
import java.util.Map; |
||||
import java.util.Set; |
||||
|
||||
public class EpgParser { |
||||
|
||||
private static final SimpleDateFormat formatFull = new SimpleDateFormat("yyyyMMddHHmmss"); |
||||
private static final SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd"); |
||||
private static final SimpleDateFormat formatTime = new SimpleDateFormat("HH:mm"); |
||||
|
||||
public static void start(Live live) { |
||||
try { |
||||
if (!live.getEpg().contains(".xml") || live.getEpg().contains("{")) return; |
||||
File file = Path.cache(Uri.parse(live.getEpg()).getLastPathSegment()); |
||||
if (shouldDownload(file)) Download.create(live.getEpg(), file).start(); |
||||
readXml(live, Path.read(file)); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
|
||||
private static boolean shouldDownload(File file) { |
||||
return !file.exists() || !equalToday(file); |
||||
} |
||||
|
||||
private static boolean equalToday(File file) { |
||||
Calendar calendar = Calendar.getInstance(); |
||||
calendar.setTimeInMillis(file.lastModified()); |
||||
return calendar.get(Calendar.DAY_OF_MONTH) == Calendar.getInstance().get(Calendar.DAY_OF_MONTH); |
||||
} |
||||
|
||||
private static Date parseDateTime(String text) throws Exception { |
||||
return formatFull.parse(text.substring(0, 14)); |
||||
} |
||||
|
||||
private static void readXml(Live live, String xml) throws Exception { |
||||
Set<String> exist = new HashSet<>(); |
||||
Map<String, Epg> epgMap = new HashMap<>(); |
||||
Map<String, String> mapping = new HashMap<>(); |
||||
String today = formatDate.format(new Date()); |
||||
Tv tv = new Persister().read(Tv.class, xml); |
||||
for (Group group : live.getGroups()) for (Channel channel : group.getChannel()) exist.add(channel.getTvgName()); |
||||
for (Tv.Channel channel : tv.getChannel()) mapping.put(channel.getId(), channel.getDisplayName()); |
||||
for (Tv.Programme programme : tv.getProgramme()) { |
||||
String key = mapping.get(programme.getChannel()); |
||||
if (!exist.contains(key)) continue; |
||||
if (!programme.equals(today)) continue; |
||||
if (!epgMap.containsKey(key)) epgMap.put(key, Epg.create(key, today)); |
||||
String title = programme.getTitle(); |
||||
String start = programme.getStart(); |
||||
String stop = programme.getStop(); |
||||
Date startDate = parseDateTime(start); |
||||
Date endDate = parseDateTime(stop); |
||||
EpgData epgData = new EpgData(); |
||||
epgData.setStart(formatTime.format(startDate)); |
||||
epgData.setEnd(formatTime.format(endDate)); |
||||
epgData.setStartTime(startDate.getTime()); |
||||
epgData.setEndTime(endDate.getTime()); |
||||
epgData.setTitle(Trans.s2t(title)); |
||||
epgMap.get(key).getList().add(epgData); |
||||
} |
||||
for (Group group : live.getGroups()) { |
||||
for (Channel channel : group.getChannel()) { |
||||
channel.setData(epgMap.get(channel.getTvgName())); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,90 @@ |
||||
package com.fongmi.android.tv.bean; |
||||
|
||||
import android.text.TextUtils; |
||||
|
||||
import org.simpleframework.xml.Attribute; |
||||
import org.simpleframework.xml.Element; |
||||
import org.simpleframework.xml.ElementList; |
||||
import org.simpleframework.xml.Root; |
||||
|
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
|
||||
@Root(name = "tv", strict = false) |
||||
public class Tv { |
||||
|
||||
@ElementList(entry = "channel", inline = true) |
||||
private List<Channel> channel; |
||||
|
||||
@ElementList(entry = "programme", inline = true) |
||||
private List<Programme> programme; |
||||
|
||||
public List<Channel> getChannel() { |
||||
return channel == null ? Collections.emptyList() : channel; |
||||
} |
||||
|
||||
public List<Programme> getProgramme() { |
||||
return programme == null ? Collections.emptyList() : programme; |
||||
} |
||||
|
||||
@Root(name = "channel") |
||||
public static class Channel { |
||||
|
||||
@Attribute(name = "id") |
||||
private String id; |
||||
|
||||
@Element(name = "display-name") |
||||
private String displayName; |
||||
|
||||
public String getId() { |
||||
return TextUtils.isEmpty(id) ? "" : id; |
||||
} |
||||
|
||||
public String getDisplayName() { |
||||
return TextUtils.isEmpty(displayName) ? "" : displayName; |
||||
} |
||||
} |
||||
|
||||
@Root(name = "programme") |
||||
public static class Programme { |
||||
|
||||
@Attribute(name = "start") |
||||
private String start; |
||||
|
||||
@Attribute(name = "stop") |
||||
private String stop; |
||||
|
||||
@Attribute(name = "channel") |
||||
private String channel; |
||||
|
||||
@Element(name = "title") |
||||
private String title; |
||||
|
||||
@Element(name = "date", required = false) |
||||
private String date; |
||||
|
||||
public String getStart() { |
||||
return TextUtils.isEmpty(start) ? "" : start; |
||||
} |
||||
|
||||
public String getStop() { |
||||
return TextUtils.isEmpty(stop) ? "" : stop; |
||||
} |
||||
|
||||
public String getChannel() { |
||||
return TextUtils.isEmpty(channel) ? "" : channel; |
||||
} |
||||
|
||||
public String getTitle() { |
||||
return TextUtils.isEmpty(title) ? "" : title; |
||||
} |
||||
|
||||
public String getDate() { |
||||
return TextUtils.isEmpty(date) ? "" : date; |
||||
} |
||||
|
||||
public boolean equals(String date) { |
||||
return getDate().isEmpty() || getDate().equals(date); |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue