Skip to content

Commit 14891e4

Browse files
committed
update
1 parent c939829 commit 14891e4

18 files changed

Lines changed: 227 additions & 71 deletions

MServer-Config.yaml

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
#### Server configurations ####
22

3+
# Film DB
4+
databaseConfig:
5+
active: false
6+
url: "jdbc:postgresql://localhost:55432/crawler"
7+
username: "crawler"
8+
password: "secret"
9+
310
# The maximum amount of cpu threads to be used.
411
maximumCpuThreads: 10
512

@@ -18,20 +25,19 @@ maximumRequestsPerSecond: 999.0
1825
# If set only these Sender will be crawled all other will be ignored.
1926
senderIncluded:
2027
#- ARD
21-
- ARTE_DE
22-
- ARTE_FR
23-
- ARTE_PL
24-
- ARTE_IT
25-
- ARTE_ES
26-
- ARTE_EN
28+
#- ARTE_DE
29+
#- ARTE_FR
30+
#- ARTE_PL
31+
#- ARTE_IT
32+
#- ARTE_ES
33+
#- ARTE_EN
2734
#- DREISAT
28-
#- FUNK
2935
#- KIKA
30-
# - DW
36+
#- DW
3137
#- ORF
3238
#- PHOENIX
3339
#- SRF
34-
#- SR
40+
- SR
3541
#- ZDF
3642

3743
#SRF,SR,PHONIX,ORF,KIKA,DW,3SAT<
@@ -113,7 +119,17 @@ importFilmlistConfigurations :
113119
path: "https://verteiler1.mediathekview.de/filme-org.xz"
114120
format: OLD_JSON_COMPRESSED_XZ
115121
createDiff: true
116-
checkImportListUrl: true
122+
checkImportListUrl: true
123+
- active: false
124+
path: "https://verteiler1.mediathekview.de/Filmliste-akt.xz"
125+
format: OLD_JSON_COMPRESSED_XZ
126+
createDiff: false
127+
checkImportListUrl: false
128+
- active: true
129+
path: jdbc
130+
format: OLD_JSON
131+
createDiff: false
132+
checkImportListUrl: false
117133

118134
# film url is consider invalid if the size is below the minSize
119135
checkImportListUrlMinSize: 5012
@@ -171,7 +187,7 @@ senderConfigurations:
171187
ARTE_ES:
172188
maximumSubpages: 6
173189
KIKA:
174-
maximumSubpages: 2
190+
maximumSubpages: 4
175191
maximumRequestsPerSecond: 8.0
176192
ZDF:
177193
maximumDaysForSendungVerpasstSection: 21
@@ -206,6 +222,8 @@ copySettings:
206222
# JSON_COMPRESSED: /var/www/mediathekview/filmlisten/filmliste_diff.json.xz
207223
OLD_JSON_COMPRESSED_XZ: copyTarget/filmliste_old_diff.json.xz
208224

225+
226+
209227
#### Logging ####
210228
logSettings:
211229
# The log level for the console.

pom.xml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
<wiremock.version>2.35.2</wiremock.version>
9494
<xz.version>1.10</xz.version>
9595
<yacl4j-core.version>0.9.2</yacl4j-core.version>
96-
<docker-maven-plugin.version>0.40.2</docker-maven-plugin.version>
96+
<docker-maven-plugin.version>0.48.0</docker-maven-plugin.version>
9797
<sortpom-maven-plugin.version>3.2.0</sortpom-maven-plugin.version>
9898
</properties>
9999

