Allow early expiry of cookies.

Currently configured to 30 minutes.
This commit is contained in:
FireMasterK 2021-05-28 20:47:25 +05:30
parent d687446dbf
commit 3811a7f264
No known key found for this signature in database
GPG Key ID: 8DFF5DD33E93DB58
2 changed files with 7 additions and 3 deletions

View File

@ -10,6 +10,7 @@ import java.net.http.HttpRequest.Builder;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.StringUtils;
import org.jsoup.Jsoup;
@ -28,6 +29,7 @@ import me.kavin.piped.utils.obj.SolvedCaptcha;
public class DownloaderImpl extends Downloader {
private static HttpCookie saved_cookie;
private static long cookie_received;
private static final Object cookie_lock = new Object();
/**
@ -64,7 +66,8 @@ public class DownloaderImpl extends Downloader {
synchronized (cookie_lock) {
if (saved_cookie != null && saved_cookie.hasExpired())
if (saved_cookie != null && saved_cookie.hasExpired()
|| (System.currentTimeMillis() - cookie_received > TimeUnit.MINUTES.toMillis(30)))
saved_cookie = null;
String redir_url = String.valueOf(response.request().uri());
@ -120,6 +123,7 @@ public class DownloaderImpl extends Downloader {
saved_cookie = HttpCookie.parse(URLUtils.silentDecode(StringUtils
.substringAfter(formResponse.headers().firstValue("Location").get(), "google_abuse=")))
.get(0);
cookie_received = System.currentTimeMillis();
} catch (InterruptedException e) {
e.printStackTrace();

View File

@ -82,7 +82,7 @@ public class ResponseHelper {
final List<Subtitle> subtitles = new ObjectArrayList<>();
final StreamInfo info = futureStream.get(10, TimeUnit.SECONDS);
final StreamInfo info = futureStream.get();
// System.out.println(Constants.mapper.writeValueAsString(info.getStreamSegments()));
info.getSubtitles()
@ -93,7 +93,7 @@ public class ResponseHelper {
final List<PipedStream> videoStreams = new ObjectArrayList<>();
final List<PipedStream> audioStreams = new ObjectArrayList<>();
final String lbryURL = futureLBRY.get(10, TimeUnit.SECONDS);
final String lbryURL = futureLBRY.get();
if (lbryURL != null)
videoStreams.add(new PipedStream(lbryURL, "MP4", "LBRY", "video/mp4", false));