Beispiel #1
0
        public void SingleSyncDownload(string link)
        {
            string exportVideoPath = @"C:\Users\david.waidmann\Downloads\Productivity\";
            string exportAudioPath = @"C:\Users\david.waidmann\Downloads\Productivity\";

            var link1 = new LinkInfo(link);

            var downloader = new YTDownloaderBuilder()
                             .SetExportAudioPath(exportAudioPath)                                     //required
                             .SetExportVideoPath(exportVideoPath)                                     //required
                             .SetExportOptions(ExportOptions.ExportVideo | ExportOptions.ExportAudio) //default
                             .SetSkipDownloadIfFileExists(false)                                      //default
                             .SetLinks(link1)                                                         //check other overloads
                             .Build();

            DownloadResult[] results = downloader.DownloadLinks();  //process the download

            foreach (var res in results)
            {
                Console.WriteLine(res.AudioSavedFilePath);
                Console.WriteLine(res.VideoSavedFilePath);
                Console.WriteLine(res.FileBaseName);
                Console.WriteLine(res.GUID);
                Console.WriteLine(res.DownloadSkipped);
            }

            downloader.AddDownloadStartedAction(link1.GUID, (evArgs) =>
            {
                Console.WriteLine("DOWNLOAD STARTED");
            });

            downloader.AddDownloadFinishedAction(link1.GUID, (evArgs) =>
            {
                Console.WriteLine("DOWNLOAD FINISHED");
            });

            downloader.AddDownloadProgressChangedAction(link1.GUID, (progressArgs) =>
            {
                Invoke(new MethodInvoker(delegate()
                {
                    progressBar.Value  = (int)progressArgs.ProgressPercentage;
                    lblPercentage.Text = $"{string.Format("{0:0.##}", progressArgs.ProgressPercentage)}%";
                    progressBar.Update();
                }));

                Console.WriteLine("Download for link:  " + link1.URL + " " + progressArgs.ProgressPercentage + "%");
            });

            downloader.AddDownloadStartedAction(link1.GUID, (convertArgs) =>
            {
                //Console.WriteLine("Converting audio to path:  " + convertArgs.AudioSavedFilePath);
            });

            downloader.AddAudioConvertingEndedAction(link1.GUID, (convertArgs) =>
            {
                Console.WriteLine("Converting audio complete");
            });
        }
Beispiel #2
0
        public void AsyncDownload(List <LinkInfo> linkinfoList)
        {
            string exportVideoPath = @"C:\Users\david.waidmann\Downloads\Productivity\";
            string exportAudioPath = @"C:\Users\david.waidmann\Downloads\Productivity\";

            var downloader = new YTDownloaderBuilder()
                             .SetExportAudioPath(exportAudioPath)                                     //required
                             .SetExportVideoPath(exportVideoPath)                                     //required
                             .SetExportOptions(ExportOptions.ExportVideo | ExportOptions.ExportAudio) //default
                             .SetSkipDownloadIfFileExists(false)                                      //default
                             .SetLinks(linkinfoList)                                                  //check other overloads
                             .Build();

            Task <DownloadResult[]> results = downloader.DownloadLinksAsync(CancellationToken.None); // process download

            foreach (var link in linkinfoList)
            {
                downloader.AddDownloadStartedAction(link.GUID, (evArgs) =>
                {
                    Console.WriteLine("DOWNLOAD STARTED");
                });

                downloader.AddDownloadFinishedAction(link.GUID, (evArgs) =>
                {
                    Console.WriteLine("DOWNLOAD FINISHED");
                });

                downloader.AddDownloadProgressChangedAction(link.GUID, (progressArgs) =>
                {
                    Invoke(new MethodInvoker(delegate()
                    {
                        progressBar.Value  = (int)progressArgs.ProgressPercentage;
                        lblPercentage.Text = $"{string.Format("{0:0.##}", progressArgs.ProgressPercentage)}%";
                        progressBar.Update();
                    }));

                    //Console.WriteLine("Download for link:  " + link.URL + " " + progressArgs.ProgressPercentage + "%");
                });

                downloader.AddDownloadStartedAction(link.GUID, (convertArgs) =>
                {
                    //Console.WriteLine("Converting audio to path:  " + convertArgs.AudioSavedFilePath);
                });

                //downloader.AddAudioConvertingEndedAction(link.GUID, (convertArgs) =>
                //{
                //    Console.WriteLine("Converting audio for link:  " + link.FileName + " completed.");
                //    //tbxUrl.ResetText();
                //    //progressBar.Value = 0;
                //    //progressBar.Refresh();
                //});
            }
        }