@@ -500,24 +500,22 @@
500500
<build>
501501
<plugins>
502502
<!-- Build docker -->
503-
504503
<plugin>
505504
<groupId>io.fabric8</groupId>
506505
<artifactId>docker-maven-plugin</artifactId>
507506
<version>${docker-maven-plugin.version}</version>
508507
<configuration>
509-
<images>
508+
<images>
510509
<image>
511510
<name>mediathekview/mserver:${project.version}</name>
512-
513511
<build>
514512
<from>eclipse-temurin:${maven.compiler.target}</from>
515513
<maintainer>Nicklas Wiegandt &lt;nicklas@wiegandt.eu&gt;</maintainer>
516514
<assembly>
517515
<descriptor>docker-assembly.xml</descriptor>
518516
</assembly>
519517
<env>
520-
<JAVA_OPTS>-Xmx4G</JAVA_OPTS>
518+
<JAVA_OPTS>-Xmx8G</JAVA_OPTS>
521519
<MSERVER_OPTS>config.yaml</MSERVER_OPTS>
522520
</env>
523521
<entryPoint>

src/main/docker/docker-compose.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
configs:
3+
init_sql:
4+
content: |
5+
CREATE TABLE IF NOT EXISTS filme (
6+
id TEXT PRIMARY KEY, -- eindeutige Film-ID
7+
data JSONB NOT NULL, -- JSON-Daten des Films
8+
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
9+
last_update TIMESTAMPTZ NOT NULL DEFAULT now(),
10+
last_url_check TIMESTAMPTZ NOT NULL DEFAULT now()
11+
);
12+
13+
services:
14+
15+
postgresMV:
16+
image: postgres:18
17+
container_name: crawler-postgres
18+
environment:
19+
POSTGRES_DB: crawler
20+
POSTGRES_USER: crawler
21+
POSTGRES_PASSWORD: secret
22+
TZ: Europe/Berlin
23+
ports:
24+
- "55432:5432"
25+
volumes:
26+
# Persistente Daten
27+
- c:/tmp/pgdata:/var/lib/postgresql
28+
configs:
29+
- source: init_sql
30+
target: /docker-entrypoint-initdb.d/init.sql
31+
restart: unless-stopped
32+
33+
mserver-r1:
34+
image: mediathekview/mserver:4.0.1-SNAPSHOT
35+
environment:
36+
MSERVER_OPTS: --config https://mediathekview.github.io/MVCrawlerConfig/config/MServer-Config-R1.yaml
37+
volumes:
38+
- c:/tmp/filmlists:/filmlists
39+
- c:/tmp/logs:/logs
40+
- c:/tmp/hist:/hist
41+
- c:/tmp/config:/config
42+
43+
mserver-r2:
44+
image: mediathekview/mserver:4.0.1-SNAPSHOT
45+
environment:
46+
MSERVER_OPTS: --config https://mediathekview.github.io/MVCrawlerConfig/config/MServer-Config-R2.yaml
47+
volumes:
48+
- c:/tmp/filmlists:/filmlists
49+
- c:/tmp/logs:/logs
50+
- c:/tmp/hist:/hist
51+
- c:/tmp/config:/config
52+
53+
mserver-checkUrls:
54+
image: mediathekview/mserver:4.0.1-SNAPSHOT
55+
environment:
56+
MSERVER_OPTS: --config https://mediathekview.github.io/MVCrawlerConfig/config/MServer-Config-R2.yaml --flow checkAvailability
57+
volumes:
58+
- /volume1/docker/Projekt-mv2/filmlists:/filmlists
59+
- /volume1/docker/Projekt-mv2/logs:/logs
60+
- /volume1/docker/Projekt-mv2/hist:/hist
61+
- /volume1/docker/Projekt-mv2/config:/config

src/main/docker/runDocker

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# all docker command
2+
3+
# run PG
4+
docker compose up -d postgresMV
5+
6+
# cron 01 01 long run
7+
docker compose run -d --rm -e MSERVER_OPTS="--config /config/MServer-Config-R1.yaml" mserver-r1
8+
9+
# cron 06-22 1,31 short run
10+
docker compose run -d --rm -e MSERVER_OPTS="--config /config/MServer-Config-R2.yaml" mserver-r2
11+
12+
# cron 22 55 url check
13+
docker compose run -d --rm -e MSERVER_OPTS="--config /config/MServer-Config-R2.yaml --flow checkAvailability" mserver-checkUrls
14+
15+
# on demand - do not run this unless you know what you are doing!
16+
docker compose run -d --rm -e MSERVER_OPTS="--config /config/MServer-Config-R2.yaml --flow importFilmlistIntoDB" mserver-r3
17+
18+

