fix: add checkIfChannelResponseIsValid method
This commit is contained in:
parent
8cd6439d19
commit
c6ee2f3ff7
|
@ -1767,17 +1767,7 @@ public final class YoutubeParsingHelper {
|
||||||
final JsonObject jsonResponse = getJsonPostResponse("navigation/resolve_url",
|
final JsonObject jsonResponse = getJsonPostResponse("navigation/resolve_url",
|
||||||
body, Localization.DEFAULT);
|
body, Localization.DEFAULT);
|
||||||
|
|
||||||
if (!isNullOrEmpty(jsonResponse.getObject("error"))) {
|
checkIfChannelResponseIsValid(jsonResponse);
|
||||||
final JsonObject errorJsonObject = jsonResponse.getObject("error");
|
|
||||||
final int errorCode = errorJsonObject.getInt("code");
|
|
||||||
if (errorCode == 404) {
|
|
||||||
throw new ContentNotAvailableException("This channel doesn't exist.");
|
|
||||||
} else {
|
|
||||||
throw new ContentNotAvailableException("Got error:\""
|
|
||||||
+ errorJsonObject.getString("status") + "\": "
|
|
||||||
+ errorJsonObject.getString("message"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final JsonObject endpoint = jsonResponse.getObject("endpoint");
|
final JsonObject endpoint = jsonResponse.getObject("endpoint");
|
||||||
|
|
||||||
|
@ -1830,9 +1820,7 @@ public final class YoutubeParsingHelper {
|
||||||
* @param params Parameters to specify the YouTube channel tab
|
* @param params Parameters to specify the YouTube channel tab
|
||||||
* @param loc YouTube localization
|
* @param loc YouTube localization
|
||||||
* @param country YouTube content country
|
* @param country YouTube content country
|
||||||
* @return
|
* @return Channel response data
|
||||||
* @throws ExtractionException
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
*/
|
||||||
public static ChannelResponseData getChannelResponse(final String channelId,
|
public static ChannelResponseData getChannelResponse(final String channelId,
|
||||||
final String params,
|
final String params,
|
||||||
|
@ -1853,17 +1841,7 @@ public final class YoutubeParsingHelper {
|
||||||
|
|
||||||
final JsonObject jsonResponse = getJsonPostResponse("browse", body, loc);
|
final JsonObject jsonResponse = getJsonPostResponse("browse", body, loc);
|
||||||
|
|
||||||
if (!isNullOrEmpty(jsonResponse.getObject("error"))) {
|
checkIfChannelResponseIsValid(jsonResponse);
|
||||||
final JsonObject errorJsonObject = jsonResponse.getObject("error");
|
|
||||||
final int errorCode = errorJsonObject.getInt("code");
|
|
||||||
if (errorCode == 404) {
|
|
||||||
throw new ContentNotAvailableException("This channel doesn't exist.");
|
|
||||||
} else {
|
|
||||||
throw new ContentNotAvailableException("Got error:\""
|
|
||||||
+ errorJsonObject.getString("status") + "\": "
|
|
||||||
+ errorJsonObject.getString("message"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final JsonObject endpoint = jsonResponse.getArray("onResponseReceivedActions")
|
final JsonObject endpoint = jsonResponse.getArray("onResponseReceivedActions")
|
||||||
.getObject(0)
|
.getObject(0)
|
||||||
|
@ -1901,6 +1879,26 @@ public final class YoutubeParsingHelper {
|
||||||
return new ChannelResponseData(ajaxJson, id);
|
return new ChannelResponseData(ajaxJson, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assert that a channel JSON response does not contain a 404 error.
|
||||||
|
* @param jsonResponse channel JSON response
|
||||||
|
* @throws ContentNotAvailableException if the channel was not found
|
||||||
|
*/
|
||||||
|
private static void checkIfChannelResponseIsValid(@Nonnull final JsonObject jsonResponse)
|
||||||
|
throws ContentNotAvailableException {
|
||||||
|
if (!isNullOrEmpty(jsonResponse.getObject("error"))) {
|
||||||
|
final JsonObject errorJsonObject = jsonResponse.getObject("error");
|
||||||
|
final int errorCode = errorJsonObject.getInt("code");
|
||||||
|
if (errorCode == 404) {
|
||||||
|
throw new ContentNotAvailableException("This channel doesn't exist.");
|
||||||
|
} else {
|
||||||
|
throw new ContentNotAvailableException("Got error:\""
|
||||||
|
+ errorJsonObject.getString("status") + "\": "
|
||||||
|
+ errorJsonObject.getString("message"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a content playback nonce (also called {@code cpn}), sent by YouTube clients in
|
* Generate a content playback nonce (also called {@code cpn}), sent by YouTube clients in
|
||||||
* playback requests (and also for some clients, in the player request body).
|
* playback requests (and also for some clients, in the player request body).
|
||||||
|
|
Loading…
Reference in New Issue