|
| 1 | +package org.schabi.newpipe.extractor.services.youtube; |
| 2 | + |
| 3 | +import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.ANDROID_CLIENT_ID; |
| 4 | +import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.ANDROID_CLIENT_NAME; |
| 5 | +import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.ANDROID_CLIENT_VERSION; |
| 6 | +import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.DESKTOP_CLIENT_PLATFORM; |
| 7 | +import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.EMBED_CLIENT_SCREEN; |
| 8 | +import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.IOS_CLIENT_ID; |
| 9 | +import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.IOS_CLIENT_NAME; |
| 10 | +import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.IOS_CLIENT_VERSION; |
| 11 | +import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.IOS_DEVICE_MODEL; |
| 12 | +import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.IOS_OS_VERSION; |
| 13 | +import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.MOBILE_CLIENT_PLATFORM; |
| 14 | +import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.TVHTML5_CLIENT_ID; |
| 15 | +import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.TVHTML5_CLIENT_NAME; |
| 16 | +import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.TVHTML5_CLIENT_PLATFORM; |
| 17 | +import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.TVHTML5_CLIENT_VERSION; |
| 18 | +import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.TVHTML5_DEVICE_MAKE; |
| 19 | +import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.TVHTML5_DEVICE_MODEL_AND_OS_NAME; |
| 20 | +import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.WATCH_CLIENT_SCREEN; |
| 21 | +import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.WEB_CLIENT_ID; |
| 22 | +import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.WEB_CLIENT_NAME; |
| 23 | +import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.WEB_EMBEDDED_CLIENT_ID; |
| 24 | +import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.WEB_EMBEDDED_CLIENT_NAME; |
| 25 | +import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.WEB_HARDCODED_CLIENT_VERSION; |
| 26 | +import static org.schabi.newpipe.extractor.services.youtube.ClientsConstants.WEB_REMIX_HARDCODED_CLIENT_VERSION; |
| 27 | + |
| 28 | +import javax.annotation.Nonnull; |
| 29 | +import javax.annotation.Nullable; |
| 30 | + |
| 31 | +// TODO: add docs |
| 32 | + |
| 33 | +public final class InnertubeClientRequestInfo { |
| 34 | + |
| 35 | + @Nonnull |
| 36 | + public ClientInfo clientInfo; |
| 37 | + @Nonnull |
| 38 | + public DeviceInfo deviceInfo; |
| 39 | + |
| 40 | + public static final class ClientInfo { |
| 41 | + |
| 42 | + @Nonnull |
| 43 | + public String clientName; |
| 44 | + @Nonnull |
| 45 | + public String clientVersion; |
| 46 | + @Nonnull |
| 47 | + public String clientScreen; |
| 48 | + @Nullable |
| 49 | + public String clientId; |
| 50 | + @Nullable |
| 51 | + public String visitorData; |
| 52 | + |
| 53 | + private ClientInfo(@Nonnull final String clientName, |
| 54 | + @Nonnull final String clientVersion, |
| 55 | + @Nonnull final String clientScreen, |
| 56 | + @Nullable final String clientId, |
| 57 | + @Nullable final String visitorData) { |
| 58 | + this.clientName = clientName; |
| 59 | + this.clientVersion = clientVersion; |
| 60 | + this.clientScreen = clientScreen; |
| 61 | + this.clientId = clientId; |
| 62 | + this.visitorData = visitorData; |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + public static final class DeviceInfo { |
| 67 | + |
| 68 | + @Nonnull |
| 69 | + public String platform; |
| 70 | + @Nullable |
| 71 | + public String deviceMake; |
| 72 | + @Nullable |
| 73 | + public String deviceModel; |
| 74 | + @Nullable |
| 75 | + public String osName; |
| 76 | + @Nullable |
| 77 | + public String osVersion; |
| 78 | + public int androidSdkVersion; |
| 79 | + |
| 80 | + private DeviceInfo(@Nonnull final String platform, |
| 81 | + @Nullable final String deviceMake, |
| 82 | + @Nullable final String deviceModel, |
| 83 | + @Nullable final String osName, |
| 84 | + @Nullable final String osVersion, |
| 85 | + final int androidSdkVersion) { |
| 86 | + this.platform = platform; |
| 87 | + this.deviceMake = deviceMake; |
| 88 | + this.deviceModel = deviceModel; |
| 89 | + this.osName = osName; |
| 90 | + this.osVersion = osVersion; |
| 91 | + this.androidSdkVersion = androidSdkVersion; |
| 92 | + } |
| 93 | + } |
| 94 | + |
| 95 | + private InnertubeClientRequestInfo(@Nonnull final ClientInfo clientInfo, |
| 96 | + @Nonnull final DeviceInfo deviceInfo) { |
| 97 | + this.clientInfo = clientInfo; |
| 98 | + this.deviceInfo = deviceInfo; |
| 99 | + } |
| 100 | + |
| 101 | + @Nonnull |
| 102 | + public static InnertubeClientRequestInfo ofWebClient() { |
| 103 | + return new InnertubeClientRequestInfo( |
| 104 | + new InnertubeClientRequestInfo.ClientInfo( |
| 105 | + WEB_CLIENT_NAME, WEB_HARDCODED_CLIENT_VERSION, WATCH_CLIENT_SCREEN, |
| 106 | + WEB_CLIENT_ID, null), |
| 107 | + new InnertubeClientRequestInfo.DeviceInfo(DESKTOP_CLIENT_PLATFORM, null, null, |
| 108 | + null, null, -1)); |
| 109 | + } |
| 110 | + |
| 111 | + @Nonnull |
| 112 | + public static InnertubeClientRequestInfo ofWebEmbeddedPlayerClient() { |
| 113 | + return new InnertubeClientRequestInfo( |
| 114 | + new InnertubeClientRequestInfo.ClientInfo(WEB_EMBEDDED_CLIENT_NAME, |
| 115 | + WEB_REMIX_HARDCODED_CLIENT_VERSION, EMBED_CLIENT_SCREEN, |
| 116 | + WEB_EMBEDDED_CLIENT_ID, null), |
| 117 | + new InnertubeClientRequestInfo.DeviceInfo(DESKTOP_CLIENT_PLATFORM, null, null, |
| 118 | + null, null, -1)); |
| 119 | + } |
| 120 | + |
| 121 | + @Nonnull |
| 122 | + public static InnertubeClientRequestInfo ofTvHtml5Client() { |
| 123 | + return new InnertubeClientRequestInfo( |
| 124 | + new InnertubeClientRequestInfo.ClientInfo(TVHTML5_CLIENT_NAME, |
| 125 | + TVHTML5_CLIENT_VERSION, WATCH_CLIENT_SCREEN, TVHTML5_CLIENT_ID, null), |
| 126 | + new InnertubeClientRequestInfo.DeviceInfo(TVHTML5_CLIENT_PLATFORM, |
| 127 | + TVHTML5_DEVICE_MAKE, TVHTML5_DEVICE_MODEL_AND_OS_NAME, |
| 128 | + TVHTML5_DEVICE_MODEL_AND_OS_NAME, "", -1)); |
| 129 | + } |
| 130 | + |
| 131 | + @Nonnull |
| 132 | + public static InnertubeClientRequestInfo ofAndroidClient() { |
| 133 | + return new InnertubeClientRequestInfo( |
| 134 | + new InnertubeClientRequestInfo.ClientInfo(ANDROID_CLIENT_NAME, |
| 135 | + ANDROID_CLIENT_VERSION, WATCH_CLIENT_SCREEN, ANDROID_CLIENT_ID, null), |
| 136 | + new InnertubeClientRequestInfo.DeviceInfo(MOBILE_CLIENT_PLATFORM, null, null, |
| 137 | + "Android", "15", 35)); |
| 138 | + } |
| 139 | + |
| 140 | + @Nonnull |
| 141 | + public static InnertubeClientRequestInfo ofIosClient() { |
| 142 | + return new InnertubeClientRequestInfo( |
| 143 | + new InnertubeClientRequestInfo.ClientInfo(IOS_CLIENT_NAME, IOS_CLIENT_VERSION, |
| 144 | + WATCH_CLIENT_SCREEN, IOS_CLIENT_ID, null), |
| 145 | + new InnertubeClientRequestInfo.DeviceInfo(MOBILE_CLIENT_PLATFORM, "Apple", |
| 146 | + IOS_DEVICE_MODEL, "iOS", IOS_OS_VERSION, -1)); |
| 147 | + } |
| 148 | +} |
0 commit comments