src/main/java/de/mediathekview/mserver/base/config/ConfigManager.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/** A manager to load configurations. */
1212
public abstract class ConfigManager<T extends ConfigDTO> {
1313
private T config;
14-
private static final Logger LOG = LogManager.getLogger(ConfigManager.class);
14+
//private static final Logger LOG = LogManager.getLogger(ConfigManager.class);
1515

1616
protected abstract String getConfigFileName();
1717

@@ -58,7 +58,8 @@ public String getResourcePath(String resourceName) {
5858
}
5959
}
6060
} catch(Exception e) {
61-
LOG.debug(e);
61+
//LOG.debug(e);
62+
e.printStackTrace();
6263
}
6364
return null;
6465
}

src/main/java/de/mediathekview/mserver/base/config/MServerConfigDTO.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88

99
/** A POJO with the configs for MServer. */
1010
public class MServerConfigDTO extends MServerBasicConfigDTO implements ConfigDTO {
11+
private MServerDBConfig databaseConfig;
1112
private final MServerCopySettings copySettings;
1213
private final Boolean writeFilmlistHashFileEnabled;
1314
private final String filmlistHashFilePath;
1415
private final Boolean writeFilmlistIdFileEnabled;
1516
private final String filmlistIdFilePath;
16-
private final MServerDBConfig mServerDBConfig;
17+
1718
/** ignore certain film by title **/
1819
private String ignoreFilmlistPath;
1920
/** add livestreams from external list **/
@@ -49,7 +50,7 @@ public MServerConfigDTO() {
4950
filmlistSavePaths = new EnumMap<>(FilmlistFormats.class);
5051
filmlistDiffSavePaths = new EnumMap<>(FilmlistFormats.class);
5152
copySettings = new MServerCopySettings();
52-
mServerDBConfig = new MServerDBConfig();
53+
databaseConfig = new MServerDBConfig();
5354
logSettings = new MServerLogSettingsDTO();
5455
crawlerURLs = new EnumMap<>(CrawlerUrlType.class);
5556

@@ -245,8 +246,12 @@ public List<ImportFilmlistConfiguration> getImportFilmlistConfigurations() {
245246
return importFilmlistConfigurations;
246247
}
247248

248-
public MServerDBConfig getMServerDBConfig() {
249-
return mServerDBConfig;
249+
public MServerDBConfig getDatabaseConfig() {
250+
return databaseConfig;
251+
}
252+
253+
public void setDatabaseConfig(MServerDBConfig databaseConfig) {
254+
this.databaseConfig = databaseConfig;
250255
}
251256

252257
/**
@@ -293,7 +298,7 @@ public boolean equals(final Object o) {
293298
&& Objects.equals(getIgnoreFilmslistPath(), that.getIgnoreFilmslistPath())
294299
&& Objects.equals(getImportLivestreamConfiguration(), that.getImportLivestreamConfiguration())
295300
&& Objects.equals(getImportFilmlistConfigurations(), that.getImportFilmlistConfigurations())
296-
&& Objects.equals(getMServerDBConfig(), that.getMServerDBConfig());
301+
&& Objects.equals(getDatabaseConfig(), that.getDatabaseConfig());
297302
}
298303

299304
@Override
@@ -321,7 +326,7 @@ public int hashCode() {
321326
getIgnoreFilmslistPath(),
322327
getImportLivestreamConfiguration(),
323328
getImportFilmlistConfigurations(),
324-
getMServerDBConfig());
329+
getDatabaseConfig());
325330
}
326331

327332
public void initializeSenderConfigurations() {

src/main/java/de/mediathekview/mserver/base/config/MServerDBConfig.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,19 @@
33
import java.util.Objects;
44

55
public class MServerDBConfig {
6-
private final Boolean active;
7-
private final String url;
8-
private final String username;
9-
private final String password;
6+
private boolean active;
7+
private String url;
8+
private String username;
9+
private String password;
1010

1111
public MServerDBConfig() {
12-
super();
1312
active = true;
14-
url = "jdbc:postgresql://OscarDS:55432/crawler";
13+
url = "jdbc:postgresql://postgresMV:55432/crawler";
1514
username = "crawler";
1615
password = "secret";
1716
}
1817

1918
public MServerDBConfig(Boolean active, String url, String username, String password) {
20-
super();
2119
this.active = active;
2220
this.url = url;
2321
this.username = username;
@@ -38,6 +36,23 @@ public String getUsername() {
3836
public String getPassword() {
3937
return password;
4038
}
39+
40+
41+
public void setActive(Boolean active) {
42+
this.active = active;
43+
}
44+
45+
public void setUrl(String url) {
46+
this.url = url;
47+
}
48+
49+
public void setUsername(String username) {
50+
this.username = username;
51+
}
52+
53+
public void setPassword(String password) {
54+
this.password = password;
55+
}
4156

4257
@Override
4358
public boolean equals(Object o) {

src/main/java/de/mediathekview/mserver/base/uploader/copy/FileCopyTask.java

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import java.nio.file.Files;
1111
import java.nio.file.Path;
1212
import java.nio.file.StandardCopyOption;
13+
import java.time.LocalDate;
14+
import java.time.format.DateTimeFormatter;
1315

1416
public class FileCopyTask extends UploadTask<FileCopyTarget> {
1517
private static final Logger LOG = LogManager.getLogger(FileCopyTask.class);
@@ -25,15 +27,36 @@ protected void printMessage(final Message aMessage, final Object... args) {
2527
@Override
2628
protected void upload() {
2729
try {
28-
if (Files.exists(uploadTarget.getTargetPath())) {
29-
printMessage(
30-
ServerMessages.FILE_COPY_TARGET_EXISTS,
31-
uploadTarget.getTargetPath().toAbsolutePath().toString());
30+
Path target = uploadTarget.getTargetPath();
31+
if (Files.exists(target)) {
32+
Path backup = backupExistingFile(target);
33+
LOG.debug("CopyTask found existing file - rename existing file to {} before overwrite", backup.getFileName());
3234
}
3335
Files.copy(sourcePath, uploadTarget.getTargetPath(), StandardCopyOption.REPLACE_EXISTING);
3436
} catch (final IOException ioException) {
3537
LOG.error("Something went wrong on copying the film list.", ioException);
3638
printMessage(ServerMessages.FILE_COPY_ERROR);
3739
}
3840
}
41+
42+
private Path backupExistingFile(Path target) throws IOException {
43+
String fileName = target.getFileName().toString();
44+
Path dir = target.getParent();
45+
46+
String date = LocalDate.now()
47+
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
48+
49+
Path backup = dir.resolve(fileName + "." + date);
50+
51+
int counter = 1;
52+
while (Files.exists(backup)) {
53+
backup = dir.resolve(fileName + "." + date + "." + counter);
54+
counter++;
55+
}
56+
57+
Files.move(target, backup);
58+
59+
return backup;
60+
}
61+
3962
}

src/main/java/de/mediathekview/mserver/base/utils/CheckUrlAvailability.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ private boolean isAvailable(Film pFilm) {
5959
timeout.set(true);
6060
return true;
6161
}
62-
if(pFilm.getDefaultUrl().isEmpty()) {
63-
System.out.println("asdf");
64-
}
6562
String normalUrl = pFilm.getDefaultUrl().get().getUrl().toString();
6663
ResponseInfo ri = fsd.getRequestInfo(normalUrl);
6764

0 commit comments

Comments
 (0)