Let isHardcodedClientVersionValid() throw IOException
This commit is contained in:
parent
45df8248bf
commit
a6a63e9570
1 changed files with 4 additions and 5 deletions
|
@ -178,7 +178,7 @@ public class YoutubeParsingHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isHardcodedClientVersionValid() {
|
public static boolean isHardcodedClientVersionValid() throws IOException {
|
||||||
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";
|
||||||
|
|
||||||
|
@ -190,7 +190,7 @@ public class YoutubeParsingHelper {
|
||||||
if (response.length() > 50) { // ensure to have a valid response
|
if (response.length() > 50) { // ensure to have a valid response
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) {}
|
} catch (ReCaptchaException ignored) {}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -200,7 +200,7 @@ public class YoutubeParsingHelper {
|
||||||
* @return
|
* @return
|
||||||
* @throws ParsingException
|
* @throws ParsingException
|
||||||
*/
|
*/
|
||||||
public static String getClientVersion() throws ParsingException {
|
public static String getClientVersion() throws ParsingException, IOException {
|
||||||
if (clientVersion != null && !clientVersion.isEmpty()) return clientVersion;
|
if (clientVersion != null && !clientVersion.isEmpty()) return clientVersion;
|
||||||
|
|
||||||
if (isHardcodedClientVersionValid()) {
|
if (isHardcodedClientVersionValid()) {
|
||||||
|
@ -350,8 +350,7 @@ public class YoutubeParsingHelper {
|
||||||
public static JsonArray getJsonResponse(String url, Localization localization) throws IOException, ExtractionException {
|
public static JsonArray getJsonResponse(String url, Localization localization) throws IOException, ExtractionException {
|
||||||
Map<String, List<String>> headers = new HashMap<>();
|
Map<String, List<String>> headers = new HashMap<>();
|
||||||
headers.put("X-YouTube-Client-Name", Collections.singletonList("1"));
|
headers.put("X-YouTube-Client-Name", Collections.singletonList("1"));
|
||||||
headers.put("X-YouTube-Client-Version",
|
headers.put("X-YouTube-Client-Version", Collections.singletonList(getClientVersion()));
|
||||||
Collections.singletonList(YoutubeParsingHelper.getClientVersion()));
|
|
||||||
final String response = getDownloader().get(url, headers, localization).responseBody();
|
final String response = getDownloader().get(url, headers, localization).responseBody();
|
||||||
|
|
||||||
if (response.length() < 50) { // ensure to have a valid response
|
if (response.length() < 50) { // ensure to have a valid response
|
||||||
|
|
Loading…
Reference in a new issue