Exemplo n.º 1
0
        public WelcomeViewVM(
            IPreferencesService preferencesService,
            IPersistenceService persistenceService,
            IDialogService dialogService,
            ITwitchService twitchService)
        {
            _preferencesService = preferencesService;
            _persistenceService = persistenceService;
            _dialogService      = dialogService;
            _twitchService      = twitchService;

            AssemblyUtil au = AssemblyUtil.Get;

            ProductName = au.GetProductName() + " " + au.GetAssemblyVersion().Trim();

            if (_preferencesService.CurrentPreferences.DownloadRememberQueue)
            {
                _persistenceService.GetDownloads();
                if (_persistenceService.Downloads.Count > 0)
                {
                    if (_dialogService.ShowMessageBox("You had downloads from your previous session would you like to resume them?", "Restore previous session?", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                    {
                        foreach (var itm in _persistenceService.Downloads)
                        {
                            _twitchService.Enqueue(itm.DownloadParams, id: itm.Id);
                        }
                    }
                    else
                    {
                        _persistenceService.PurgeDownloads();
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void Download()
        {
            try
            {
                lock (_commandLockObject)
                {
                    Validate();

                    if (!HasErrors)
                    {
                        if (File.Exists(_downloadParams.FullPath))
                        {
                            MessageBoxResult result = _dialogService.ShowMessageBox("The file already exists. Do you want to overwrite it?", "Download", MessageBoxButton.YesNo, MessageBoxImage.Question);

                            if (result != MessageBoxResult.Yes)
                            {
                                return;
                            }
                        }

                        _twitchService.Enqueue(_downloadParams);
                        _navigationService.NavigateBack();
                        _notificationService.ShowNotification("Download added");
                    }
                }
            }
            catch (Exception ex)
            {
                _dialogService.ShowAndLogException(ex);
            }
        }
        private void Download()
        {
            try
            {
                lock (_commandLockObject)
                {
                    Validate();

                    if (!HasErrors)
                    {
                        if (File.Exists(_downloadParams.FullPath))
                        {
                            MessageBoxResult result = _dialogService.ShowMessageBox("파일이 이미 존재 합니다. 덮어쓰시겠습니까?", "다운로드", MessageBoxButton.YesNo, MessageBoxImage.Question);

                            if (result != MessageBoxResult.Yes)
                            {
                                return;
                            }
                        }

                        _twitchService.Enqueue(_downloadParams);
                        _navigationService.NavigateBack();
                        _notificationService.ShowNotification("다운로드에 추가됨");
                    }
                }
            }
            catch (Exception ex)
            {
                _dialogService.ShowAndLogException(ex);
            }
        }
Exemplo n.º 4
0
        private void RetryDownload(string id)
        {
            try
            {
                lock (_commandLockObject)
                {
                    if (!string.IsNullOrWhiteSpace(id))
                    {
                        var download = FailedDownloads.Where(q => q.Id == id).FirstOrDefault();

                        if (download != null)
                        {
                            _twitchService.Enqueue(download.DownloadParams, true, id);
                            _persistenceService.DeleteFailedRecord(download.Id);
                            _persistenceService.FailedDownloads.Remove(download);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _dialogService.ShowAndLogException(ex);
            }
        }
Exemplo n.º 5
0
        private void Download()
        {
            try
            {
                lock (_commandLockObject)
                {
                    Validate();

                    //if (!HasErrors)
                    //{
                    //    if (File.Exists(_downloadParams.FullPath))
                    //    {
                    //        MessageBoxResult result = _dialogService.ShowMessageBox("The file already exists. Do you want to overwrite it?", "Download", MessageBoxButton.YesNo, MessageBoxImage.Question);

                    //        if (result != MessageBoxResult.Yes)
                    //        {
                    //            return;
                    //        }
                    //    }

                    //    _twitchService.Enqueue(_downloadParams);
                    //    _navigationService.NavigateBack();
                    //    _notificationService.ShowNotification("Download added");
                    //}
                    if (!HasErrors)
                    {
                        int downloadAddedCount = 1;
                        if (_downloadParams.AutoSplit && _downloadParams.AutoSplitTime.TotalSeconds > Preferences.MinSplitLength)
                        {
                            string baseFolder   = Path.GetDirectoryName(_downloadParams.FullPath);
                            string baseFilename = Path.GetFileName(_downloadParams.FullPath);

                            var splitTimes = TwitchVideo.GetListOfSplitTimes(_downloadParams.Video.Length, _downloadParams.CropStart ? (TimeSpan?)_downloadParams.CropStartTime : null, _downloadParams.CropEnd ? (TimeSpan?)_downloadParams.CropEndTime : null, _downloadParams.AutoSplitTime, _downloadParams.AutoSplitOverlap);
                            foreach (var splitPair in splitTimes)
                            {
                                string             filename   = GetFilenameFromTemplate(baseFilename, baseFolder, splitPair.Item1, splitPair.Item2);
                                DownloadParameters tempParams = new DownloadParameters(_downloadParams.Video, _downloadParams.VodAuthInfo, _downloadParams.Quality, baseFolder, filename, _downloadParams.DisableConversion, false, new TimeSpan(), 0);
                                tempParams.StreamingNow  = _downloadParams.StreamingNow;
                                tempParams.AutoSplit     = false;
                                tempParams.CropStart     = splitPair.Item1.HasValue;
                                tempParams.CropStartTime = splitPair.Item1 ?? new TimeSpan();
                                tempParams.CropEnd       = splitPair.Item2.HasValue;
                                tempParams.CropEndTime   = splitPair.Item2 ?? _downloadParams.Video.Length;
                                if (tempParams.StreamingNow)
                                {
                                    tempParams.AutoSplit        = true;
                                    tempParams.AutoSplitOverlap = _downloadParams.AutoSplitOverlap;
                                    tempParams.AutoSplitTime    = _downloadParams.AutoSplitTime;
                                    tempParams.Filename         = baseFilename;
                                }
                                _twitchService.Enqueue(tempParams);
                            }
                            downloadAddedCount = splitTimes.Count;
                        }
                        else
                        {
                            if (File.Exists(_downloadParams.FullPath))
                            {
                                MessageBoxResult result = _dialogService.ShowMessageBox("The file already exists. Do you want to overwrite it?", "Download", MessageBoxButton.YesNo, MessageBoxImage.Question);

                                if (result != MessageBoxResult.Yes)
                                {
                                    return;
                                }
                            }

                            _twitchService.Enqueue(_downloadParams);
                        }
                        _navigationService.NavigateBack();
                        if (downloadAddedCount <= 1)
                        {
                            _notificationService.ShowNotification("Download added");
                        }
                        else
                        {
                            _notificationService.ShowNotification($"{downloadAddedCount} downloads added");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _dialogService.ShowAndLogException(ex);
            }
        }
Exemplo n.º 6
0
        private void DownloadAll()
        {
            var addedCount       = 0;
            var skippedCount     = 0;
            var overwrittenCount = 0;

            try
            {
                var  existingCount       = 0;
                bool overrideAllExisting = false;
                bool skipAllExisting     = false;
                foreach (var video in _twitchService.Videos)
                {
                    lock (_commandLockObject)
                    {
                        if (video != null)
                        {
                            VodAuthInfo vodAuthInfo = _twitchService.RetrieveVodAuthInfo(video.Id);

                            if (!vodAuthInfo.Privileged && vodAuthInfo.SubOnly)
                            {
                                _dialogService.ShowMessageBox($"This video ({video.Title}) is sub-only! Twitch removed the ability for 3rd party software to download such videos, sorry :(", "SUB HYPE!", MessageBoxButton.OK, MessageBoxImage.Exclamation);

                                continue;
                            }

                            Preferences currentPrefs = _preferencesService.CurrentPreferences.Clone();

                            string folder = currentPrefs.DownloadSubfoldersForFav && _preferencesService.IsChannelInFavourites(video.Channel)
                                ? Path.Combine(currentPrefs.DownloadFolder, video.Channel)
                                : currentPrefs.DownloadFolder;

                            string filename = _filenameService.SubstituteWildcards(currentPrefs.DownloadFileName, video);
                            filename = _filenameService.EnsureExtension(filename, currentPrefs.DownloadDisableConversion);

                            DownloadParameters downloadParams = new DownloadParameters(video, vodAuthInfo, video.Qualities.First(), folder, filename, currentPrefs.DownloadDisableConversion);

                            if (File.Exists(downloadParams.FullPath))
                            {
                                existingCount++;

                                if (existingCount == 2)
                                {
                                    var messageMultiple = $"It seems there are multiple files that already exist.{Environment.NewLine}{Environment.NewLine}Press Cancel if you want to get a question for each existing file.{Environment.NewLine}{Environment.NewLine}Press Yes if you want to override all existing files.{Environment.NewLine}{Environment.NewLine}Press No if you want to skip all existing files";
                                    var resultMultiple  = _dialogService.ShowMessageBox(messageMultiple, "Download", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);

                                    switch (resultMultiple)
                                    {
                                    case MessageBoxResult.None:
                                    case MessageBoxResult.OK:
                                        break;

                                    case MessageBoxResult.Yes:
                                        overrideAllExisting = true;
                                        break;

                                    case MessageBoxResult.Cancel:
                                        break;

                                    case MessageBoxResult.No:
                                        skipAllExisting = true;
                                        break;

                                    default:
                                        throw new ArgumentOutOfRangeException();
                                    }
                                }

                                if (skipAllExisting)
                                {
                                    skippedCount++;
                                    continue;
                                }

                                if (overrideAllExisting)
                                {
                                    overwrittenCount++;
                                    addedCount++;
                                    _twitchService.Enqueue(downloadParams);
                                    continue;
                                }

                                var message = $"The file: {Environment.NewLine}{downloadParams.FullPath}{Environment.NewLine} already exists. Do you want to overwrite it?{Environment.NewLine}{Environment.NewLine}If you press Cancel the rest of the downloads will not be added.";
                                var result  = _dialogService.ShowMessageBox(message, "Download", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);

                                switch (result)
                                {
                                case MessageBoxResult.None:
                                case MessageBoxResult.OK:
                                case MessageBoxResult.Yes:
                                    overwrittenCount++;
                                    break;

                                case MessageBoxResult.Cancel:
                                    this.ShowMultiDownloadNotification(addedCount, skippedCount, overwrittenCount);
                                    return;

                                case MessageBoxResult.No:
                                    skippedCount++;
                                    continue;

                                default:
                                    throw new ArgumentOutOfRangeException();
                                }
                            }

                            addedCount++;
                            _twitchService.Enqueue(downloadParams);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _dialogService.ShowAndLogException(ex);
            }

            this.ShowMultiDownloadNotification(addedCount, skippedCount, overwrittenCount);
        }
Exemplo n.º 7
0
        private void EnqueueDownloads()
        {
            bool hasMoreParts = true;

            TimeSpan partStartTime = _downloadParams.CropStart ? _downloadParams.CropStartTime : TimeSpan.Zero;
            TimeSpan videoEndTime  = _downloadParams.CropEnd ? _downloadParams.CropEndTime : _downloadParams.Video.Length;
            TimeSpan partEndTime   = videoEndTime;
            int?     partNumber    = null;

            if (_downloadParams.SplitVideo)
            {
                partNumber = 1;
                _downloadParams.CropStart = true;
                _downloadParams.CropEnd   = true;
            }

            do
            {
                if (_downloadParams.SplitVideo && ((partEndTime - partStartTime) > _downloadParams.SplitLength))
                {
                    partEndTime = partStartTime + _downloadParams.SplitLength;
                }
                else
                {
                    hasMoreParts = false;
                }


                _downloadParams.CropStartTime = partStartTime;
                _downloadParams.CropEndTime   = partEndTime;
                if (_useCustomFilename)
                {
                    if (partNumber.HasValue)
                    {
                        if (partNumber > 1)
                        {
                            _downloadParams.Filename = _downloadParams.Filename.Remove(0, 4);
                        }
                        _downloadParams.Filename = ((int)partNumber).ToString("000") + "_" + _downloadParams.Filename;
                    }
                }
                else
                {
                    UpdateFilenameFromTemplate(partNumber);
                }



                if (File.Exists(_downloadParams.FullPath))
                {
                    MessageBoxResult result = _dialogService.ShowMessageBox("The file already exists. Do you want to overwrite it?", "Download", MessageBoxButton.YesNo, MessageBoxImage.Question);

                    if (result != MessageBoxResult.Yes)
                    {
                        return;
                    }
                }

                _twitchService.Enqueue((DownloadParameters)_downloadParams.Clone());

                if (hasMoreParts)
                {
                    partNumber++;
                    partStartTime = partEndTime;
                    partEndTime   = videoEndTime;
                }
            } while (hasMoreParts);
        }