示例#1
0
        private static void DownloadVideo(Options inputOptions)
        {
            VideoDownloadOptions downloadOptions = new VideoDownloadOptions();

            if (inputOptions.Id == "" || !inputOptions.Id.All(Char.IsDigit))
            {
                Console.WriteLine("[ERROR] - Invalid VOD ID, unable to parse. Must be only numbers.");
                Environment.Exit(1);
            }

            downloadOptions.DownloadThreads = inputOptions.DownloadThreads;
            downloadOptions.Id                = Int32.Parse(inputOptions.Id);
            downloadOptions.Oauth             = inputOptions.Oauth;
            downloadOptions.Filename          = inputOptions.OutputFile;
            downloadOptions.Quality           = inputOptions.Quality;
            downloadOptions.CropBeginning     = inputOptions.CropBeginningTime == 0.0 ? false : true;
            downloadOptions.CropBeginningTime = inputOptions.CropBeginningTime;
            downloadOptions.CropEnding        = inputOptions.CropEndingTime == 0.0 ? false : true;
            downloadOptions.CropEndingTime    = inputOptions.CropEndingTime;
            downloadOptions.FfmpegPath        = inputOptions.FfmpegPath == null || inputOptions.FfmpegPath == "" ? ffmpegPath : Path.GetFullPath(inputOptions.FfmpegPath);
            downloadOptions.TempFolder        = inputOptions.TempFolder;

            VideoDownloader           videoDownloader = new VideoDownloader(downloadOptions);
            Progress <ProgressReport> progress        = new Progress <ProgressReport>();

            progress.ProgressChanged += Progress_ProgressChanged;
            videoDownloader.DownloadAsync(progress, new CancellationToken()).Wait();
        }
        public async Task RunAsync()
        {
            VideoDownloader           downloader = new VideoDownloader(DownloadOptions);
            Progress <ProgressReport> progress   = new Progress <ProgressReport>();

            progress.ProgressChanged += Progress_ProgressChanged;
            Status = TwitchTaskStatus.Running;
            OnPropertyChanged("Status");
            try
            {
                await downloader.DownloadAsync(progress, TokenSource.Token);

                if (TokenSource.IsCancellationRequested)
                {
                    Status = TwitchTaskStatus.Cancelled;
                    OnPropertyChanged("Status");
                }
                else
                {
                    Status = TwitchTaskStatus.Finished;
                    OnPropertyChanged("Status");
                }
            }
            catch
            {
                Status = TwitchTaskStatus.Failed;
                OnPropertyChanged("Status");
            }
        }
        private async void btnDownload_Click(object sender, RoutedEventArgs e)
        {
            bool isValid = ValidateInput();

            if (isValid)
            {
                SaveFileDialog saveFileDialog = new SaveFileDialog();

                saveFileDialog.Filter           = "MP4 Files | *.mp4";
                saveFileDialog.RestoreDirectory = true;
                saveFileDialog.FileName         = MainWindow.GetFilename(Settings.Default.TemplateVod, textTitle.Text, currentVideoId.ToString(), currentVideoTime, textStreamer.Text);

                if (saveFileDialog.ShowDialog() == true)
                {
                    SetEnabled(false);
                    btnGetInfo.IsEnabled = false;

                    VideoDownloadOptions options = new VideoDownloadOptions();
                    options.DownloadThreads = (int)numDownloadThreads.Value;
                    options.Filename        = saveFileDialog.FileName;
                    options.Oauth           = textOauth.Text;
                    options.Quality         = comboQuality.Text;
                    options.Id                = currentVideoId;
                    options.CropBeginning     = (bool)checkStart.IsChecked;
                    options.CropBeginningTime = (int)(new TimeSpan((int)numStartHour.Value, (int)numStartMinute.Value, (int)numStartSecond.Value).TotalSeconds);
                    options.CropEnding        = (bool)checkEnd.IsChecked;
                    options.CropEndingTime    = (int)(new TimeSpan((int)numEndHour.Value, (int)numEndMinute.Value, (int)numEndSecond.Value).TotalSeconds);
                    options.FfmpegPath        = "ffmpeg";
                    options.TempFolder        = Settings.Default.TempPath;

                    VideoDownloader           currentDownload  = new VideoDownloader(options);
                    Progress <ProgressReport> downloadProgress = new Progress <ProgressReport>(OnProgressChanged);

                    SetImage("Images/ppOverheat.gif", true);
                    statusMessage.Text = "Downloading";

                    try
                    {
                        await currentDownload.DownloadAsync(downloadProgress, new CancellationToken());

                        statusMessage.Text = "Done";
                        SetImage("Images/ppHop.gif", true);
                    }
                    catch (Exception ex)
                    {
                        statusMessage.Text = "ERROR";
                        SetImage("Images/peepoSad.png", false);
                        AppendLog("ERROR: " + ex.Message);
                    }
                    btnGetInfo.IsEnabled = true;
                }
            }
            else
            {
                AppendLog("ERROR: Invalid Crop Inputs");
            }
        }
        private async void btnDownload_Click(object sender, RoutedEventArgs e)
        {
            bool isValid = ValidateInput();

            if (isValid)
            {
                SaveFileDialog saveFileDialog = new SaveFileDialog();

                saveFileDialog.Filter           = "MP4 Files | *.mp4";
                saveFileDialog.RestoreDirectory = true;
                saveFileDialog.FileName         = MainWindow.GetFilename(Settings.Default.TemplateVod, textTitle.Text, currentVideoId.ToString(), currentVideoTime, textStreamer.Text);

                if (saveFileDialog.ShowDialog() == true)
                {
                    SetEnabled(false);
                    btnGetInfo.IsEnabled = false;

                    VideoDownloadOptions options = GetOptions(saveFileDialog.FileName, null);

                    VideoDownloader           currentDownload  = new VideoDownloader(options);
                    Progress <ProgressReport> downloadProgress = new Progress <ProgressReport>(OnProgressChanged);

                    SetImage("Images/ppOverheat.gif", true);
                    statusMessage.Text = "Downloading";

                    try
                    {
                        await currentDownload.DownloadAsync(downloadProgress, new CancellationToken());

                        statusMessage.Text = "Done";
                        SetImage("Images/ppHop.gif", true);
                    }
                    catch (Exception ex)
                    {
                        statusMessage.Text = "ERROR";
                        SetImage("Images/peepoSad.png", false);
                        AppendLog("ERROR: " + ex.Message);
                    }
                    btnGetInfo.IsEnabled = true;
                }
            }
            else
            {
                AppendLog("ERROR: Invalid Crop Inputs");
            }
        }
示例#5
0
        //[ActionName("YoutubeSearch")]
        //[Route("youtubeSearch")]
        public async Task <IActionResult> Index(string YoutubeUri, string JobId)
        {
            ViewBag.JobId = JobId;

            try
            {
                VideoDownloader videoDownloader = new VideoDownloader();
                await _hubContext.Clients.Group(JobId).SendAsync("Index", "Start downloading video ...");

                string VideoFileName = videoDownloader.DownloadAsync(YoutubeUri, _configuration, _hubContext, JobId);


                if (VideoFileName != string.Empty)
                {
                    await _hubContext.Clients.Group(JobId).SendAsync("Index", "video downloaded successfully");

                    await Task.Delay(500);

                    VideoConverter videoConverter = new VideoConverter();
                    await _hubContext.Clients.Group(JobId).SendAsync("Index", "start converting video into mp3 format ...");

                    int errorCode = videoConverter.ConvertAsync(VideoFileName, _configuration, _hubContext, JobId);
                    if (errorCode == 0)
                    {
                        await _hubContext.Clients.Group(JobId).SendAsync("Index", "video converted successfully");

                        await Task.Delay(500);


                        AudioRecongnition audioRecongnition = new AudioRecongnition();
                        await _hubContext.Clients.Group(JobId).SendAsync("Index", "start recognition process of mp3 music ...");

                        RecognitionResultModel recognitionResultModel = await audioRecongnition.RecognizeAsync(VideoFileName, _configuration);

                        if (recognitionResultModel.errorCode == 0)
                        {
                            await _hubContext.Clients.Group(JobId).SendAsync("Index", "mp3 music recognized successfully successfully");

                            await Task.Delay(500);

                            YoutubeSearcher youtubeSearcher = new YoutubeSearcher();

                            await _hubContext.Clients.Group(JobId).SendAsync("Index", "Searching for videos related to the artist...");

                            List <VideoTempleteModel> listVideo = await youtubeSearcher.Run(recognitionResultModel.artist);

                            await _hubContext.Clients.Group(JobId).SendAsync("Index", "Getting youtube result...");

                            await Task.Delay(500);

                            ViewBag.error = "Video list is empty!";
                            return(View("Index", listVideo));;
                        }
                        else
                        {
                            ViewBag.error = recognitionResultModel.errorDescription;
                            return(View("Index", new List <VideoTempleteModel>()));
                        }
                    }
                    else
                    {
                        ViewBag.error = "Sorry! An Error occure in converting video into mp3 music";
                        return(View("Index", new List <VideoTempleteModel>()));
                    }
                }
                else
                {
                    ViewBag.error = "sorry! An error occure in downloading video";
                    return(View("Index", new List <VideoTempleteModel>()));
                }
            }
            catch (Exception ex)
            {
                ViewBag.error = "Unknown error ocured - " + ex.Message;

                return(View("Index", new List <VideoTempleteModel>()));
            }
        }