Add androidSdkless client to fix 403 errors on audio-only streams - #371
Conversation
Co-authored-by: binSaed <33700292+binSaed@users.noreply.github.com>
Add androidSdkless client to fix 403 errors on audio-only streams
There was a problem hiding this comment.
Pull request overview
This PR adds a new androidSdkless YouTube API client to fix 403 errors that occur when streaming audio-only content. The root cause is that the existing android client includes an androidSdkVersion field which triggers YouTube's PO Token requirement.
Changes:
- Added
YoutubeApiClient.androidSdklessclient based on yt-dlp's working implementation that omits theandroidSdkVersionfield - Changed the default client from
androidtoandroidSdklessinStreamClient.getManifest() - Updated documentation for the existing
androidclient to note PO Token requirements
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| lib/src/videos/youtube_api_client.dart | Adds new androidSdkless client constant and updates android client documentation |
| lib/src/videos/streams/stream_client.dart | Changes default client to androidSdkless for better compatibility |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| videoId = VideoId.fromString(videoId); | ||
| final clients = ytClients ?? [YoutubeApiClient.android]; | ||
| final clients = ytClients ?? [YoutubeApiClient.androidSdkless]; |
There was a problem hiding this comment.
Consider adding a specific test case that validates the androidSdkless client works correctly with audio-only streams to prevent regressions of the 403 error issue this PR aims to fix. The test could use ytClients parameter to explicitly test both the old android client (expecting potential 403 errors) and the new androidSdkless client (expecting success).
IssueCodefinal manifests = await _yt.videos.streams.getManifest( videoId);
final availableManifests = List<AudioStreamInfo>.of([]);
await Future.wait([
for (final manifest in manifests.audio)
http.head(manifest.url).then((res) {
print('$manifest : ${res.statusCode}');
if (res.statusCode > 299 || res.statusCode < 200) return;
availableManifests.add(manifest);
}),
]);Result |
|
شكرااا |
Audio-only streams return 403 while muxed streams work. Root cause: the
androidclient includesandroidSdkVersionwhich triggers YouTube's PO Token requirement.Changes
YoutubeApiClient.androidSdkless— Android client withoutandroidSdkVersionfield, based on yt-dlp's working implementationandroidtoandroidSdklessinStreamClient.getManifest()Reference
From yt-dlp's _base.py:
The original
androidclient is preserved for users who need it explicitly.