fix bug when source would indefinitely append to table instead of updating it because of null value behavior in unique indices
This commit is contained in:
parent
996829b8e9
commit
af6f9d5db6
3 changed files with 7 additions and 12 deletions
|
|
@ -43,8 +43,7 @@ public class Crawler {
|
||||||
UpdatableRecord<SourceRecord> source = new UpdatableRecordImpl<>(SOURCE);
|
UpdatableRecord<SourceRecord> source = new UpdatableRecordImpl<>(SOURCE);
|
||||||
source.set(SOURCE.TYPE, item.type.getSqlName());
|
source.set(SOURCE.TYPE, item.type.getSqlName());
|
||||||
source.set(SOURCE.ROOT_NAME, item.rootCategory);
|
source.set(SOURCE.ROOT_NAME, item.rootCategory);
|
||||||
source.set(SOURCE.URL, item.url);
|
source.set(SOURCE.URL_OR_PATH, item.url != null ? item.url : item.path);
|
||||||
source.set(SOURCE.PATH, item.path);
|
|
||||||
source.set(SOURCE.COOKIES, item.cookies);
|
source.set(SOURCE.COOKIES, item.cookies);
|
||||||
|
|
||||||
sources.add(source);
|
sources.add(source);
|
||||||
|
|
@ -144,7 +143,7 @@ public class Crawler {
|
||||||
switch (source.type) {
|
switch (source.type) {
|
||||||
case "m3u-local" -> {
|
case "m3u-local" -> {
|
||||||
try {
|
try {
|
||||||
if (source.path == null) {
|
if (source.urlOrPath == null) {
|
||||||
logger.error("m3u local has to have \"path\" variable");
|
logger.error("m3u local has to have \"path\" variable");
|
||||||
continue;
|
continue;
|
||||||
} else if (source.rootName == null) {
|
} else if (source.rootName == null) {
|
||||||
|
|
@ -152,7 +151,7 @@ public class Crawler {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String m3uData = Files.readString(Paths.get(source.path), StandardCharsets.UTF_8);
|
String m3uData = Files.readString(Paths.get(source.urlOrPath), StandardCharsets.UTF_8);
|
||||||
ArrayList<M3U> m3u = M3UParser.parse(m3uData);
|
ArrayList<M3U> m3u = M3UParser.parse(m3uData);
|
||||||
|
|
||||||
updateAllChannels(m3u, source.rootName);
|
updateAllChannels(m3u, source.rootName);
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,8 @@ public class Source {
|
||||||
@Column(name = "ROOT_NAME")
|
@Column(name = "ROOT_NAME")
|
||||||
public String rootName;
|
public String rootName;
|
||||||
|
|
||||||
@Column(name = "URL")
|
@Column(name = "URL_OR_PATH")
|
||||||
public String url;
|
public String urlOrPath;
|
||||||
|
|
||||||
@Column(name = "PATH")
|
|
||||||
public String path;
|
|
||||||
|
|
||||||
@Column(name = "COOKIES")
|
@Column(name = "COOKIES")
|
||||||
public String cookies;
|
public String cookies;
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,11 @@ CREATE TABLE source (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
type TEXT NOT NULL,
|
type TEXT NOT NULL,
|
||||||
root_name TEXT NOT NULL,
|
root_name TEXT NOT NULL,
|
||||||
url TEXT,
|
url_or_path TEXT NOT NULL,
|
||||||
path TEXT,
|
|
||||||
cookies TEXT
|
cookies TEXT
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE UNIQUE INDEX idx_source_url_path ON source(url,path);
|
CREATE UNIQUE INDEX idx_source_url_or_path ON source(url_or_path);
|
||||||
|
|
||||||
CREATE TABLE crawl (
|
CREATE TABLE crawl (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue