예제 #1
0
 public void EnableInteractions()
 {
     IsIndeterminate               = false;
     IsInputEnabled                = true;
     IsButtonEnabled               = true;
     IsComboBoxEnabled             = true;
     ProgressBarPercent            = 0;
     TaskBarProgressValue          = HelpersModel.GetTaskBarProgressValue(100, ProgressBarPercent);
     TaskbarItemProgressStateModel = TaskbarItemProgressState.Normal;
 }
예제 #2
0
 public void DisableInteractions()
 {
     IsIndeterminate               = true;
     IsInputEnabled                = false;
     IsComboBoxEnabled             = false;
     ProgressBarPercent            = 0;
     _downloadFileSize             = 0.0;
     _audioVideoDownloadCounter    = 0;
     TaskBarProgressValue          = HelpersModel.GetTaskBarProgressValue(100, ProgressBarPercent);
     TaskbarItemProgressStateModel = TaskbarItemProgressState.Indeterminate;
 }
        public (bool measureDownloadTime, string downloadedFileSize, bool isIndeterminate, TaskbarItemProgressState taskbarItemProgressStateModel, int progressBarPercent, double taskBarProgressValue, bool measureProcessingTime, string standardOutputOut) Extract(string standardOutput, string finishedMessage)
        {
            int positionFrom;
            int positionTo;

            if (standardOutput.Contains(Localization.Properties.Resources.ThreadPoolWorkerDownload) && standardOutput.Contains(Localization.Properties.Resources.ThreadPoolWorkerEta))
            {
                measureDownloadTime = true;
                positionFrom        = standardOutput.IndexOf(Localization.Properties.Resources.ThreadPoolWorkerOf, StringComparison.InvariantCultureIgnoreCase) + Localization.Properties.Resources.ThreadPoolWorkerOf.Length;
                positionTo          = standardOutput.LastIndexOf(Localization.Properties.Resources.ThreadPoolWorkerAt, StringComparison.InvariantCultureIgnoreCase);

                if ((positionTo - positionFrom) > 0)
                {
                    downloadedFileSize = standardOutput.Substring(positionFrom, positionTo - positionFrom);
                }

                positionFrom = standardOutput.IndexOf("] ", StringComparison.InvariantCultureIgnoreCase) + "] ".Length;
                positionTo   = standardOutput.LastIndexOf("%", StringComparison.InvariantCultureIgnoreCase);

                if ((positionTo - positionFrom) > 0)
                {
                    var percent = standardOutput.Substring(positionFrom, positionTo - positionFrom);
                    if (double.TryParse(percent.Trim(), NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var downloadedPercent))
                    {
                        isIndeterminate = false;
                        taskbarItemProgressStateModel = TaskbarItemProgressState.Normal;
                        progressBarPercent            = Convert.ToInt32(Math.Round(downloadedPercent));
                        taskBarProgressValue          = HelpersModel.GetTaskBarProgressValue(100, progressBarPercent);
                    }
                    else
                    {
                        isIndeterminate = true;
                        taskbarItemProgressStateModel = TaskbarItemProgressState.Indeterminate;
                    }
                }
                standardOutputOut = standardOutput;
            }
            if (standardOutput.Contains("has already been"))
            {
                standardOutputOut   = standardOutput;
                downloadedFileSize  = Localization.Properties.Resources.FileHasAlreadyBeenDownloaded;
                measureDownloadTime = false;
            }
            if (standardOutput.Contains("[ffmpeg]"))
            {
                standardOutputOut     = finishedMessage;
                measureProcessingTime = true;
                measureDownloadTime   = false;
            }

            return(measureDownloadTime, downloadedFileSize, isIndeterminate, taskbarItemProgressStateModel, progressBarPercent, taskBarProgressValue, measureProcessingTime, standardOutputOut);
        }
예제 #4
0
 public ModelClass()
 {
     Initalize();
     EnableInteractions();
     PeriodicTimerProcessing = new Timer(_ => ProcessingTimeMeasurement(), null, TimeSpan.Zero, TimeSpan.FromMilliseconds(_timerResolution));
     PeriodicTimerDownload   = new Timer(_ => DownloadTimeMeasurement(), null, TimeSpan.Zero, TimeSpan.FromMilliseconds(_timerResolution));
     PeriodicTimerPinger     = new Timer(_ => TimerPinger(), null, TimeSpan.FromMilliseconds(15000), TimeSpan.FromMilliseconds(1000));
     PeriodicTimerClipper    = new Timer(_ => TimerClipper(), null, TimeSpan.Zero, TimeSpan.FromMilliseconds(_timerResolution));
     QualityDefault          = HelpersModel.QualityDefault();
     Quality         = HelpersModel.QualityObservableCollection();
     SelectedQuality = Quality[0];
     _ = ApplicationUpdater.UpdateAsync(this);
     GlowBrushColor          = new SolidColorBrush(Colors.LightBlue);
     _synchronizationContext = SynchronizationContext.Current;
 }
