mirror of
https://github.com/MaintainTeam/LastPipeBender.git
synced 2025-03-01 05:48:22 +03:00
RUMBLE: fix getting video size for Rumble as they no longer support HEAD (discovered 20230203)
This commit is contained in:
parent
dc70e82a6f
commit
2d662d79ff
1 changed files with 19 additions and 1 deletions
|
@ -14,6 +14,8 @@ import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
|
|||
import org.schabi.newpipe.util.InfoCache;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -115,7 +117,11 @@ public final class DownloaderImpl extends Downloader {
|
|||
public long getContentLength(final String url) throws IOException {
|
||||
try {
|
||||
final Response response = head(url);
|
||||
return Long.parseLong(response.getHeader("Content-Length"));
|
||||
if (response.responseCode() == 405) { // HEAD Method not allowed
|
||||
return getContentLengthViaGet(url);
|
||||
} else {
|
||||
return Long.parseLong(response.getHeader("Content-Length"));
|
||||
}
|
||||
} catch (final NumberFormatException e) {
|
||||
throw new IOException("Invalid content length", e);
|
||||
} catch (final ReCaptchaException e) {
|
||||
|
@ -179,4 +185,16 @@ public final class DownloaderImpl extends Downloader {
|
|||
return new Response(response.code(), response.message(), response.headers().toMultimap(),
|
||||
responseBodyToReturn, latestUrl);
|
||||
}
|
||||
|
||||
// some servers eg rumble do not allow HEAD requests anymore (discovered 202300203)
|
||||
private long getContentLengthViaGet(final String url) throws IOException {
|
||||
final HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
|
||||
conn.setInstanceFollowRedirects(true);
|
||||
conn.setRequestProperty("User-Agent", USER_AGENT);
|
||||
conn.setRequestProperty("Accept", "*/*");
|
||||
conn.setRequestProperty("Accept-Encoding", "*");
|
||||
final String contentSize = conn.getHeaderField("Content-Length");
|
||||
conn.disconnect();
|
||||
return Long.parseLong(contentSize);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue