Skip to content

Commit 4f6e325

Browse files
authored
integrate mlib (#1091)
* integrate mlib * fix deprecation * remove deprecated use of new URL * fix oboslete funk crawler api param * remove deprecated function * fix java doc * fix sonar * fix sonar * refactor mlib-messages * cleanup * remove mlib in docs
1 parent 83d5dcf commit 4f6e325

File tree

196 files changed

+5447
-503
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

196 files changed

+5447
-503
lines changed

ARCHITECTURE_OVERVIEW.adoc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,6 @@ Starts all configured crawlers, collects the results and start the filmlist writ
8888

8989
Contains basic logic needed in every crawler like the work splitting.
9090

91-
=== MLib
92-
93-
An internal library which contains the model objects of MediathekView.
94-
9591
=== Crawler
9692

9793
The heart of MServer crawlers for the public broadcaster media libraries.

MServer-Config.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,8 @@ senderConfigurations:
188188

189189

190190
# configure string variables
191-
crawlerApiParams:
192-
FUNK_REQUEST_TOKEN: 137782e774d7cadc93dcbffbbde0ce9c
193-
191+
#crawlerApiParams:
192+
194193
#### COPY ####
195194
copySettings:
196195
# En- / disables FTP

docs/architecture/images/Architectural_Overview.svg

Lines changed: 0 additions & 20 deletions
Loading

pom.xml

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@
6161

6262
<assertj.version>3.27.4</assertj.version>
6363
<byte-buddy.version>1.17.7</byte-buddy.version>
64+
<commons-compress.version>1.28.0</commons-compress.version>
6465
<commons-net.version>3.12.0</commons-net.version>
66+
<commons-lang.version>3.19.0</commons-lang.version>
6567
<commons-text.version>1.14.0</commons-text.version>
6668
<exec-maven-plugin.version>3.5.1</exec-maven-plugin.version>
6769
<hamcrest.version>3.0</hamcrest.version>
@@ -71,6 +73,7 @@
7173
<jersey.version>3.1.11</jersey.version>
7274
<javax-jaxb.version>4.0.2</javax-jaxb.version>
7375
<log4j2.version>2.25.1</log4j2.version>
76+
<jetbrains-annotations.version>22.0.0</jetbrains-annotations.version>
7477
<junit.version>5.13.4</junit.version>
7578
<license-maven-plugin.version>2.0.0</license-maven-plugin.version>
7679
<maven-assembly-plugin.version>3.4.2</maven-assembly-plugin.version>
@@ -86,7 +89,10 @@
8689
<maven-surefire-plugin.version>3.0.0-M7</maven-surefire-plugin.version>
8790
<mockito.version>5.19.0</mockito.version>
8891
<nexus-staging-maven-plugin.version>1.6.13</nexus-staging-maven-plugin.version>
92+
<okhttp3.version>4.10.0</okhttp3.version>
8993
<wiremock.version>2.35.2</wiremock.version>
94+
<xz.version>1.10</xz.version>
95+
<yacl4j-core.version>0.9.2</yacl4j-core.version>
9096
<docker-maven-plugin.version>0.40.2</docker-maven-plugin.version>
9197
<sortpom-maven-plugin.version>3.2.0</sortpom-maven-plugin.version>
9298
</properties>
@@ -118,11 +124,38 @@
118124
</dependencyManagement>
119125

120126
<dependencies>
121-
<!-- MLib -->
127+
128+
<dependency>
129+
<groupId>org.apache.commons</groupId>
130+
<artifactId>commons-compress</artifactId>
131+
<version>${commons-compress.version}</version>
132+
</dependency>
133+
<dependency>
134+
<groupId>org.apache.commons</groupId>
135+
<artifactId>commons-lang3</artifactId>
136+
<version>${commons-lang.version}</version>
137+
</dependency>
138+
<dependency>
139+
<groupId>org.apache.commons</groupId>
140+
<artifactId>commons-text</artifactId>
141+
<version>${commons-text.version}</version>
142+
</dependency>
143+
<dependency>
144+
<groupId>org.tukaani</groupId>
145+
<artifactId>xz</artifactId>
146+
<version>${xz.version}</version>
147+
</dependency>
148+
122149
<dependency>
123-
<groupId>de.mediathekview</groupId>
124-
<artifactId>MLib</artifactId>
125-
<version>4.0.1-SNAPSHOT</version>
150+
<groupId>com.github.fabriziocucci</groupId>
151+
<artifactId>yacl4j-core</artifactId>
152+
<version>${yacl4j-core.version}</version>
153+
</dependency>
154+
155+
<dependency>
156+
<groupId>com.squareup.okhttp3</groupId>
157+
<artifactId>okhttp</artifactId>
158+
<version>${okhttp3.version}</version>
126159
</dependency>
127160

128161
<!-- Google Guava for rate limiting on Arte -->
@@ -145,6 +178,10 @@
145178
<version>${jsoup.version}</version>
146179
</dependency>
147180

181+
<dependency>
182+
<groupId>org.glassfish.jersey.core</groupId>
183+
<artifactId>jersey-client</artifactId>
184+
</dependency>
148185
<dependency>
149186
<groupId>org.glassfish.jersey.core</groupId>
150187
<artifactId>jersey-common</artifactId>
@@ -169,7 +206,13 @@
169206
<artifactId>log4j-core</artifactId>
170207
</dependency>
171208

172-
<!-- Unit Tests -->
209+
<dependency>
210+
<groupId>org.jetbrains</groupId>
211+
<artifactId>annotations</artifactId>
212+
<version>${jetbrains-annotations.version}</version>
213+
</dependency>
214+
215+
<!-- Unit Tests -->
173216
<dependency>
174217
<groupId>org.junit.jupiter</groupId>
175218
<artifactId>junit-jupiter-api</artifactId>
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
package de.mediathekview.mserver.base.compression;
2+
3+
import java.io.*;
4+
import java.nio.ByteBuffer;
5+
import java.nio.channels.Channels;
6+
import java.nio.channels.ReadableByteChannel;
7+
import java.nio.channels.WritableByteChannel;
8+
import java.nio.file.Files;
9+
import java.nio.file.Path;
10+
import java.util.zip.GZIPInputStream;
11+
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
12+
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream;
13+
import org.apache.commons.compress.compressors.xz.XZCompressorInputStream;
14+
import org.apache.commons.compress.compressors.xz.XZCompressorOutputStream;
15+
import org.tukaani.xz.LZMA2Options;
16+
17+
/** A util class to work with compressed files. */
18+
public class CompressionManager {
19+
private static CompressionManager instance;
20+
21+
private CompressionManager() {
22+
super();
23+
}
24+
25+
public static CompressionManager getInstance() {
26+
if (instance == null) {
27+
instance = new CompressionManager();
28+
}
29+
return instance;
30+
}
31+
32+
public OutputStream compress(
33+
final CompressionType aCompressionType, final OutputStream aOutputStream) throws IOException {
34+
switch (aCompressionType) {
35+
case XZ:
36+
return XZCompressorOutputStream.builder().setOutputStream(new BufferedOutputStream(aOutputStream, 512000)).setLzma2Options(new LZMA2Options(9)).get();
37+
case GZIP:
38+
return new MediathekviewGZIPOutputStrean(new BufferedOutputStream(aOutputStream, 512000));
39+
case BZIP:
40+
// This uses already the best compression.
41+
return new BZip2CompressorOutputStream(new BufferedOutputStream(aOutputStream, 512000));
42+
default:
43+
throw new IllegalArgumentException(
44+
String.format("The type \"%s\" isn't supported.", aCompressionType.name()));
45+
}
46+
}
47+
48+
/**
49+
* Compresses a file and uses the old name and appends the file appender based on the {@link
50+
* CompressionType}.
51+
*
52+
* @param aCompressionType The type in which should be compressed.
53+
* @param aSourceFile The file to compress.
54+
* @throws IOException Throws an IOException when the file to be compressed does not exists.
55+
*/
56+
public void compress(final CompressionType aCompressionType, final Path aSourceFile)
57+
throws IOException {
58+
compress(aCompressionType, aSourceFile, aSourceFile);
59+
}
60+
61+
/**
62+
* Compresses a file.
63+
*
64+
* @param aCompressionType The type in which should be compressed.
65+
* @param aSourceFile The file to compress.
66+
* @param aTargetPath The path for the compressed file.
67+
* @throws IOException Throws an IOException when the file to be compressed does not exists.
68+
*/
69+
public void compress(
70+
final CompressionType aCompressionType, final Path aSourceFile, final Path aTargetPath)
71+
throws IOException {
72+
final Path targetPath =
73+
aTargetPath.getFileName().toString().endsWith(aCompressionType.getFileEnding())
74+
? aTargetPath
75+
: aTargetPath.resolveSibling(
76+
aTargetPath.getFileName().toString() + aCompressionType.getFileEnding());
77+
78+
try (final BufferedInputStream input = new BufferedInputStream(Files.newInputStream(aSourceFile), 512000);
79+
final OutputStream output = compress(aCompressionType, Files.newOutputStream(targetPath))) {
80+
fastChannelCopy(Channels.newChannel(input), Channels.newChannel(output));
81+
}
82+
}
83+
84+
/**
85+
* Uncompresses a {@link InputStream}.
86+
*
87+
* @param aCompressionType The type in which should be compressed.
88+
* @param aInputStream The {@link InputStream} to uncompress.
89+
* @return A uncompressed {@link InputStream}
90+
* @throws IOException Throws an IOException when the file to be decompressed does not exists.
91+
*/
92+
public InputStream decompress(
93+
final CompressionType aCompressionType, final InputStream aInputStream) throws IOException {
94+
switch (aCompressionType) {
95+
case XZ:
96+
return new XZCompressorInputStream(aInputStream);
97+
case GZIP:
98+
return new GZIPInputStream(aInputStream);
99+
case BZIP:
100+
return new BZip2CompressorInputStream(aInputStream);
101+
default:
102+
throw new IllegalArgumentException(
103+
String.format("The type \"%s\" isn't supported.", aCompressionType.name()));
104+
}
105+
}
106+
107+
/**
108+
* Decompresses a file and uses the old name and removes the file appender based on the {@link
109+
* CompressionType}.
110+
*
111+
* @param aCompressionType The type in which should be compressed.
112+
* @param aSourceFile The source File to be decompressed
113+
* @throws IOException Throws an IOException when the file to be decompressed does not exists.
114+
*/
115+
public void decompress(final CompressionType aCompressionType, final Path aSourceFile)
116+
throws IOException {
117+
decompress(
118+
aCompressionType,
119+
aSourceFile,
120+
aSourceFile.resolveSibling(
121+
aSourceFile.getFileName().toString().replace(aCompressionType.getFileEnding(), "")));
122+
}
123+
124+
/**
125+
* Decompresses a file.
126+
*
127+
* @param aCompressionType The type in which should be compressed.
128+
* @param aSourceFile The file to decompress.
129+
* @param aTargetPath The path for the decompressed file.
130+
* @throws IOException Throws an IOException when the file to be decompressed does not exists.
131+
*/
132+
public void decompress(
133+
final CompressionType aCompressionType, final Path aSourceFile, final Path aTargetPath)
134+
throws IOException {
135+
try (final InputStream input = decompress(aCompressionType, Files.newInputStream(aSourceFile));
136+
final OutputStream output = new BufferedOutputStream(Files.newOutputStream(aTargetPath))) {
137+
fastChannelCopy(Channels.newChannel(input), Channels.newChannel(output));
138+
}
139+
}
140+
141+
private void fastChannelCopy(final ReadableByteChannel src, final WritableByteChannel dest)
142+
throws IOException {
143+
final ByteBuffer buffer = ByteBuffer.allocateDirect(64 * 1024);
144+
while (src.read(buffer) != -1) {
145+
buffer.flip();
146+
dest.write(buffer);
147+
buffer.compact();
148+
}
149+
150+
buffer.flip();
151+
152+
while (buffer.hasRemaining()) {
153+
dest.write(buffer);
154+
}
155+
}
156+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package de.mediathekview.mserver.base.compression;
2+
3+
public enum CompressionType {
4+
XZ(".xz"),
5+
GZIP(".gz"),
6+
BZIP(".bz");
7+
8+
private final String fileEnding;
9+
10+
CompressionType(final String aFileEnding) {
11+
fileEnding = aFileEnding;
12+
}
13+
14+
public String getFileEnding() {
15+
return fileEnding;
16+
}
17+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package de.mediathekview.mserver.base.compression;
2+
3+
import java.io.IOException;
4+
import java.io.OutputStream;
5+
import java.util.zip.Deflater;
6+
import java.util.zip.GZIPOutputStream;
7+
8+
class MediathekviewGZIPOutputStrean extends GZIPOutputStream {
9+
MediathekviewGZIPOutputStrean(final OutputStream out) throws IOException {
10+
super(out);
11+
def.setLevel(Deflater.BEST_COMPRESSION);
12+
}
13+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package de.mediathekview.mserver.base.config;
2+
3+
/**
4+
* A Data-Transfer-Object which holds the actual configuration.
5+
*/
6+
public interface ConfigDTO
7+
{
8+
}

0 commit comments

Comments
 (0)