Skip to content

Commit

Permalink
- remove all query parameters from an URL
Browse files Browse the repository at this point in the history
- fixes a bug where downloads are not correctly detected as direct and might fail later
- see mediathekview/MServer#989
  • Loading branch information
derreisende77 committed May 21, 2024
1 parent 3cc4b42 commit 80799fd
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/main/java/mediathek/daten/DatenDownload.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
Expand Down Expand Up @@ -137,6 +139,12 @@ public DatenDownload(DatenPset pSet, DatenFilm film, byte quelle, DatenAbo abo,
} else {
arr[DOWNLOAD_URL] = film.getUrlFuerAufloesung(FilmResolution.Enum.fromLegacyString(aufloesung));
}
//if URL contains query parameters
if (arr[DOWNLOAD_URL].contains("?")) {
//remove query parameters
arr[DOWNLOAD_URL] = getUrlWithoutParameters(arr[DOWNLOAD_URL]);
}

arr[DatenDownload.DOWNLOAD_INFODATEI] = pSet.arr[DatenPset.PROGRAMMSET_INFODATEI];
arr[DatenDownload.DOWNLOAD_SUBTITLE] = pSet.arr[DatenPset.PROGRAMMSET_SUBTITLE];
arr[DatenDownload.DOWNLOAD_SPOTLIGHT] = pSet.arr[DatenPset.PROGRAMMSET_SPOTLIGHT];
Expand Down Expand Up @@ -265,6 +273,26 @@ private static String datumDatumZeitReinigen(String datum) {
return ret;
}

/**
* Remove all query parameters from url, e.g. ?explicit=true
* @param url the original url
* @return filtered url string
*/
private String getUrlWithoutParameters(String url) {
try {
var uri = new URI(url);
return new URI(uri.getScheme(),
uri.getAuthority(),
uri.getPath(),
null, // Ignore the query part of the input url
uri.getFragment()).toString();
}
catch (URISyntaxException e) {
logger.error("Failed to parse url, returning unmodified", e);
return url;
}
}

public void startDownload() {
// Start erstellen und zur Liste hinzufügen
this.start = new Start();
Expand Down

0 comments on commit 80799fd

Please sign in to comment.