Update tools
This commit is contained in:
parent
cfa8d12e83
commit
0d61a541ee
|
|
@ -15,4 +15,3 @@ dependencyResolutionManagement {
|
|||
}
|
||||
rootProject.name = "CatVodSpider"
|
||||
include ':app'
|
||||
include ':tools'
|
||||
|
|
|
|||
|
|
@ -1,10 +1,18 @@
|
|||
plugins {
|
||||
id 'java-library'
|
||||
id 'java'
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
sourceCompatibility = JavaVersion.VERSION_11
|
||||
targetCompatibility = JavaVersion.VERSION_11
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
compileJava {
|
||||
options.encoding = 'UTF-8'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -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
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
data.json 為對應表,可依據需求新增修改 epg、name、logo。
|
||||
1. 執行 run.bat
|
||||
2. 輸入直播文本網址或檔名
|
||||
3. 自動產出 live.json
|
||||
|
|
@ -0,0 +1 @@
|
|||
java -jar run.jar
|
||||
Binary file not shown.
|
|
@ -0,0 +1 @@
|
|||
rootProject.name = 'tools'
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
Manifest-Version: 1.0
|
||||
Main-Class: com.fongmi.tools.Run
|
||||
|
|
@ -14,9 +14,6 @@ import java.util.List;
|
|||
import java.util.Locale;
|
||||
import java.util.Scanner;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
|
||||
public class Run {
|
||||
|
||||
private final List<Group> groups;
|
||||
|
|
@ -24,23 +21,24 @@ public class Run {
|
|||
private final Gson gson;
|
||||
|
||||
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() {
|
||||
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();
|
||||
}
|
||||
|
||||
private void start() throws IOException {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
System.out.print("請輸入網址或檔名:");
|
||||
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));
|
||||
private void start(String text) throws IOException {
|
||||
if (text.startsWith("http")) parse(Util.call(text));
|
||||
else parse(Util.getFile(text));
|
||||
//parseTxt(Util.getFile(getClass(), "live.txt"));
|
||||
System.out.println(gson.toJson(groups));
|
||||
writeFile();
|
||||
}
|
||||
|
||||
|
|
@ -84,8 +82,8 @@ 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());
|
||||
channel.epg(item.getEpg());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -98,7 +96,7 @@ public class Run {
|
|||
|
||||
private void writeFile() {
|
||||
try {
|
||||
File file = new File("json", "live.json");
|
||||
File file = new File("live.json");
|
||||
PrintWriter writer = new PrintWriter(file, String.valueOf(StandardCharsets.UTF_8));
|
||||
writer.println(gson.toJson(groups));
|
||||
writer.close();
|
||||
|
|
|
|||
|
|
@ -1,13 +1,22 @@
|
|||
package com.fongmi.tools;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
|
||||
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) {
|
||||
try {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
|
@ -19,4 +28,12 @@ public class Util {
|
|||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static String getFile(String fileName) {
|
||||
try {
|
||||
return Files.readString(Path.of(fileName));
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,74 +10,28 @@ 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("epg")
|
||||
private String epg;
|
||||
|
||||
@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();
|
||||
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 getEpg() {
|
||||
return epg;
|
||||
}
|
||||
|
||||
public String getLogo() {
|
||||
return logo;
|
||||
}
|
||||
|
||||
public void setLogo(String logo) {
|
||||
this.logo = logo;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue