mirror of
https://github.com/TeamNewPipe/NewPipeExtractor.git
synced 2024-12-14 14:20: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,11 +185,26 @@ 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
|
||||||
clientVersion = HARDCODED_CLIENT_VERSION;
|
return true;
|
||||||
return clientVersion;
|
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) {}
|
} 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;
|
||||||
|
return clientVersion;
|
||||||
|
}
|
||||||
|
|
||||||
// Try extracting it from YouTube's website otherwise
|
// Try extracting it from YouTube's website otherwise
|
||||||
try {
|
try {
|
||||||
final String url = "https://www.youtube.com/results?search_query=test";
|
final String url = "https://www.youtube.com/results?search_query=test";
|
||||||
|
Loading…
Reference in New Issue
Block a user