Skip to content

Commit 80799fd

Browse files
committed
- remove all query parameters from an URL
- fixes a bug where downloads are not correctly detected as direct and might fail later - see mediathekview/MServer#989
1 parent 3cc4b42 commit 80799fd

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/main/java/mediathek/daten/DatenDownload.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import javax.xml.stream.XMLStreamReader;
2323
import javax.xml.stream.XMLStreamWriter;
2424
import java.io.File;
25+
import java.net.URI;
26+
import java.net.URISyntaxException;
2527
import java.util.ArrayList;
2628
import java.util.Arrays;
2729
import java.util.Date;
@@ -137,6 +139,12 @@ public DatenDownload(DatenPset pSet, DatenFilm film, byte quelle, DatenAbo abo,
137139
} else {
138140
arr[DOWNLOAD_URL] = film.getUrlFuerAufloesung(FilmResolution.Enum.fromLegacyString(aufloesung));
139141
}
142+
//if URL contains query parameters
143+
if (arr[DOWNLOAD_URL].contains("?")) {
144+
//remove query parameters
145+
arr[DOWNLOAD_URL] = getUrlWithoutParameters(arr[DOWNLOAD_URL]);
146+
}
147+
140148
arr[DatenDownload.DOWNLOAD_INFODATEI] = pSet.arr[DatenPset.PROGRAMMSET_INFODATEI];
141149
arr[DatenDownload.DOWNLOAD_SUBTITLE] = pSet.arr[DatenPset.PROGRAMMSET_SUBTITLE];
142150
arr[DatenDownload.DOWNLOAD_SPOTLIGHT] = pSet.arr[DatenPset.PROGRAMMSET_SPOTLIGHT];
@@ -265,6 +273,26 @@ private static String datumDatumZeitReinigen(String datum) {
265273
return ret;
266274
}
267275

276+
/**
277+
* Remove all query parameters from url, e.g. ?explicit=true
278+
* @param url the original url
279+
* @return filtered url string
280+
*/
281+
private String getUrlWithoutParameters(String url) {
282+
try {
283+
var uri = new URI(url);
284+
return new URI(uri.getScheme(),
285+
uri.getAuthority(),
286+
uri.getPath(),
287+
null, // Ignore the query part of the input url
288+
uri.getFragment()).toString();
289+
}
290+
catch (URISyntaxException e) {
291+
logger.error("Failed to parse url, returning unmodified", e);
292+
return url;
293+
}
294+
}
295+
268296
public void startDownload() {
269297
// Start erstellen und zur Liste hinzufügen
270298
this.start = new Start();

0 commit comments

Comments
 (0)