mirror of
https://github.com/TeamNewPipe/NewPipeExtractor
synced 2025-08-29 13:27:38 +00:00
[YouTube] Add WEB_MUSIC_ANALYTICS constants, make some methods public
This is the client for YouTube Charts (charts.youtube.com). Also change nullability of two fields and fix wrong client constant usage in ofWebEmbeddedPlayerClient method in InnertubeClientRequestInfo. Usages in YoutubeParsingHelper have been updated, getClientHeaders and prepareJsonBuilder methods in this class have been made public.
This commit is contained in:
parent
f4b0a7d97e
commit
a4aeedff90
@ -45,6 +45,12 @@ final class ClientsConstants {
|
|||||||
static final String WEB_EMBEDDED_CLIENT_NAME = "WEB_EMBEDDED_PLAYER";
|
static final String WEB_EMBEDDED_CLIENT_NAME = "WEB_EMBEDDED_PLAYER";
|
||||||
static final String WEB_EMBEDDED_CLIENT_VERSION = "1.20250121.00.00";
|
static final String WEB_EMBEDDED_CLIENT_VERSION = "1.20250121.00.00";
|
||||||
|
|
||||||
|
// WEB_MUSIC_ANALYTICS (YouTube charts)
|
||||||
|
|
||||||
|
static final String WEB_MUSIC_ANALYTICS_CLIENT_ID = "31";
|
||||||
|
static final String WEB_MUSIC_ANALYTICS_CLIENT_NAME = "WEB_MUSIC_ANALYTICS";
|
||||||
|
static final String WEB_MUSIC_ANALYTICS_CLIENT_VERSION = "2.0";
|
||||||
|
|
||||||
// IOS (iOS YouTube app) client fields
|
// IOS (iOS YouTube app) client fields
|
||||||
|
|
||||||
static final String IOS_CLIENT_ID = "5";
|
static final String IOS_CLIENT_ID = "5";
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package org.schabi.newpipe.extractor.services.youtube;
|
package org.schabi.newpipe.extractor.services.youtube;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.ANDROID_CLIENT_ID;
|
import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.ANDROID_CLIENT_ID;
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.ANDROID_CLIENT_NAME;
|
import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.ANDROID_CLIENT_NAME;
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.ANDROID_CLIENT_VERSION;
|
import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.ANDROID_CLIENT_VERSION;
|
||||||
@ -16,11 +19,11 @@ import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.WEB
|
|||||||
import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.WEB_CLIENT_NAME;
|
import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.WEB_CLIENT_NAME;
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.WEB_EMBEDDED_CLIENT_ID;
|
import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.WEB_EMBEDDED_CLIENT_ID;
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.WEB_EMBEDDED_CLIENT_NAME;
|
import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.WEB_EMBEDDED_CLIENT_NAME;
|
||||||
|
import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.WEB_EMBEDDED_CLIENT_VERSION;
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.WEB_HARDCODED_CLIENT_VERSION;
|
import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.WEB_HARDCODED_CLIENT_VERSION;
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.WEB_REMIX_HARDCODED_CLIENT_VERSION;
|
import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.WEB_MUSIC_ANALYTICS_CLIENT_ID;
|
||||||
|
import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.WEB_MUSIC_ANALYTICS_CLIENT_NAME;
|
||||||
import javax.annotation.Nonnull;
|
import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.WEB_MUSIC_ANALYTICS_CLIENT_VERSION;
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
// TODO: add docs
|
// TODO: add docs
|
||||||
|
|
||||||
@ -38,28 +41,28 @@ public final class InnertubeClientRequestInfo {
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
public String clientVersion;
|
public String clientVersion;
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public String clientScreen;
|
|
||||||
@Nullable
|
|
||||||
public String clientId;
|
public String clientId;
|
||||||
@Nullable
|
@Nullable
|
||||||
|
public String clientScreen;
|
||||||
|
@Nullable
|
||||||
public String visitorData;
|
public String visitorData;
|
||||||
|
|
||||||
private ClientInfo(@Nonnull final String clientName,
|
private ClientInfo(@Nonnull final String clientName,
|
||||||
@Nonnull final String clientVersion,
|
@Nonnull final String clientVersion,
|
||||||
@Nonnull final String clientScreen,
|
@Nonnull final String clientId,
|
||||||
@Nullable final String clientId,
|
@Nullable final String clientScreen,
|
||||||
@Nullable final String visitorData) {
|
@Nullable final String visitorData) {
|
||||||
this.clientName = clientName;
|
this.clientName = clientName;
|
||||||
this.clientVersion = clientVersion;
|
this.clientVersion = clientVersion;
|
||||||
this.clientScreen = clientScreen;
|
|
||||||
this.clientId = clientId;
|
this.clientId = clientId;
|
||||||
|
this.clientScreen = clientScreen;
|
||||||
this.visitorData = visitorData;
|
this.visitorData = visitorData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class DeviceInfo {
|
public static final class DeviceInfo {
|
||||||
|
|
||||||
@Nonnull
|
@Nullable
|
||||||
public String platform;
|
public String platform;
|
||||||
@Nullable
|
@Nullable
|
||||||
public String deviceMake;
|
public String deviceMake;
|
||||||
@ -71,7 +74,7 @@ public final class InnertubeClientRequestInfo {
|
|||||||
public String osVersion;
|
public String osVersion;
|
||||||
public int androidSdkVersion;
|
public int androidSdkVersion;
|
||||||
|
|
||||||
private DeviceInfo(@Nonnull final String platform,
|
private DeviceInfo(@Nullable final String platform,
|
||||||
@Nullable final String deviceMake,
|
@Nullable final String deviceMake,
|
||||||
@Nullable final String deviceModel,
|
@Nullable final String deviceModel,
|
||||||
@Nullable final String osName,
|
@Nullable final String osName,
|
||||||
@ -96,8 +99,8 @@ public final class InnertubeClientRequestInfo {
|
|||||||
public static InnertubeClientRequestInfo ofWebClient() {
|
public static InnertubeClientRequestInfo ofWebClient() {
|
||||||
return new InnertubeClientRequestInfo(
|
return new InnertubeClientRequestInfo(
|
||||||
new InnertubeClientRequestInfo.ClientInfo(
|
new InnertubeClientRequestInfo.ClientInfo(
|
||||||
WEB_CLIENT_NAME, WEB_HARDCODED_CLIENT_VERSION, WATCH_CLIENT_SCREEN,
|
WEB_CLIENT_NAME, WEB_HARDCODED_CLIENT_VERSION, WEB_CLIENT_ID,
|
||||||
WEB_CLIENT_ID, null),
|
WATCH_CLIENT_SCREEN, null),
|
||||||
new InnertubeClientRequestInfo.DeviceInfo(DESKTOP_CLIENT_PLATFORM, null, null,
|
new InnertubeClientRequestInfo.DeviceInfo(DESKTOP_CLIENT_PLATFORM, null, null,
|
||||||
null, null, -1));
|
null, null, -1));
|
||||||
}
|
}
|
||||||
@ -106,17 +109,27 @@ public final class InnertubeClientRequestInfo {
|
|||||||
public static InnertubeClientRequestInfo ofWebEmbeddedPlayerClient() {
|
public static InnertubeClientRequestInfo ofWebEmbeddedPlayerClient() {
|
||||||
return new InnertubeClientRequestInfo(
|
return new InnertubeClientRequestInfo(
|
||||||
new InnertubeClientRequestInfo.ClientInfo(WEB_EMBEDDED_CLIENT_NAME,
|
new InnertubeClientRequestInfo.ClientInfo(WEB_EMBEDDED_CLIENT_NAME,
|
||||||
WEB_REMIX_HARDCODED_CLIENT_VERSION, EMBED_CLIENT_SCREEN,
|
WEB_EMBEDDED_CLIENT_VERSION, WEB_EMBEDDED_CLIENT_ID, EMBED_CLIENT_SCREEN,
|
||||||
WEB_EMBEDDED_CLIENT_ID, null),
|
null),
|
||||||
new InnertubeClientRequestInfo.DeviceInfo(DESKTOP_CLIENT_PLATFORM, null, null,
|
new InnertubeClientRequestInfo.DeviceInfo(DESKTOP_CLIENT_PLATFORM, null, null,
|
||||||
null, null, -1));
|
null, null, -1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
public static InnertubeClientRequestInfo ofWebMusicAnalyticsChartsClient() {
|
||||||
|
return new InnertubeClientRequestInfo(
|
||||||
|
new InnertubeClientRequestInfo.ClientInfo(WEB_MUSIC_ANALYTICS_CLIENT_NAME,
|
||||||
|
WEB_MUSIC_ANALYTICS_CLIENT_VERSION, WEB_MUSIC_ANALYTICS_CLIENT_ID, null,
|
||||||
|
null),
|
||||||
|
new InnertubeClientRequestInfo.DeviceInfo(null, null, null,
|
||||||
|
null, null, -1));
|
||||||
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static InnertubeClientRequestInfo ofAndroidClient() {
|
public static InnertubeClientRequestInfo ofAndroidClient() {
|
||||||
return new InnertubeClientRequestInfo(
|
return new InnertubeClientRequestInfo(
|
||||||
new InnertubeClientRequestInfo.ClientInfo(ANDROID_CLIENT_NAME,
|
new InnertubeClientRequestInfo.ClientInfo(ANDROID_CLIENT_NAME,
|
||||||
ANDROID_CLIENT_VERSION, WATCH_CLIENT_SCREEN, ANDROID_CLIENT_ID, null),
|
ANDROID_CLIENT_VERSION, ANDROID_CLIENT_ID, WATCH_CLIENT_SCREEN, null),
|
||||||
new InnertubeClientRequestInfo.DeviceInfo(MOBILE_CLIENT_PLATFORM, null, null,
|
new InnertubeClientRequestInfo.DeviceInfo(MOBILE_CLIENT_PLATFORM, null, null,
|
||||||
"Android", "15", 35));
|
"Android", "15", 35));
|
||||||
}
|
}
|
||||||
@ -125,7 +138,7 @@ public final class InnertubeClientRequestInfo {
|
|||||||
public static InnertubeClientRequestInfo ofIosClient() {
|
public static InnertubeClientRequestInfo ofIosClient() {
|
||||||
return new InnertubeClientRequestInfo(
|
return new InnertubeClientRequestInfo(
|
||||||
new InnertubeClientRequestInfo.ClientInfo(IOS_CLIENT_NAME, IOS_CLIENT_VERSION,
|
new InnertubeClientRequestInfo.ClientInfo(IOS_CLIENT_NAME, IOS_CLIENT_VERSION,
|
||||||
WATCH_CLIENT_SCREEN, IOS_CLIENT_ID, null),
|
IOS_CLIENT_ID, WATCH_CLIENT_SCREEN, null),
|
||||||
new InnertubeClientRequestInfo.DeviceInfo(MOBILE_CLIENT_PLATFORM, "Apple",
|
new InnertubeClientRequestInfo.DeviceInfo(MOBILE_CLIENT_PLATFORM, "Apple",
|
||||||
IOS_DEVICE_MODEL, "iOS", IOS_OS_VERSION, -1));
|
IOS_DEVICE_MODEL, "iOS", IOS_OS_VERSION, -1));
|
||||||
}
|
}
|
||||||
|
@ -1181,7 +1181,7 @@ public final class YoutubeParsingHelper {
|
|||||||
* @param name The X-YouTube-Client-Name value.
|
* @param name The X-YouTube-Client-Name value.
|
||||||
* @param version X-YouTube-Client-Version value.
|
* @param version X-YouTube-Client-Version value.
|
||||||
*/
|
*/
|
||||||
static Map<String, List<String>> getClientHeaders(@Nonnull final String name,
|
public static Map<String, List<String>> getClientHeaders(@Nonnull final String name,
|
||||||
@Nonnull final String version) {
|
@Nonnull final String version) {
|
||||||
return Map.of("X-YouTube-Client-Name", List.of(name),
|
return Map.of("X-YouTube-Client-Name", List.of(name),
|
||||||
"X-YouTube-Client-Version", List.of(version));
|
"X-YouTube-Client-Version", List.of(version));
|
||||||
@ -1525,7 +1525,7 @@ public final class YoutubeParsingHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
static JsonBuilder<JsonObject> prepareJsonBuilder(
|
public static JsonBuilder<JsonObject> prepareJsonBuilder(
|
||||||
@Nonnull final Localization localization,
|
@Nonnull final Localization localization,
|
||||||
@Nonnull final ContentCountry contentCountry,
|
@Nonnull final ContentCountry contentCountry,
|
||||||
@Nonnull final InnertubeClientRequestInfo innertubeClientRequestInfo,
|
@Nonnull final InnertubeClientRequestInfo innertubeClientRequestInfo,
|
||||||
@ -1534,9 +1534,15 @@ public final class YoutubeParsingHelper {
|
|||||||
.object("context")
|
.object("context")
|
||||||
.object("client")
|
.object("client")
|
||||||
.value("clientName", innertubeClientRequestInfo.clientInfo.clientName)
|
.value("clientName", innertubeClientRequestInfo.clientInfo.clientName)
|
||||||
.value("clientVersion", innertubeClientRequestInfo.clientInfo.clientVersion)
|
.value("clientVersion", innertubeClientRequestInfo.clientInfo.clientVersion);
|
||||||
.value("clientScreen", innertubeClientRequestInfo.clientInfo.clientScreen)
|
|
||||||
.value("platform", innertubeClientRequestInfo.deviceInfo.platform);
|
if (innertubeClientRequestInfo.clientInfo.clientScreen != null) {
|
||||||
|
builder.value("clientScreen", innertubeClientRequestInfo.clientInfo.clientScreen);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (innertubeClientRequestInfo.deviceInfo.platform != null) {
|
||||||
|
builder.value("platform", innertubeClientRequestInfo.deviceInfo.platform);
|
||||||
|
}
|
||||||
|
|
||||||
if (innertubeClientRequestInfo.clientInfo.visitorData != null) {
|
if (innertubeClientRequestInfo.clientInfo.visitorData != null) {
|
||||||
builder.value("visitorData", innertubeClientRequestInfo.clientInfo.visitorData);
|
builder.value("visitorData", innertubeClientRequestInfo.clientInfo.visitorData);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user