Skip to content

Commit b89b6b1

Browse files
committed
Check if hard-coded client version is valid in separate function
1 parent 7898ba2 commit b89b6b1

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubeParsingHelper.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,7 @@ public static JsonObject getInitialData(String html) throws ParsingException {
175175
}
176176
}
177177

178-
/**
179-
* Get the client version from a page
180-
* @return
181-
* @throws ParsingException
182-
*/
183-
public static String getClientVersion() throws ParsingException {
184-
if (clientVersion != null && !clientVersion.isEmpty()) return clientVersion;
185-
186-
// Test if hard-coded client version is valid
178+
public static boolean isHardcodedClientVersionValid() {
187179
try {
188180
final String url = "https://www.youtube.com/results?search_query=test&pbj=1";
189181

@@ -193,11 +185,26 @@ public static String getClientVersion() throws ParsingException {
193185
Collections.singletonList(HARDCODED_CLIENT_VERSION));
194186
final String response = getDownloader().get(url, headers).responseBody();
195187
if (response.length() > 50) { // ensure to have a valid response
196-
clientVersion = HARDCODED_CLIENT_VERSION;
197-
return clientVersion;
188+
return true;
198189
}
199190
} catch (Exception ignored) {}
200191

192+
return false;
193+
}
194+
195+
/**
196+
* Get the client version from a page
197+
* @return
198+
* @throws ParsingException
199+
*/
200+
public static String getClientVersion() throws ParsingException {
201+
if (clientVersion != null && !clientVersion.isEmpty()) return clientVersion;
202+
203+
if (isHardcodedClientVersionValid()) {
204+
clientVersion = HARDCODED_CLIENT_VERSION;
205+
return clientVersion;
206+
}
207+
201208
// Try extracting it from YouTube's website otherwise
202209
try {
203210
final String url = "https://www.youtube.com/results?search_query=test";

0 commit comments

Comments
 (0)