예제 #5
0
 private void SendData(string fileName, string standardOutput)
 {
     try
     {
         UpdateWebhook(DownloadLink, fileName, standardOutput);
     }
     catch (HttpRequestException webhookException)
     {
         TaskBarProgressValue          = HelpersModel.GetTaskBarProgressValue(100, 100);
         TaskbarItemProgressStateModel = TaskbarItemProgressState.Error;
         Thread.Sleep(1000);
         StandardOutput = Localization.Properties.Resources.ExceptionUpdatingWebhookFailed;
         Log.Error(webhookException, Localization.Properties.Resources.ExceptionUpdatingWebhookFailed);
         _informationAndExceptionOutput = webhookException.Message;
         _downloadedFileSize            = null;
         EnableInteractions();
         return;
     }
 }
예제 #6
0
        private void UpdateUiFromTheWorkerThread(object state)
        {
            Quality.Clear();
            var availableAudioFormats = state as List <string>;
            var qualityDynamic        = new List <string>();
            var qualityDynamicFormat  = new List <string>();

            availableAudioFormats.Reverse();
            bool addOpus = true, addVorbis = true, addM4a = true;

            foreach (var item in availableAudioFormats)
            {
                if (HelpersModel.FindFormat(item).Contains("opus"))
                {
                    if (addOpus)
                    {
                        qualityDynamic.Add(Localization.Properties.Resources.AudioQualityRawWebm);
                        qualityDynamic.Add(Localization.Properties.Resources.AudioQualityRawOpus);
                        addOpus = false;
                    }
                }
                if (HelpersModel.FindFormat(item).Contains("vorbis"))
                {
                    if (addVorbis)
                    {
                        qualityDynamic.Add(Localization.Properties.Resources.AudioQualityRawVorbis);
                        addVorbis = false;
                    }
                }
                if (HelpersModel.FindFormat(item).Contains("m4a"))
                {
                    if (addM4a)
                    {
                        qualityDynamic.Add(Localization.Properties.Resources.AudioQualityRawAac);
                        addM4a = false;
                    }
                }

                qualityDynamicFormat.Add(ArragementDynamicFormatsOutput(item));
            }

            qualityDynamic.ForEach(Quality.Add);
            QualityDefault.ForEach(Quality.Add);
            qualityDynamicFormat.ForEach(Quality.Add);
            Quality.Add(Localization.Properties.Resources.AudioAndVideoBestYouTubeQuality);

            var optimalQualityIndex = Quality.ToList().FindIndex(x => x.Contains("m4a"));
            var defaultQualityCount = 19;

            if (optimalQualityIndex != -1)
            {
                if (IsUsingLastQualitySelected && Quality.Count == defaultQualityCount)
                {
                    SelectedQuality = Quality[_lastUsedQualityIndex];
                }
                else
                {
                    SelectedQuality = Quality[optimalQualityIndex];
                }
            }
            else
            {
                Quality.Clear();
                Quality.Add(Localization.Properties.Resources.AudioQualityCouldNotBeRetrieved);
                SelectedQuality = Quality[0];
                if (_isOnline)
                {
                    StandardOutput = Localization.Properties.Resources.StandardOutputYouTubeLinkIsInvalid;
                    Log.Error(StandardOutput);
                }
                else
                {
                    StandardOutput = Localization.Properties.Resources.StandardOutputNoInternetConnection;
                    Log.Error(StandardOutput);
                }
                IsButtonEnabled = false;
                return;
            }
            StandardOutput    = Localization.Properties.Resources.StandardOutputReady;
            IsComboBoxEnabled = true;
        }
