Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Every video gives a 403 when downloading #98

Open
vinnie1234 opened this issue Jun 15, 2024 · 3 comments
Open

Every video gives a 403 when downloading #98

vinnie1234 opened this issue Jun 15, 2024 · 3 comments

Comments

@vinnie1234
Copy link

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

https://rr4---sn-32o-1the.googlevideo.com/videoplayback?expire=1718474153&ei=SYFtZqn-Ceqai9oPkLOKuAU&ip=77.174.240.244&id=o-AN_46gMB4pA9p-kqMKiBq_a3QUazgkwCHdfBNoe89uEV&itag=251&source=youtube&requiressl=yes&xpc=EgVo2aDSNQ==&mh=bx&mm=31,29&mn=sn-32o-1the,sn-5hne6nzk&ms=au,rdu&mv=m&mvi=4&pl=26&initcwndbps=2146250&bui=AbKP-1PLoB9KhmGub4g8VZuGmcmrpZPOemtWlWZqRFVuGYYFTL05WcWITyK6ZOb35B3__T2yZpTzFvWJ&spc=UWF9f5OyHHMiIpBjw7PpFGzpvcB7U_qZOu_h2UWLvldCroP-Ej8GSdj7m1K8&vprv=1&svpuc=1&mime=audio/webm&ns=ujNdWRYrfGzaKm0oQXeNiUsQ&rqh=1&gir=yes&clen=1168939&dur=74.041&lmt=1708560915899548&mt=1718452374&fvip=3&keepalive=yes&c=WEB&sefc=1&txp=4432434&n=udhNDQq2j2d37rLT&sparams=expire,ei,ip,id,itag,source,requiressl,xpc,bui,spc,vprv,svpuc,mime,ns,rqh,gir,clen,dur,lmt&sig=AJfQdSswRAIgdErbrJIwQRiK1lM4KEnzS1Lh6omf3XlO8RUy9mdVeWICIBtUjV_MZiLQGyYGmlpAP0wscS88Mz6EIoyxonJIFvCE&lsparams=mh,mm,mn,ms,mv,mvi,pl,initcwndbps&lsig=AHlkHjAwRQIhAO1lbrJR6KjTkdMegGd57lsTt0DBt2igBQFXVjk-PgVbAiA_8L9TL909hpR1iKGlKzPLRgp2Aa3rGTSyIXtybycjYw==

        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).
at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
at Program.<>c__DisplayClass0_0.<<

$>g__DownloadMedia|0>d.MoveNext() in D:\Projects\TEST\TEST\TEST\Program.cs:line 87
--- End of stack trace from previous location ---
at Program.$(String[] args) in D:\Projects\TEST\TEST\TEST\Program.cs:line 51

@rochapablo
Copy link

rochapablo commented Jun 21, 2024

omansak/libvideo#283

@Dav2070
Copy link

Dav2070 commented Aug 1, 2024

Any update on this? The issue on libvideo is already fixed since last week.

@tatmanblue
Copy link

ping in case there is an answer. I am experiencing this same error. I am not sure how to incorporate @rochapablo suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants