File tree Expand file tree Collapse file tree
extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler Expand file tree Collapse file tree Original file line number Diff line number Diff 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" ;
You can’t perform that action at this time.
0 commit comments