예제 #7
0
        private void ThreadPoolWorker()
        {
            _isDownloadRunning = true;
            string selectedQuality = HelpersModel.GetQuality(SelectedQuality);

            Log.Information(selectedQuality);
            DisableInteractions();
            Thread.CurrentThread.IsBackground = true;
            _currentThreadPoolWorker          = Thread.CurrentThread;

            StandardOutput = Localization.Properties.Resources.StartingDownload;
            var statusWithLink = Localization.Properties.Resources.StatusLogStartingDownloadOfTheLink + DownloadLink;

            InformationAndExceptionOutput = statusWithLink;
            Log.Information(statusWithLink);
            string command;

            (command, _finishedMessage) = HelpersModel.CreateCommandAndMessage(selectedQuality, DownloadLink);

            var startinfo = new ProcessStartInfo("CMD.exe", command)
            {
                CreateNoWindow         = true,
                UseShellExecute        = false,
                RedirectStandardOutput = true,
                RedirectStandardError  = true,
            };

            var readLineExtractor = new ReadLineExtractorModel();
            var process           = new Process {
                StartInfo = startinfo
            };

            process.Start();

            var reader = process.StandardOutput;

            while (!reader.EndOfStream)
            {
                StandardOutput = reader.ReadLine();
                StandardOutput = HelpersModel.StandardOutputLocalizator(StandardOutput);
                (_measureDownloadTime, _downloadedFileSize, IsIndeterminate, TaskbarItemProgressStateModel, ProgressBarPercent, TaskBarProgressValue, _measureProcessingTime, StandardOutput) = readLineExtractor.Extract(StandardOutput, _finishedMessage);
                Thread.Sleep(_timerResolution);
            }

            process.WaitForExit();
            _measureProcessingTime = false;

            if (_downloadedFileSize == null || string.IsNullOrWhiteSpace(_downloadedFileSize))
            {
                TimersOutput                  = string.Empty;
                TaskBarProgressValue          = HelpersModel.GetTaskBarProgressValue(100, 100);
                TaskbarItemProgressStateModel = TaskbarItemProgressState.Error;
                Thread.Sleep(1000);
                if (_isOnline)
                {
                    if (IsWebsitesUnlockerSelected)
                    {
                        if (!DownloadLink.Contains("https://www."))
                        {
                            StandardOutput = Localization.Properties.Resources.NotValidLink;
                            Log.Error(StandardOutput);
                        }
                        else
                        {
                            StandardOutput = Localization.Properties.Resources.NoFileDownloadedUnsupportedWebsite;
                            Log.Error(StandardOutput);
                        }
                    }
                    else
                    {
                        StandardOutput = Localization.Properties.Resources.ErrorNoFileDownloadedUpdatesAreNeeded;
                        Log.Error(StandardOutput);
                    }
                }
                else
                {
                    StandardOutput = Localization.Properties.Resources.ErrorNoInternetConnectionNoFileDownloaded;
                    Log.Error(StandardOutput);
                }
                ButtonContent = Localization.Properties.Resources.ButtonContentDownload;
                EnableInteractions();
                _isDownloadRunning = false;
                process.Dispose();
                return;
            }
            if (_downloadedFileSize == Localization.Properties.Resources.FileHasAlreadyBeenDownloaded)
            {
                TimersOutput                  = string.Empty;
                TaskBarProgressValue          = HelpersModel.GetTaskBarProgressValue(100, 100);
                TaskbarItemProgressStateModel = TaskbarItemProgressState.Paused;
                Thread.Sleep(1000);
                var output = Localization.Properties.Resources.StandardOutputReady + ". " + _downloadedFileSize;
                StandardOutput = output;
                Log.Information(output);
                ButtonContent = Localization.Properties.Resources.ButtonContentDownload;
                EnableInteractions();
                _isDownloadRunning = false;
                process.Dispose();
                return;
            }
            else
            {
                var processingTimeTimer = (_processingTime * _timerResolution) / 1000.0;
                var downloadTimeTimer   = (_downloadTime * _timerResolution) / 1000.0;
                (string fileName, double fileSize) = GetFileNameAndSize(selectedQuality);
                if (_downloadedFileSize.Contains("~"))
                {
                    _downloadedFileSize = _downloadedFileSize.Substring(1);
                }
                TimersOutput   = string.Empty;
                StandardOutput = Localization.Properties.Resources.ProcessingTime + processingTimeTimer.ToString("N0", CultureInfo.InvariantCulture) + "s. " +
                                 Localization.Properties.Resources.DownloadTime + downloadTimeTimer.ToString("N0", CultureInfo.InvariantCulture) + "s. " +
                                 Localization.Properties.Resources.DownloadedFileSize + _downloadedFileSize + ". " +
                                 Localization.Properties.Resources.TranscodedFileSize + fileSize.ToString("F", CultureInfo.InvariantCulture) + "MiB. ";

                if (double.TryParse(_downloadedFileSize.Remove(_downloadedFileSize.Length - 3), NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var downloadedFileSize))
                {
                    var ratio = downloadedFileSize / fileSize;
                    StandardOutput += Localization.Properties.Resources.Ratio + ratio.ToString("F", CultureInfo.InvariantCulture) + ".";
                }

                SendData(fileName, StandardOutput);
                _downloadedFileSize = null;
                _processingTime     = 1;
                _downloadTime       = 1;
                ButtonContent       = Localization.Properties.Resources.ButtonContentDownload;
                EnableInteractions();
                _isDownloadRunning = false;
                process.Dispose();
                InformationAndExceptionOutput = Localization.Properties.Resources.StatusLogFinishedDownload;
                Log.Information(StandardOutput);
            }
        }