YoutubeDLSharp icon indicating copy to clipboard operation
YoutubeDLSharp copied to clipboard

YoutubeDL version value is not cross-platform compatible

Open kitsumed opened this issue 1 year ago • 0 comments

The version key in the YoutubeDL class is not working as expected on Linux systems due to its use of FileVersionInfo.GetVersionInfo, which can have undesired behavior, like returning a empty string. A stable work-around would be to get the version output from the yt-dlp binary itself by running it with the --version argument when first creating the object and then save the value to a private version key that can later be read using the public version key as a GET; only.

As a workaround for others users, you can get the current yt-dlp version using this code (not async)

// Create a temporary yt-dlp proc
YoutubeDLProcess temporaryYTDLPProc = new YoutubeDLProcess("yt-dlp path here");
// Create a event handler to listen to the proc outputs
EventHandler<DataReceivedEventArgs> outputHandler = (o, e) =>
{
// e.Data is the proc output, when running --version arg, the first and only output should be in yyyy.MM.dd format.
};
// Attach the event handler to the proc
temporaryYTDLPProc.OutputReceived += outputHandler;
// Run the proc with the --version argument and wait for proc exit
temporaryYTDLPProc.RunAsync(null, new OptionSet { Version = true}).Wait();
// Detach the event handler to allow the GC to free memory
temporaryYTDLPProc.OutputReceived -= outputHandler;

kitsumed avatar Dec 23 '24 21:12 kitsumed