Update tools

This commit is contained in:
FongMi 2023-01-03 13:55:03 +08:00
parent cfa8d12e83
commit 0d61a541ee
12 changed files with 151 additions and 162 deletions

View File

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

View File

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

BIN
tools/gradle/wrapper/gradle-wrapper.jar vendored Normal file

Binary file not shown.

View File

@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

4
tools/release/README.md Normal file
View File

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

1
tools/release/run.bat Normal file
View File

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

BIN
tools/release/run.jar Normal file

Binary file not shown.

1
tools/settings.gradle Normal file
View File

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

View File

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

View File

@ -14,9 +14,6 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Scanner; import java.util.Scanner;
import okhttp3.OkHttpClient;
import okhttp3.Request;
public class Run { public class Run {
private final List<Group> groups; private final List<Group> groups;
@ -24,23 +21,24 @@ public class Run {
private final Gson gson; private final Gson gson;
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
new Run().start(); if (args.length > 0) {
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(getClass(), "data.json")); data = Data.arrayFrom(Util.getFile("data.json"));
gson = new Gson().newBuilder().disableHtmlEscaping().setPrettyPrinting().create(); gson = new Gson().newBuilder().disableHtmlEscaping().setPrettyPrinting().create();
} }
private void start() throws IOException { private void start(String text) throws IOException {
Scanner scanner = new Scanner(System.in); if (text.startsWith("http")) parse(Util.call(text));
System.out.print("請輸入網址或檔名:"); else parse(Util.getFile(text));
String text = scanner.nextLine();
if (text.startsWith("http")) parse(new OkHttpClient().newCall(new Request.Builder().url(text).build()).execute().body().string());
else parse(Util.getFile(getClass(), text));
//parseTxt(Util.getFile(getClass(), "live.txt")); //parseTxt(Util.getFile(getClass(), "live.txt"));
System.out.println(gson.toJson(groups));
writeFile(); writeFile();
} }
@ -84,8 +82,8 @@ public class Run {
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.epg(item.getEpgid());
channel.logo(item.getLogo()); channel.logo(item.getLogo());
channel.epg(item.getEpg());
break; break;
} }
} }
@ -98,7 +96,7 @@ public class Run {
private void writeFile() { private void writeFile() {
try { try {
File file = new File("json", "live.json"); File file = new File("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();

View File

@ -1,13 +1,22 @@
package com.fongmi.tools; package com.fongmi.tools;
import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.stream.Stream; import java.util.stream.Stream;
import okhttp3.OkHttpClient;
import okhttp3.Request;
public class Util { public class Util {
public static String call(String url) throws IOException {
return new OkHttpClient().newCall(new Request.Builder().url(url).build()).execute().body().string();
}
public static String getFile(Class<?> clz, String fileName) { public static String getFile(Class<?> clz, String fileName) {
try { try {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@ -19,4 +28,12 @@ public class Util {
return ""; return "";
} }
} }
public static String getFile(String fileName) {
try {
return Files.readString(Path.of(fileName));
} catch (Exception e) {
return "";
}
}
} }

View File

@ -10,74 +10,28 @@ import java.util.List;
public class Data { public class Data {
@SerializedName("tvid")
private String tvid;
@SerializedName("epgid")
private String epgid;
@SerializedName("name") @SerializedName("name")
private String name; private String name;
@SerializedName("status") @SerializedName("epg")
private String status; private String epg;
@SerializedName("note")
private String note;
@SerializedName("logo") @SerializedName("logo")
private String logo; private String logo;
public static Data objectFrom(String str) {
return new Gson().fromJson(str, Data.class);
}
public static List<Data> arrayFrom(String str) { public static List<Data> arrayFrom(String str) {
Type listType = new TypeToken<ArrayList<Data>>() { Type listType = new TypeToken<ArrayList<Data>>() {}.getType();
}.getType();
return new Gson().fromJson(str, listType); 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() { public String getName() {
return name; return name;
} }
public void setName(String name) { public String getEpg() {
this.name = name; return epg;
}
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() { public String getLogo() {
return logo; return logo;
} }
public void setLogo(String logo) {
this.logo = logo;
}
} }