[YouTube] Support new client in YoutubeHttpDataSource

This commit is contained in:
AudricV
2026-06-09 23:36:41 +02:00
parent 1058370db0
commit 058810f452
@@ -14,8 +14,10 @@ import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
import static com.google.android.exoplayer2.util.Util.castNonNull;
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getAndroidUserAgent;
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getIosUserAgent;
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getVisionOsUserAgent;
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.isAndroidStreamingUrl;
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.isIosStreamingUrl;
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.isVisionOsStreamingUrl;
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.isWebStreamingUrl;
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.isWebEmbeddedPlayerStreamingUrl;
import static java.lang.Math.min;
@@ -670,16 +672,17 @@ public final class YoutubeHttpDataSource extends BaseDataSource implements HttpD
httpURLConnection.setRequestProperty(HttpHeaders.TE, "trailers");
final boolean isAndroidStreamingUrl = isAndroidStreamingUrl(requestUrl);
final boolean isIosStreamingUrl = isIosStreamingUrl(requestUrl);
if (isAndroidStreamingUrl) {
if (isAndroidStreamingUrl(requestUrl)) {
// Improvement which may be done: find the content country used to request YouTube
// contents to add it in the user agent instead of using the default
httpURLConnection.setRequestProperty(HttpHeaders.USER_AGENT,
getAndroidUserAgent(null));
} else if (isIosStreamingUrl) {
} else if (isIosStreamingUrl(requestUrl)) {
httpURLConnection.setRequestProperty(HttpHeaders.USER_AGENT,
getIosUserAgent(null));
} else if (isVisionOsStreamingUrl(requestUrl)) {
httpURLConnection.setRequestProperty(HttpHeaders.USER_AGENT,
getVisionOsUserAgent(null));
} else {
// non-mobile user agent
httpURLConnection.setRequestProperty(HttpHeaders.USER_AGENT, DownloaderImpl.USER_AGENT);