Support transfer
This commit is contained in:
parent
25e903581a
commit
46dd1110b6
|
|
@ -1,37 +1,72 @@
|
|||
package com.fongmi.tools;
|
||||
|
||||
import com.fongmi.tools.bean.Channel;
|
||||
import com.fongmi.tools.bean.Data;
|
||||
import com.fongmi.tools.bean.Group;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
|
||||
public class Run {
|
||||
|
||||
private final List<Group> items = new ArrayList<>();
|
||||
private final Gson gson = new Gson().newBuilder().disableHtmlEscaping().setPrettyPrinting().create();
|
||||
private final List<Group> groups;
|
||||
private final List<Data> data;
|
||||
private final Gson gson;
|
||||
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws IOException {
|
||||
new Run().start();
|
||||
}
|
||||
|
||||
private void start() {
|
||||
parse(Util.getFile(getClass(), "live.txt"));
|
||||
System.out.println(gson.toJson(items));
|
||||
public Run() {
|
||||
groups = new ArrayList<>();
|
||||
data = Data.arrayFrom(Util.getFile(getClass(), "data.json"));
|
||||
gson = new Gson().newBuilder().disableHtmlEscaping().setPrettyPrinting().create();
|
||||
}
|
||||
|
||||
private void start() throws IOException {
|
||||
parseOnline(new OkHttpClient().newCall(new Request.Builder().url("http://home.jundie.top:81/Cat/tv/live.txt").build()).execute().body().string());
|
||||
//parseTxt(Util.getFile(getClass(), "live.txt"));
|
||||
System.out.println(gson.toJson(groups));
|
||||
writeFile();
|
||||
}
|
||||
|
||||
private void parse(String text) {
|
||||
private void parseOnline(String text) {
|
||||
for (String line : text.split("\n")) {
|
||||
String[] split = line.split(",");
|
||||
if (split.length < 2) continue;
|
||||
if (line.contains("#genre#")) items.add(Group.create(split[0]));
|
||||
if (line.contains("#genre#")) groups.add(Group.create(split[0]));
|
||||
if (split[1].contains("://")) {
|
||||
Group group = groups.get(groups.size() - 1);
|
||||
String name = split[0];
|
||||
String url = split[1];
|
||||
group.find(Channel.create().name(name)).addUrls(url.split("#"));
|
||||
}
|
||||
}
|
||||
int number = 0;
|
||||
for (Group group : groups) {
|
||||
for (Channel channel : group.getChannel()) {
|
||||
channel.number(String.format(Locale.getDefault(), "%03d", ++number));
|
||||
combine(channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void parseTxt(String text) {
|
||||
for (String line : text.split("\n")) {
|
||||
String[] split = line.split(",");
|
||||
if (split.length < 2) continue;
|
||||
if (line.contains("#genre#")) groups.add(Group.create(split[0]));
|
||||
if (!line.contains("://")) continue;
|
||||
Group group = items.get(items.size() - 1);
|
||||
Group group = groups.get(groups.size() - 1);
|
||||
String number = split[0];
|
||||
String epg = split[1];
|
||||
String logo = split[2];
|
||||
|
|
@ -41,6 +76,16 @@ public class Run {
|
|||
}
|
||||
}
|
||||
|
||||
private void combine(Channel channel) {
|
||||
for (Data item : data) {
|
||||
if (item.getName().contains(channel.getName())) {
|
||||
channel.epg(item.getEpgid());
|
||||
channel.logo(item.getLogo());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getUa(String url) {
|
||||
if (url.contains("play-live.ifeng")) return "okhttp/3.15";
|
||||
return null;
|
||||
|
|
@ -50,7 +95,7 @@ public class Run {
|
|||
try {
|
||||
File file = new File("json", "live.json");
|
||||
PrintWriter writer = new PrintWriter(file, String.valueOf(StandardCharsets.UTF_8));
|
||||
writer.println(gson.toJson(items));
|
||||
writer.println(gson.toJson(groups));
|
||||
writer.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ public class Channel {
|
|||
if (this == obj) return true;
|
||||
if (!(obj instanceof Channel)) return false;
|
||||
Channel it = (Channel) obj;
|
||||
return getName().equals(it.getName()) || getNumber().equals(it.getNumber());
|
||||
return getName().equals(it.getName()) || (!getNumber().isEmpty() && getNumber().equals(it.getNumber()));
|
||||
}
|
||||
|
||||
public static class Sorter implements Comparator<Channel> {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,83 @@
|
|||
package com.fongmi.tools.bean;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Data {
|
||||
|
||||
@SerializedName("tvid")
|
||||
private String tvid;
|
||||
@SerializedName("epgid")
|
||||
private String epgid;
|
||||
@SerializedName("name")
|
||||
private String name;
|
||||
@SerializedName("status")
|
||||
private String status;
|
||||
@SerializedName("note")
|
||||
private String note;
|
||||
@SerializedName("logo")
|
||||
private String logo;
|
||||
|
||||
public static Data objectFrom(String str) {
|
||||
return new Gson().fromJson(str, Data.class);
|
||||
}
|
||||
|
||||
public static List<Data> arrayFrom(String str) {
|
||||
Type listType = new TypeToken<ArrayList<Data>>() {
|
||||
}.getType();
|
||||
return new Gson().fromJson(str, listType);
|
||||
}
|
||||
|
||||
public String getTvid() {
|
||||
return tvid;
|
||||
}
|
||||
|
||||
public void setTvid(String tvid) {
|
||||
this.tvid = tvid;
|
||||
}
|
||||
|
||||
public String getEpgid() {
|
||||
return epgid;
|
||||
}
|
||||
|
||||
public void setEpgid(String epgid) {
|
||||
this.epgid = epgid;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getNote() {
|
||||
return note;
|
||||
}
|
||||
|
||||
public void setNote(String note) {
|
||||
this.note = note;
|
||||
}
|
||||
|
||||
public String getLogo() {
|
||||
return logo;
|
||||
}
|
||||
|
||||
public void setLogo(String logo) {
|
||||
this.logo = logo;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue