public override async Task <VideoUrlParseResult> ParseByUrlAsync(string url, bool getTitle) { var youtubeDl = new YoutubeDL { RetrieveAllInfo = true, YoutubeDlPath = GetPath(AppConfig.YoutubeDLPath), PythonPath = GetPath(AppConfig.PythonPath) }; youtubeDl.StandardOutputEvent += StandardOutputEvent; youtubeDl.StandardErrorEvent += StandardErrorEvent; DownloadInfo result; try { var task = youtubeDl.GetDownloadInfoAsync(url); result = await TimeoutAfter(task, 10000); } catch (TaskCanceledException) { var warnings = GetErrorString(youtubeDl.Info); _log.Error("Timeout. Error list: {0}", warnings); return(VideoUrlParseResult.CreateError(url, VideoUrlParseResultType.LoadError, "Timeout")); } catch (TimeoutException) { youtubeDl.CancelDownload(); _log.Error("Timeout"); return(VideoUrlParseResult.CreateError(url, VideoUrlParseResultType.LoadError, "Timeout")); } if (result == null) { var warnings = GetErrorString(youtubeDl.Info); _log.Error("Result from parser is empty. Error list: {0}", warnings); return(VideoUrlParseResult.CreateError(url, VideoUrlParseResultType.LoadError, "Result from parser is empty")); } if (!(result is VideoDownloadInfo info)) { var warnings = GetErrorString(youtubeDl.Info); _log.Error("Unexpected result from parser. Error list: {0}. Result type is {1}. Title is {2}", warnings, result.GetType().Name, result.Title); return(VideoUrlParseResult.CreateError(url, VideoUrlParseResultType.LoadError, "Unexpected result from parser.")); } DateTime?date = null; if (DateTime.TryParseExact(info.UploadDate, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out var parsedDate)) { date = parsedDate; } var bandcampMetadata = new PVExtendedMetadata(new BandcampMetadata { Url = info.WebpageUrl }); var meta = VideoTitleParseResult.CreateSuccess(info.Title, info.Uploader, info.UploaderId, info.Thumbnail, (int?)info.Duration, uploadDate: date, extendedMetadata: bandcampMetadata); return(VideoUrlParseResult.CreateOk(url, PVService.Bandcamp, info.Id, meta)); }
public static async Task Main(string[] args) { var a = new YoutubeDL(@"D:\Neos Nightly\Neos\RuntimeData\youtube-dl.exe"); a.Options.VideoSelectionOptions.NoPlaylist = true; var info = await a.GetDownloadInfoAsync(" https://youtu.be/yiACBm3ynDQ"); Console.WriteLine("Test"); //YoutubeDL ydlClient = new YoutubeDL(); //ydlClient.Options.DownloadOptions.FragmentRetries = -1; //ydlClient.Options.DownloadOptions.Retries = -1; //ydlClient.Options.VideoFormatOptions.Format = Enums.VideoFormat.best; //ydlClient.Options.PostProcessingOptions.AudioFormat = Enums.AudioFormat.best; //ydlClient.Options.PostProcessingOptions.AudioQuality = "0"; //string options = ydlClient.Options.Serialize(); //ydlClient.Options = Options.Deserialize(options); //ydlClient.StandardErrorEvent += (sender, error) => Console.WriteLine(error); //ydlClient.StandardOutputEvent += (sender, output) => Console.WriteLine(output); //ydlClient.Info.PropertyChanged += (sender, e) => //{ // DownloadInfo info = (DownloadInfo) sender; // var propertyValue = info.GetType().GetProperty(e.PropertyName).GetValue(info); // switch (e.PropertyName) // { // case "VideoProgress": // Console.WriteLine($" > Video Progress: {propertyValue}%"); // break; // case "Status": // Console.WriteLine($" > Status: {propertyValue}"); // break; // case "DownloadRate": // Console.WriteLine($" > Download Rate: {propertyValue}"); // break; // default: // break; // } //}; //ydlClient.Download("https://www.youtube.com/watch?v=dQw4w9WgXcQ"); }
public async Task <WebVideoInfo> GetWebVideoInfoAsync(string videoUrl, bool singleBest = false, bool videoBest = false) { var youtubeDl = new YoutubeDL(); youtubeDl.VideoUrl = videoUrl; youtubeDl.RetrieveAllInfo = true; var videoInfo = await youtubeDl.GetDownloadInfoAsync() as VideoDownloadInfo;// PrepareDownloadAsync(); FormatDownloadInfo videoFormat; FormatDownloadInfo audioFormat = null; if (singleBest) { videoFormat = videoInfo?.Formats.Where(v => v.Vcodec != "none" && v.Acodec != "none").OrderBy(v => v.Height).ThenBy(v => v.Width) .LastOrDefault(); } else if (videoBest) { videoFormat = videoInfo?.Formats.Where(v => v.Vcodec != "none").OrderBy(v => v.Height).ThenBy(v => v.Width) .LastOrDefault(); } else { videoFormat = videoInfo?.RequestedFormats.FirstOrDefault(v => v.Vcodec != "none"); audioFormat = videoInfo?.RequestedFormats.FirstOrDefault(v => v.Acodec != "none"); } if (videoFormat == null) { throw new InvalidOperationException("No video stream was found by specified URL: " + videoUrl); } return(new WebVideoInfo { OriginalUrl = videoUrl, VideoStreamUrl = videoFormat.Url, AudioStreamUrl = audioFormat?.Url, ThumbnailUrl = videoInfo.Thumbnail, VideoTitle = videoInfo.Title, VideoDescription = videoInfo.Description, }); }
public void GetUrlTest() { var youtubeDL = new YoutubeDL(); youtubeDL.Options.PostProcessingOptions.FfmpegLocation = @"W:\Home\sport\SportVideoAnalyzer\external\CommonSources\Video\FFMpegExecutable\ffmpeg.exe"; youtubeDL.Options.VideoFormatOptions.Format = Enums.VideoFormat.best; var videoInfoTask = youtubeDL.GetDownloadInfoAsync("https://www.youtube.com/watch?v=lGOeksQe4DE"); videoInfoTask.Wait(); var videoInfo = videoInfoTask.Result; Assert.IsNotNull(videoInfo); youtubeDL = new YoutubeDL(); youtubeDL.Options.PostProcessingOptions.FfmpegLocation = @"W:\Home\sport\SportVideoAnalyzer\external\CommonSources\Video\FFMpegExecutable\ffmpeg.exe"; youtubeDL.Options.VideoFormatOptions.Format = Enums.VideoFormat.best; videoInfoTask = youtubeDL.GetDownloadInfoAsync("https://www.youtube.com/watch?v=lGOeksQe4DE"); videoInfoTask.Wait(); videoInfo = videoInfoTask.Result; Assert.IsNotNull(videoInfo); }
private async Task <DownloadResponse> DownloadSong(SongRequest request) { await _batcher.WaitAsync(); try { var youtubeDl = new YoutubeDL(); var standardOutBuilder = new StringBuilder(); var standardErrorBuilder = new StringBuilder(); youtubeDl.StandardOutputEvent += (s, output) => standardOutBuilder.Append(output); youtubeDl.StandardErrorEvent += (s, error) => standardErrorBuilder.Append(error); var artistPath = Path.Combine(request.Artist[0].ToString(), request.Artist); var artistAlbumPath = Path.Combine(artistPath, request.Album); var artistAlbumFilePath = Path.Combine(artistAlbumPath, $"{request.Title}.m4a"); var fullFilePath = Path.Combine(MusicArtistsDirectory, artistAlbumFilePath); youtubeDl.Options.FilesystemOptions.Output = fullFilePath; youtubeDl.Options.VideoFormatOptions.FormatAdvanced = "bestaudio[ext=m4a]"; var info = await youtubeDl.GetDownloadInfoAsync(); await youtubeDl.DownloadAsync(request.Url); return(new DownloadResponse(request.Url, info.Title, standardOutBuilder.ToString(), standardErrorBuilder.ToString())); } catch (Exception) { throw; } finally { _batcher.Release(); } }