/// <summary> /// Performs the download of the specified video with the given YoutubeDL instance and a prior overwrite check. /// </summary> public async Task <RunResult <string> > RunDownload(YoutubeDL ydl, VideoEntry video, CancellationToken ct, IProgress <DownloadProgress> progress, OptionSet overrideOptions = null) { if ((Settings.Default.OverwriteMode != OverwriteMode.Overwrite) && allowsOverwriteCheck) { bool restricted = ydl.RestrictFilenames; string ext = GetExt(); string fileName = Utils.Sanitize(video.Title, restricted); string path = Path.Combine(ydl.OutputFolder, $"{fileName}.{ext}"); if (File.Exists(path)) { if (Settings.Default.OverwriteMode == OverwriteMode.None) { // Don't redownload if file exists. progress?.Report(new DownloadProgress(DownloadState.Success, data: path)); return(new RunResult <string>(true, new string[0], path)); } else { // Set download path to a new location to prevent overwriting existing file. string downloadPath = getNotExistingFilePath(ydl.OutputFolder, fileName, ext); if (overrideOptions == null) { overrideOptions = new OptionSet(); } overrideOptions.Output = downloadPath; } } } return(await RunRealDownload(ydl, video.Url, ct, progress, overrideOptions)); }
/// <summary> /// Performs the download of the specified video with the given YoutubeDL instance and a prior overwrite check. /// </summary> public async Task <RunResult <string> > RunDownload(YoutubeDL ydl, VideoEntry video, CancellationToken ct, IProgress <DownloadProgress> progress, OptionSet overrideOptions = null) { if (!ydl.OverwriteFiles && allowsOverwriteCheck) { bool restricted = ydl.RestrictFilenames; string ext = GetExt(); string path = Path.Combine(ydl.OutputFolder, $"{Utils.Sanitize(video.Title, restricted)}.{ext}"); if (File.Exists(path)) { // Don't redownload if file exists. progress?.Report(new DownloadProgress(DownloadState.Success, data: path)); return(new RunResult <string>(true, new string[0], path)); } } return(await RunRealDownload(ydl, video.Url, ct, progress, overrideOptions)); }