mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-12-14 14:20:29 +05:30
Allow early expiry of cookies.
Currently configured to 30 minutes.
This commit is contained in:
parent
d687446dbf
commit
3811a7f264
@ -10,6 +10,7 @@ import java.net.http.HttpRequest.Builder;
|
|||||||
import java.net.http.HttpResponse;
|
import java.net.http.HttpResponse;
|
||||||
import java.net.http.HttpResponse.BodyHandlers;
|
import java.net.http.HttpResponse.BodyHandlers;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.jsoup.Jsoup;
|
import org.jsoup.Jsoup;
|
||||||
@ -28,6 +29,7 @@ import me.kavin.piped.utils.obj.SolvedCaptcha;
|
|||||||
public class DownloaderImpl extends Downloader {
|
public class DownloaderImpl extends Downloader {
|
||||||
|
|
||||||
private static HttpCookie saved_cookie;
|
private static HttpCookie saved_cookie;
|
||||||
|
private static long cookie_received;
|
||||||
private static final Object cookie_lock = new Object();
|
private static final Object cookie_lock = new Object();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -64,7 +66,8 @@ public class DownloaderImpl extends Downloader {
|
|||||||
|
|
||||||
synchronized (cookie_lock) {
|
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;
|
saved_cookie = null;
|
||||||
|
|
||||||
String redir_url = String.valueOf(response.request().uri());
|
String redir_url = String.valueOf(response.request().uri());
|
||||||
@ -120,6 +123,7 @@ public class DownloaderImpl extends Downloader {
|
|||||||
saved_cookie = HttpCookie.parse(URLUtils.silentDecode(StringUtils
|
saved_cookie = HttpCookie.parse(URLUtils.silentDecode(StringUtils
|
||||||
.substringAfter(formResponse.headers().firstValue("Location").get(), "google_abuse=")))
|
.substringAfter(formResponse.headers().firstValue("Location").get(), "google_abuse=")))
|
||||||
.get(0);
|
.get(0);
|
||||||
|
cookie_received = System.currentTimeMillis();
|
||||||
|
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -82,7 +82,7 @@ public class ResponseHelper {
|
|||||||
|
|
||||||
final List<Subtitle> subtitles = new ObjectArrayList<>();
|
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()));
|
// System.out.println(Constants.mapper.writeValueAsString(info.getStreamSegments()));
|
||||||
info.getSubtitles()
|
info.getSubtitles()
|
||||||
@ -93,7 +93,7 @@ public class ResponseHelper {
|
|||||||
final List<PipedStream> videoStreams = new ObjectArrayList<>();
|
final List<PipedStream> videoStreams = new ObjectArrayList<>();
|
||||||
final List<PipedStream> audioStreams = new ObjectArrayList<>();
|
final List<PipedStream> audioStreams = new ObjectArrayList<>();
|
||||||
|
|
||||||
final String lbryURL = futureLBRY.get(10, TimeUnit.SECONDS);
|
final String lbryURL = futureLBRY.get();
|
||||||
|
|
||||||
if (lbryURL != null)
|
if (lbryURL != null)
|
||||||
videoStreams.add(new PipedStream(lbryURL, "MP4", "LBRY", "video/mp4", false));
|
videoStreams.add(new PipedStream(lbryURL, "MP4", "LBRY", "video/mp4", false));
|
||||||
|
Loading…
Reference in New Issue
Block a user