Support xml.gz

pull/586/head
FongMi 2 years ago
parent dd5d525020
commit 627c2080ca
  1. 18
      app/src/main/java/com/fongmi/android/tv/api/EpgParser.java
  2. 2
      app/src/main/java/com/fongmi/android/tv/server/process/Local.java
  3. 17
      app/src/main/java/com/fongmi/android/tv/utils/FileUtil.java
  4. 8
      catvod/src/main/java/com/github/catvod/utils/Path.java

@ -9,6 +9,7 @@ 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.fongmi.android.tv.utils.FileUtil;
import com.github.catvod.utils.Path;
import com.github.catvod.utils.Trans;
@ -31,10 +32,11 @@ public class EpgParser {
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 (!live.getEpg().endsWith(".xml") && !live.getEpg().endsWith(".gz")) return;
File file = Path.epg(Uri.parse(live.getEpg()).getLastPathSegment());
if (shouldDownload(file)) Download.create(live.getEpg(), file).start();
readXml(live, Path.read(file));
if (file.getName().endsWith(".gz")) readGzip(live, file);
else readXml(live, file);
} catch (Exception e) {
e.printStackTrace();
}
@ -54,12 +56,18 @@ public class EpgParser {
return formatFull.parse(text.substring(0, 14));
}
private static void readXml(Live live, String xml) throws Exception {
private static void readGzip(Live live, File file) throws Exception {
File xml = Path.epg(file.getName().replace(".gz", ""));
if (!xml.exists()) FileUtil.extractGzip(file, xml);
readXml(live, xml);
}
private static void readXml(Live live, File file) 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);
Tv tv = new Persister().read(Tv.class, Path.read(file));
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()) {

@ -56,7 +56,7 @@ public class Local implements Process {
for (String k : files.keySet()) {
String fn = params.get(k);
File temp = new File(files.get(k));
if (fn.toLowerCase().endsWith(".zip")) FileUtil.unzip(temp, Path.root(path));
if (fn.toLowerCase().endsWith(".zip")) FileUtil.extractZip(temp, Path.root(path));
else Path.copy(temp, Path.root(path, fn));
}
return Nano.success();

@ -13,10 +13,15 @@ import com.fongmi.android.tv.R;
import com.fongmi.android.tv.impl.Callback;
import com.github.catvod.utils.Path;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.net.URLConnection;
import java.text.DecimalFormat;
import java.util.Enumeration;
import java.util.zip.GZIPInputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
@ -34,7 +39,17 @@ public class FileUtil {
App.get().startActivity(intent);
}
public static void unzip(File target, File path) {
public static void extractGzip(File target, File path) {
byte[] buffer = new byte[1024];
try (GZIPInputStream is = new GZIPInputStream(new BufferedInputStream(new FileInputStream(target))); BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(path))) {
int read;
while ((read = is.read(buffer)) != -1) os.write(buffer, 0, read);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void extractZip(File target, File path) {
try (ZipFile zip = new ZipFile(target)) {
Enumeration<?> entries = zip.entries();
while (entries.hasMoreElements()) {

@ -72,6 +72,10 @@ public class Path {
return mkdir(new File(cache() + File.separator + "exo"));
}
public static File epg() {
return mkdir(new File(cache() + File.separator + "epg"));
}
public static File jpa() {
return mkdir(new File(cache() + File.separator + "jpa"));
}
@ -96,6 +100,10 @@ public class Path {
return new File(files(), name);
}
public static File epg(String name) {
return new File(epg(), name);
}
public static File js(String name) {
return new File(js(), name);
}

Loading…
Cancel
Save