Fix build

This commit is contained in:
FongMi 2023-01-03 14:11:49 +08:00
parent 0d61a541ee
commit c523ab990f
8 changed files with 78 additions and 100 deletions

View File

@ -15,3 +15,4 @@ dependencyResolutionManagement {
} }
rootProject.name = "CatVodSpider" rootProject.name = "CatVodSpider"
include ':app' include ':app'
include ':tools'

View File

@ -1,18 +1,10 @@
plugins { plugins {
id 'java' id 'java-library'
} }
java { java {
sourceCompatibility = JavaVersion.VERSION_11 sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_1_8
}
repositories {
mavenCentral()
}
compileJava {
options.encoding = 'UTF-8'
} }
dependencies { dependencies {

View File

@ -1,4 +0,0 @@
data.json 為對應表,可依據需求新增修改 epg、name、logo。
1. 執行 run.bat
2. 輸入直播文本網址或檔名
3. 自動產出 live.json

View File

@ -1 +0,0 @@
java -jar run.jar

Binary file not shown.

View File

@ -1 +0,0 @@
rootProject.name = 'tools'

View File

@ -1,2 +0,0 @@
Manifest-Version: 1.0
Main-Class: com.fongmi.tools.Run

View File

@ -12,96 +12,89 @@ import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Scanner;
public class Run { public class Run {
private final List<Group> groups; private final List<Group> groups;
private final List<Data> data; private final List<Data> data;
private final Gson gson; private final Gson gson;
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
if (args.length > 0) { new Run().start("http://home.jundie.top:81/Cat/tv/live.txt");
new Run().start(args[0]); }
} else {
System.out.print("請輸入網址或檔名:");
new Run().start(new Scanner(System.in).nextLine());
}
}
public Run() { public Run() {
groups = new ArrayList<>(); groups = new ArrayList<>();
data = Data.arrayFrom(Util.getFile("data.json")); data = Data.arrayFrom(Util.getFile(getClass(), "data.json"));
gson = new Gson().newBuilder().disableHtmlEscaping().setPrettyPrinting().create(); gson = new Gson().newBuilder().disableHtmlEscaping().setPrettyPrinting().create();
} }
private void start(String text) throws IOException { private void start(String text) throws IOException {
if (text.startsWith("http")) parse(Util.call(text)); //parseTxt(Util.getFile(getClass(), "live.txt"));
else parse(Util.getFile(text)); parse(Util.call(text));
//parseTxt(Util.getFile(getClass(), "live.txt")); writeFile();
writeFile(); }
}
private void parse(String text) { private void parse(String text) {
for (String line : text.split("\n")) { for (String line : text.split("\n")) {
String[] split = line.split(","); String[] split = line.split(",");
if (split.length < 2) continue; if (split.length < 2) continue;
if (line.contains("#genre#")) groups.add(Group.create(split[0])); if (line.contains("#genre#")) groups.add(Group.create(split[0]));
if (split[1].contains("://")) { if (split[1].contains("://")) {
Group group = groups.get(groups.size() - 1); Group group = groups.get(groups.size() - 1);
String name = split[0]; String name = split[0];
String url = split[1].trim(); String url = split[1].trim();
group.find(Channel.create().name(name).epg(name)).addUrls(url.split("#")); group.find(Channel.create().name(name).epg(name)).addUrls(url.split("#"));
} }
} }
int number = 0; int number = 0;
for (Group group : groups) { for (Group group : groups) {
for (Channel channel : group.getChannel()) { for (Channel channel : group.getChannel()) {
channel.number(String.format(Locale.getDefault(), "%03d", ++number)); channel.number(String.format(Locale.getDefault(), "%03d", ++number));
combine(channel); combine(channel);
} }
} }
} }
private void parseTxt(String text) { private void parseTxt(String text) {
for (String line : text.split("\n")) { for (String line : text.split("\n")) {
String[] split = line.split(","); String[] split = line.split(",");
if (split.length < 2) continue; if (split.length < 2) continue;
if (line.contains("#genre#")) groups.add(Group.create(split[0])); if (line.contains("#genre#")) groups.add(Group.create(split[0]));
if (!line.contains("://")) continue; if (!line.contains("://")) continue;
Group group = groups.get(groups.size() - 1); Group group = groups.get(groups.size() - 1);
String number = split[0]; String number = split[0];
String epg = split[1]; String epg = split[1];
String logo = split[2]; String logo = split[2];
String name = split[3]; String name = split[3];
String url = split[4]; String url = split[4];
group.find(Channel.create().number(number).epg(epg).logo(logo).name(name).ua(getUa(url))).addUrls(url.split("#")); group.find(Channel.create().number(number).epg(epg).logo(logo).name(name).ua(getUa(url))).addUrls(url.split("#"));
} }
} }
private void combine(Channel channel) { private void combine(Channel channel) {
for (Data item : data) { for (Data item : data) {
if (item.getName().contains(channel.getName())) { if (item.getName().contains(channel.getName())) {
channel.logo(item.getLogo()); channel.logo(item.getLogo());
channel.epg(item.getEpg()); channel.epg(item.getEpg());
break; break;
} }
} }
} }
private String getUa(String url) { private String getUa(String url) {
if (url.contains("play-live.ifeng")) return "okhttp/3.15"; if (url.contains("play-live.ifeng")) return "okhttp/3.15";
return null; return null;
} }
private void writeFile() { private void writeFile() {
try { try {
File file = new File("live.json"); File file = new File("json", "live.json");
PrintWriter writer = new PrintWriter(file, String.valueOf(StandardCharsets.UTF_8)); PrintWriter writer = new PrintWriter(file, String.valueOf(StandardCharsets.UTF_8));
writer.println(gson.toJson(groups)); writer.println(gson.toJson(groups));
writer.close(); writer.close();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }