Ejemplo n.º 1
0
        public bool AddDownload(Download download)
        {
            if (download == null)
            {
                return(true);
            }

            foreach (Download dl in Downloads)
            {
                if (dl.Url == download.Url)
                {
                    return(false);
                }
            }

            if (download.Status == DownloadStatus.Downloading || download.Status == DownloadStatus.Processing)
            {
                download.Status = preferencesManager.Preferences.ResumeDownloads ? DownloadStatus.Queued : DownloadStatus.Stopped;
            }

            download.PropertyChanged += Download_PropertyChanged;

            download.Index = Downloads.Count + 1;

            Downloads.Add(download);

            // Get the video title, but dont download the video yet, even if the download is 'Waiting' or 'Stopped'
            if (preferencesManager.Preferences.FetchTitle && download.Title == null)
            {
                YdlArguments args = new YdlArguments();
                args.General.IgnoreConfig      = true;
                args.General.FlatPlaylist      = true;
                args.VideoSelection.NoPlaylist = true;
                args.Verbosity.Simulate        = true;
                args.Verbosity.GetTitle        = true;

                args.Url = download.Url;

                string            strArgs      = Download.ArgumentSerializer.Serialize(args, true);
                ExecutableProcess titleProcess = new ExecutableProcess(YdlPath, strArgs, download.DownloadDirectory);

                titleProcess.OnReceived += (sender, data) => {
                    if (download.Title == null && !string.IsNullOrWhiteSpace(data?.Trim()))
                    {
                        download.Title = data.Trim();
                    }
                };
#if DEBUG
                titleProcess.OnExited += (sender, code) => Logger.Instance.Debug(nameof(DownloadManager), $"Title process has exited: {code}");
#endif
                titleProcess.Start();
            }

            FirePropertyChanged(nameof(TotalDownloads));
            return(true);
        }
Ejemplo n.º 2
0
        private static string GetYdlVersion(string binaryLocation)
        {
            // Get the version of the current youtube-dl binary.
            string currentVersion = string.Empty;

            using (ExecutableProcess process = new ExecutableProcess(binaryLocation, "--version", Path.GetDirectoryName(binaryLocation))) {
                process.OnReceived += (ee, data) => {
                    currentVersion += data;
                };
                process.Start();
                process.WaitForExit();
            }
            return(currentVersion.ToLower());
        }
Ejemplo n.º 3
0
        private void StartDownload()
        {
            BeginInvoke(((Action) delegate {
                lblStatus.Text = Localization.GetString("update_dialog.status.waiting", "Please wait...");
            }));

            string currentVersion = GetYdlVersion(BinaryLocation);

            WriteLogLine(Localization.GetString("update_dialog.log.current_version", "Current version: {CurrentVersion}").Replace("{CurrentVersion}", currentVersion));

            string checkingText = Localization.GetString("update_dialog.checking", "Checking for updates...");

            BeginInvoke(((Action) delegate {
                lblStatus.Text = checkingText;
            }));

            WriteLogLine(checkingText);

            bool hasErrors = false;

            using (ExecutableProcess ep = new ExecutableProcess(BinaryLocation, "-U")) {
                ep.OnReceived += (s, data) => {
                    if (data == null)
                    {
                        return;
                    }

                    if (data.IndexOf("ERROR", StringComparison.InvariantCultureIgnoreCase) != -1)
                    {
                        hasErrors = true;
                    }
                    WriteLogLine(data);
                };
                ep.OnError += (s, data) => WriteLogLine(data);

                ep.Start();
                ep.WaitForExit();
            }

            UpdateCompleted(!hasErrors);
        }
Ejemplo n.º 4
0
        public ViewModel(IGeneralDataProvider generalDataProvider)
        {
            this.GeneralDataProvider = generalDataProvider;

            //this.TimerViewModel = new TimerViewModel();

            // Initialize the current time elapsed field by adding the offset
            this.SecondsAlreadyPassed = this.SecondsAlreadyPassed.Add(ViewModel.StartFromSecConfProp);

            // We specify this method to be executed every 1 srcond // BACKGROUND WORK
            this.BackgroundWorkTimerInterval = TimeSpan.FromSeconds(1);
            var process = new ExecutableProcess(this.BackgroundWorkTimerInterval, ViewModel.MyProcessToExecute);

            process.Start();

            // We specify this method to be executed every 1 srcond // DISPLAYED IN LABEL
            this.LabelTimerInterval = TimeSpan.FromSeconds(1);
            this.newProcess         = new ExecutableProcess(this.LabelTimerInterval, LabelTimer);
            this.newProcess.Start();

            Initialize();
        }