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

Video URI throwing System.ArgumentOutOfRangeException #25

Closed
CJProgramming23 opened this issue Dec 10, 2015 · 8 comments
Closed

Video URI throwing System.ArgumentOutOfRangeException #25

CJProgramming23 opened this issue Dec 10, 2015 · 8 comments

Comments

@CJProgramming23
Copy link

So I was trying to use this to download YouTube videos. It was working fine, then quite a few different YouTube URLs starting throwing errors when I tried to download it.
In this case "downloadInfo.YouTubeID" is "Ip6ex1vqf6I"
Here is the relevant code:
var yt = YouTube.Default;
var video = yt.GetVideo( "https://youtube.com/watch?v=" + downloadInfo.YouTubeID );
// throws on this line
File.WriteAllBytes( videoPath, video.GetBytes() );

I've noticed that in debugging mode, I can look at the YouTubeVideo object generated by yt.GetVideo, and the URI property is at fault, as it says video.Uri threw an exception of type System.ArgumentOutOfRangeException

Here is the stack trace if it helps.

   at System.String.IndexOf(Char value, Int32 startIndex, Int32 count)
   at VideoLibrary.YouTubeVideo.FunctionBody(String function, String js, Int32 start)
   at VideoLibrary.YouTubeVideo.Operations(String js, String[]& lines)
   at VideoLibrary.YouTubeVideo.DecryptedSignature(String signature, String js)
   at VideoLibrary.YouTubeVideo.<DecryptAsync>d__34.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at VideoLibrary.YouTubeVideo.<GetUriAsync>d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at VideoLibrary.VideoClient.<GetBytesAsync>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at VideoLibrary.Video.<GetBytesAsync>d__11.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at VideoLibrary.Video.GetBytes()
   at MusicPlayer.YTDownloader.Download(DownloadInfo downloadInfo, String& finalMP3File) in B:\Development\MusicPlayer\MusicPlayer\YTDownloader.cs:line 58
   at MusicPlayer.DownloadManager.DownloadNext() in B:\Development\MusicPlayer\MusicPlayer\DownloadManager.cs:line 139
   at MusicPlayer.MainWindow.bwDownloads_DoWork(Object sender, DoWorkEventArgs e) in B:\Development\MusicPlayer\MusicPlayer\MainWindow.cs:line 359
   at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)
   at System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)

Thanks!

@rubensollie
Copy link

I think I've found the problem for this issue. You just need to change a single line in YouTubeVideo.Decrypt.cs.

You need to change this function:

private string DeclaredFunctionPrefix(string function) =>
"function " + function + '(';

to this:

private string DeclaredFunctionPrefix(string function) =>
function + "=function(";

It gives this exception, because YouTube has probably changed the javascript. I think it has been changed from function br(a) to br=function(a)

@CJProgramming23
Copy link
Author

Yeah that works. It worked for all of the ~100 videos I tested it on. Thanks.

@jamesqo
Copy link
Collaborator

jamesqo commented Dec 11, 2015

Thanks for reporting this, guys. I'll publish a new NuGet package by tonight.

@jamesqo
Copy link
Collaborator

jamesqo commented Dec 11, 2015

Possibly related: ovnisoftware/YoutubeExtractor@6126488

@rubensollie
Copy link

No problem, happy to help. It would probably be the best to check for both function br(a) and br=function(a) though, might they change it back in the future. Could save some work later on. Good evening!

@rubensollie
Copy link

It seems like youtube has updated again, so the issue is back. No worries though, because the fix is really easy again.

It seems to have changed

from var {function}=function()
to nh.{function}=function()

so instead of checking for the var like we have now:
int index = js.IndexOf($"var {function}=function(");

we change it to:
int index = js.IndexOf($"{function}=function(");

This seems to fix it again for now.

@jamesqo
Copy link
Collaborator

jamesqo commented Dec 19, 2015

Fixed again; I'll upload the new NuGet package within a few minutes. Thanks @rubensollie for notifying me.

@iancona
Copy link

iancona commented Jan 20, 2016

It is happening again. :(

jackw899 added a commit to jackw899/libvideo that referenced this issue Jan 8, 2017
hig-dev pushed a commit to hig-dev/libvideo that referenced this issue Jan 31, 2017
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