mirror of
https://github.com/TeamNewPipe/NewPipeExtractor.git
synced 2024-12-15 06:40:33 +05:30
Check if hard-coded client version is valid in separate function
This commit is contained in:
parent
7898ba230d
commit
b89b6b1db2
@ -175,15 +175,7 @@ public class YoutubeParsingHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static boolean isHardcodedClientVersionValid() {
|
||||||
* Get the client version from a page
|
|
||||||
* @return
|
|
||||||
* @throws ParsingException
|
|
||||||
*/
|
|
||||||
public static String getClientVersion() throws ParsingException {
|
|
||||||
if (clientVersion != null && !clientVersion.isEmpty()) return clientVersion;
|
|
||||||
|
|
||||||
// Test if hard-coded client version is valid
|
|
||||||
try {
|
try {
|
||||||
final String url = "https://www.youtube.com/results?search_query=test&pbj=1";
|
final String url = "https://www.youtube.com/results?search_query=test&pbj=1";
|
||||||
|
|
||||||
@ -193,10 +185,25 @@ public class YoutubeParsingHelper {
|
|||||||
Collections.singletonList(HARDCODED_CLIENT_VERSION));
|
Collections.singletonList(HARDCODED_CLIENT_VERSION));
|
||||||
final String response = getDownloader().get(url, headers).responseBody();
|
final String response = getDownloader().get(url, headers).responseBody();
|
||||||
if (response.length() > 50) { // ensure to have a valid response
|
if (response.length() > 50) { // ensure to have a valid response
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (Exception ignored) {}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the client version from a page
|
||||||
|
* @return
|
||||||
|
* @throws ParsingException
|
||||||
|
*/
|
||||||
|
public static String getClientVersion() throws ParsingException {
|
||||||
|
if (clientVersion != null && !clientVersion.isEmpty()) return clientVersion;
|
||||||
|
|
||||||
|
if (isHardcodedClientVersionValid()) {
|
||||||
clientVersion = HARDCODED_CLIENT_VERSION;
|
clientVersion = HARDCODED_CLIENT_VERSION;
|
||||||
return clientVersion;
|
return clientVersion;
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) {}
|
|
||||||
|
|
||||||
// Try extracting it from YouTube's website otherwise
|
// Try extracting it from YouTube's website otherwise
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user