Apply requested codestyle improvements.

This commit is contained in:
FireMasterK 2022-02-26 17:12:51 +00:00
parent 6950b362f2
commit e6d334765d
No known key found for this signature in database
GPG key ID: 49451E4482CC5BCD
2 changed files with 34 additions and 36 deletions

View file

@ -89,9 +89,9 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
// we couldn't get information about the channel associated with this URL, if there is one. // we couldn't get information about the channel associated with this URL, if there is one.
if (!channelId[0].equals("channel")) { if (!channelId[0].equals("channel")) {
final byte[] body = JsonWriter.string(prepareDesktopJsonBuilder( final byte[] body = JsonWriter.string(prepareDesktopJsonBuilder(
getExtractorLocalization(), getExtractorContentCountry()) getExtractorLocalization(), getExtractorContentCountry())
.value("url", "https://www.youtube.com/" + channelPath) .value("url", "https://www.youtube.com/" + channelPath)
.done()) .done())
.getBytes(UTF_8); .getBytes(UTF_8);
final JsonObject jsonResponse = getJsonPostResponse("navigation/resolve_url", final JsonObject jsonResponse = getJsonPostResponse("navigation/resolve_url",
@ -104,8 +104,8 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
throw new ContentNotAvailableException("This channel doesn't exist."); throw new ContentNotAvailableException("This channel doesn't exist.");
} else { } else {
throw new ContentNotAvailableException("Got error:\"" throw new ContentNotAvailableException("Got error:\""
+ errorJsonObject.getString("status") + "\": " + errorJsonObject.getString("status") + "\": "
+ errorJsonObject.getString("message")); + errorJsonObject.getString("message"));
} }
} }
@ -136,10 +136,10 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
int level = 0; int level = 0;
while (level < 3) { while (level < 3) {
final byte[] body = JsonWriter.string(prepareDesktopJsonBuilder( final byte[] body = JsonWriter.string(prepareDesktopJsonBuilder(
getExtractorLocalization(), getExtractorContentCountry()) getExtractorLocalization(), getExtractorContentCountry())
.value("browseId", id) .value("browseId", id)
.value("params", "EgZ2aWRlb3M%3D") // Equal to videos .value("params", "EgZ2aWRlb3M%3D") // Equal to videos
.done()) .done())
.getBytes(UTF_8); .getBytes(UTF_8);
final JsonObject jsonResponse = getJsonPostResponse("browse", body, final JsonObject jsonResponse = getJsonPostResponse("browse", body,
@ -273,16 +273,15 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
public long getSubscriberCount() throws ParsingException { public long getSubscriberCount() throws ParsingException {
final JsonObject c4TabbedHeaderRenderer = initialData.getObject("header") final JsonObject c4TabbedHeaderRenderer = initialData.getObject("header")
.getObject("c4TabbedHeaderRenderer"); .getObject("c4TabbedHeaderRenderer");
if (c4TabbedHeaderRenderer.has("subscriberCountText")) { if (!c4TabbedHeaderRenderer.has("subscriberCountText")) {
try {
return Utils.mixedNumberWordToLong(getTextFromObject(c4TabbedHeaderRenderer
.getObject("subscriberCountText")));
} catch (final NumberFormatException e) {
throw new ParsingException("Could not get subscriber count", e);
}
} else {
return UNKNOWN_SUBSCRIBER_COUNT; return UNKNOWN_SUBSCRIBER_COUNT;
} }
try {
return Utils.mixedNumberWordToLong(getTextFromObject(c4TabbedHeaderRenderer
.getObject("subscriberCountText")));
} catch (final NumberFormatException e) {
throw new ParsingException("Could not get subscriber count", e);
}
} }
@Override @Override
@ -385,9 +384,9 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
.getString("token"); .getString("token");
final byte[] body = JsonWriter.string(prepareDesktopJsonBuilder(getExtractorLocalization(), final byte[] body = JsonWriter.string(prepareDesktopJsonBuilder(getExtractorLocalization(),
getExtractorContentCountry()) getExtractorContentCountry())
.value("continuation", continuation) .value("continuation", continuation)
.done()) .done())
.getBytes(UTF_8); .getBytes(UTF_8);
return new Page(YOUTUBEI_V1_URL + "browse?key=" + getKey(), null, channelIds, null, body); return new Page(YOUTUBEI_V1_URL + "browse?key=" + getKey(), null, channelIds, null, body);

View file

@ -180,7 +180,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
// TODO: this parses English formatted dates only, we need a better approach to parse // TODO: this parses English formatted dates only, we need a better approach to parse
// the textual date // the textual date
final LocalDate localDate = LocalDate.parse(getTextFromObject( final LocalDate localDate = LocalDate.parse(getTextFromObject(
getVideoPrimaryInfoRenderer().getObject("dateText")), getVideoPrimaryInfoRenderer().getObject("dateText")),
DateTimeFormatter.ofPattern("dd MMM yyyy", Locale.ENGLISH)); DateTimeFormatter.ofPattern("dd MMM yyyy", Locale.ENGLISH));
return DateTimeFormatter.ISO_LOCAL_DATE.format(localDate); return DateTimeFormatter.ISO_LOCAL_DATE.format(localDate);
} catch (final Exception ignored) { } catch (final Exception ignored) {
@ -440,15 +440,14 @@ public class YoutubeStreamExtractor extends StreamExtractor {
@Override @Override
public long getUploaderSubscriberCount() throws ParsingException { public long getUploaderSubscriberCount() throws ParsingException {
final JsonObject videoOwnerRenderer = JsonUtils.getObject(videoSecondaryInfoRenderer, "owner.videoOwnerRenderer"); final JsonObject videoOwnerRenderer = JsonUtils.getObject(videoSecondaryInfoRenderer, "owner.videoOwnerRenderer");
if (videoOwnerRenderer.has("subscriberCountText")) { if (!videoOwnerRenderer.has("subscriberCountText")) {
try {
return Utils.mixedNumberWordToLong(getTextFromObject(videoOwnerRenderer.getObject("subscriberCountText")));
} catch (final NumberFormatException e) {
throw new ParsingException("Could not get uploader subscriber count", e);
}
} else {
return UNKNOWN_SUBSCRIBER_COUNT; return UNKNOWN_SUBSCRIBER_COUNT;
} }
try {
return Utils.mixedNumberWordToLong(getTextFromObject(videoOwnerRenderer.getObject("subscriberCountText")));
} catch (final NumberFormatException e) {
throw new ParsingException("Could not get uploader subscriber count", e);
}
} }
@Nonnull @Nonnull
@ -680,9 +679,9 @@ public class YoutubeStreamExtractor extends StreamExtractor {
final Localization localization = getExtractorLocalization(); final Localization localization = getExtractorLocalization();
final ContentCountry contentCountry = getExtractorContentCountry(); final ContentCountry contentCountry = getExtractorContentCountry();
final byte[] body = JsonWriter.string(prepareDesktopJsonBuilder( final byte[] body = JsonWriter.string(prepareDesktopJsonBuilder(
localization, contentCountry) localization, contentCountry)
.value("videoId", videoId) .value("videoId", videoId)
.done()) .done())
.getBytes(UTF_8); .getBytes(UTF_8);
// Put the sts string if we already know it so we don't have to fetch again the player // Put the sts string if we already know it so we don't have to fetch again the player
@ -731,8 +730,8 @@ public class YoutubeStreamExtractor extends StreamExtractor {
if (ageRestricted) { if (ageRestricted) {
final byte[] ageRestrictedBody = JsonWriter.string(prepareDesktopEmbedVideoJsonBuilder( final byte[] ageRestrictedBody = JsonWriter.string(prepareDesktopEmbedVideoJsonBuilder(
localization, contentCountry, videoId) localization, contentCountry, videoId)
.done()) .done())
.getBytes(UTF_8); .getBytes(UTF_8);
nextResponse = getJsonPostResponse("next", ageRestrictedBody, localization); nextResponse = getJsonPostResponse("next", ageRestrictedBody, localization);
} else { } else {
@ -814,7 +813,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
final String videoId) final String videoId)
throws IOException, ExtractionException { throws IOException, ExtractionException {
final byte[] mobileBody = JsonWriter.string(prepareAndroidMobileJsonBuilder( final byte[] mobileBody = JsonWriter.string(prepareAndroidMobileJsonBuilder(
localization, contentCountry) localization, contentCountry)
.value("videoId", videoId) .value("videoId", videoId)
.done()) .done())
.getBytes(UTF_8); .getBytes(UTF_8);
@ -887,8 +886,8 @@ public class YoutubeStreamExtractor extends StreamExtractor {
final String videoId) final String videoId)
throws IOException, ExtractionException { throws IOException, ExtractionException {
final byte[] androidMobileEmbedBody = JsonWriter.string( final byte[] androidMobileEmbedBody = JsonWriter.string(
prepareAndroidMobileEmbedVideoJsonBuilder(localization, contentCountry, videoId) prepareAndroidMobileEmbedVideoJsonBuilder(localization, contentCountry, videoId)
.done()) .done())
.getBytes(UTF_8); .getBytes(UTF_8);
final JsonObject androidMobileEmbedPlayerResponse = getJsonMobilePostResponse("player", final JsonObject androidMobileEmbedPlayerResponse = getJsonMobilePostResponse("player",
androidMobileEmbedBody, contentCountry, localization); androidMobileEmbedBody, contentCountry, localization);