-
Notifications
You must be signed in to change notification settings - Fork 47
Open
Description
Hello,
Every video I tried gives me an 403 when I want to download the audio stream or video stream.
Example video:
https://www.youtube.com/embed/-FGrZolntqk
ResourceUri for audio stream
var result = await grabber.GrabAsync(new Uri($"https://www.youtube.com/embed/{fields?[0]}"));
var mediaFiles = result.Resources<GrabbedMedia>().ToArray();
var videoStream = mediaFiles.GetHighestQualityVideo();
var audioStream = mediaFiles.GetHighestQualityAudio();
if (audioStream == null)
throw new InvalidOperationException("No audio stream detected.");
if (videoStream == null)
throw new InvalidOperationException("No video stream detected.");
var audioPath = await DownloadMedia(audioStream, result);
var videoPath = await DownloadMedia(videoStream, result);
GenerateOutputFile(audioPath, videoPath, videoStream, path);
async Task<string> DownloadMedia(GrabbedMedia media, IGrabResult grabResult)
{
Console.WriteLine(\"Downloading {0}...\", media.Title ?? media.FormatTitle ?? media.Resolution);
using var response = await Client.GetAsync(media.ResourceUri);
response.EnsureSuccessStatusCode();
await using var downloadStream = await response.Content.ReadAsStreamAsync();
await using var resourceStream = await grabResult.WrapStreamAsync(downloadStream);
var path = Path.GetTempFileName();
await using var fileStream = new FileStream(path, FileMode.Create);
TempFiles.Add(path);
await resourceStream.CopyToAsync(fileStream);
return path;
}
Error message:
System.Net.Http.HttpRequestException: Response status code does not indicate success: 403 (Forbidden).
$>g__DownloadMedia|0>d.MoveNext() in D:\Projects\TEST\TEST\TEST\Program.cs:line 87
at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
at Program.<>c__DisplayClass0_0.<<
--- End of stack trace from previous location ---
at Program.$(String[] args) in D:\Projects\TEST\TEST\TEST\Program.cs:line 51
Dav2070mediaexplorer74
Metadata
Metadata
Assignees
Labels
No labels