From 3391067cab10b9fedda5cb0a73728cee258cc206 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Mauduit?= Date: Wed, 7 Dec 2016 22:16:28 +0100 Subject: [PATCH] Adding cookies member to Downloader --- .../main/java/org/schabi/newpipe/Downloader.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/src/main/java/org/schabi/newpipe/Downloader.java b/app/src/main/java/org/schabi/newpipe/Downloader.java index 1cc4fcdf2..3c701fde3 100644 --- a/app/src/main/java/org/schabi/newpipe/Downloader.java +++ b/app/src/main/java/org/schabi/newpipe/Downloader.java @@ -35,6 +35,7 @@ import javax.net.ssl.HttpsURLConnection; public class Downloader implements org.schabi.newpipe.extractor.Downloader { private static final String USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0"; + private static String mCookies = ""; private static Downloader instance = null; @@ -51,6 +52,14 @@ public class Downloader implements org.schabi.newpipe.extractor.Downloader { return instance; } + public static synchronized void setCookies(String cookies) { + Downloader.mCookies = cookies; + } + + public static synchronized String getCookies() { + return Downloader.mCookies; + } + /**Download the text file at the supplied URL as in download(String), * but set the HTTP header field "Accept-Language" to the supplied string. * @param siteUrl the URL of the text file to return the contents of @@ -89,6 +98,10 @@ public class Downloader implements org.schabi.newpipe.extractor.Downloader { con.setRequestMethod("GET"); con.setRequestProperty("User-Agent", USER_AGENT); + if (getCookies().length() > 0) { + con.setRequestProperty("Cookie", getCookies()); + } + in = new BufferedReader( new InputStreamReader(con.getInputStream())); String inputLine;