Closed BergLek closed 5 years ago
Can't replicate it, worked fine just now in DemoWpf.
Can you give me the exact exception stack trace? Also, what is triggering the error? Getting video streams? Getting video info?
My program works like this: It takes the title of the video and saves it in an audio with the same name. When I try to put some character like "?" or "|" in the path that the file will be stored it returns the error. This happens in the DownloadMediaStreamAsync () function.
System.Reflection.TargetInvocationException HResult=0x80131604 Message=An exception was thrown by the destination of a call. Source=mscorlib StackTrace: em System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) em System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) em System.Delegate.DynamicInvokeImpl(Object[] args) em System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme) em System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj) em System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) em System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) em System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) em System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme) em System.Windows.Forms.Control.InvokeMarshaledCallbacks() em System.Windows.Forms.Control.WndProc(Message& m) em System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) em System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) em System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) em System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) em System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) em System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) em System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) em System.Windows.Forms.Application.Run(Form mainForm) em MtaForm.Program.Main() em C:\Users\Daniel\Desktop\mta music\EMbedtest - Copia\MtaForm\Program.cs:line 34
Internal exception 1: ArgumentException: Invalid characters on path.
I don't see YoutubeExplode in the stack trace anywhere, so the problem is on your end. Are you using video title as file name? If so then you need to escape invalid characters as it's shown in DemoWpf/DemoConsole.
Ok, I'll put a common name and after the download is complete I rename the file. Thank you
You don't have to rename the file, just avoid the following characters in the file name when downloading:
Easiest way to do this (imo) is this:
string cleanName = String.Join("", name.Split(Path.GetInvalidPathChars()));
I do it with an extension method: https://github.com/Tyrrrz/YoutubeExplode/blob/e77a1215981da3f5bddda60a9415bc0314e883e9/DemoConsole/Program.cs#L83
I did a test and realized that any video that has the character "?" in the title it results in ArgumentException: Invalid characters in the path. I do not know if it's just me, anyway I'd like someone to try to download this link: https://www.youtube.com/watch?v=tcHJodG5hX8 Sorry for my English...