Пример #1
0
 public string BuildOutputFileName(
     string sourcePath,
     string sourceName,
     int title,
     TimeSpan titleDuration,
     VideoRangeType rangeType,
     int startChapter,
     int endChapter,
     int totalChapters,
     TimeSpan startTime,
     TimeSpan endTime,
     int startFrame,
     int endFrame,
     string nameFormatOverride,
     bool multipleTitlesOnSource,
     Picker picker)
 {
     return(FileUtilities.CleanFileName(
                ReplaceArguments(sourcePath, sourceName, title, titleDuration, rangeType, startChapter, endChapter, totalChapters, startTime, endTime, startFrame, endFrame, nameFormatOverride, multipleTitlesOnSource, picker),
                allowBackslashes: true));
 }
Пример #2
0
        private string ReplaceArguments(
            string sourcePath,
            string sourceName,
            int title,
            TimeSpan titleDuration,
            VideoRangeType rangeType,
            int startChapter,
            int endChapter,
            int totalChapters,
            TimeSpan startTime,
            TimeSpan endTime,
            int startFrame,
            int endFrame,
            string nameFormatOverride,
            bool multipleTitlesOnSource,
            Picker picker)
        {
            string fileName;

            if (picker == null)
            {
                picker = this.PickersService.SelectedPicker.Picker;
            }

            if (Config.AutoNameCustomFormat || !string.IsNullOrWhiteSpace(nameFormatOverride) || picker.NameFormatOverrideEnabled)
            {
                string rangeString = string.Empty;
                switch (rangeType)
                {
                case VideoRangeType.Chapters:
                    if (startChapter == endChapter)
                    {
                        rangeString = startChapter.ToString();
                    }
                    else
                    {
                        rangeString = startChapter + "-" + endChapter;
                    }

                    break;

                case VideoRangeType.Seconds:
                    rangeString = startTime.ToFileName() + "-" + endTime.ToFileName();
                    break;

                case VideoRangeType.Frames:
                    rangeString = startFrame + "-" + endFrame;
                    break;
                }

                if (!string.IsNullOrWhiteSpace(nameFormatOverride))
                {
                    fileName = nameFormatOverride;
                }
                else if (picker.NameFormatOverrideEnabled)
                {
                    fileName = picker.NameFormatOverride;
                }
                else
                {
                    fileName = Config.AutoNameCustomFormatString;
                }

                fileName = fileName.Replace("{source}", sourceName);
                fileName = ReplaceTitles(fileName, title);
                fileName = fileName.Replace("{range}", rangeString);

                fileName = fileName.Replace("{titleduration}", titleDuration.ToFileName());

                // {chapters} is deprecated in favor of {range} but we replace here for backwards compatibility.
                fileName = fileName.Replace("{chapters}", rangeString);

                fileName = fileName.Replace("{preset}", this.PresetsService.SelectedPreset.Preset.Name);
                fileName = ReplaceParents(fileName, sourcePath);

                DateTime now = DateTime.Now;
                if (fileName.Contains("{date}"))
                {
                    fileName = fileName.Replace("{date}", now.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture));
                }

                if (fileName.Contains("{time}"))
                {
                    fileName = fileName.Replace("{time}", string.Format("{0:d2}.{1:d2}.{2:d2}", now.Hour, now.Minute, now.Second));
                }

                if (fileName.Contains("{quality}"))
                {
                    VCProfile profile = this.PresetsService.SelectedPreset.Preset.EncodingProfile;
                    double    quality = 0;
                    switch (profile.VideoEncodeRateType)
                    {
                    case VCVideoEncodeRateType.ConstantQuality:
                        quality = profile.Quality;
                        break;

                    case VCVideoEncodeRateType.AverageBitrate:
                        quality = profile.VideoBitrate;
                        break;

                    case VCVideoEncodeRateType.TargetSize:
                        quality = profile.TargetSize;
                        break;

                    default:
                        break;
                    }

                    fileName = fileName.Replace("{quality}", quality.ToString());
                }
            }
            else
            {
                string titleSection = string.Empty;
                if (multipleTitlesOnSource)
                {
                    titleSection = " - Title " + title;
                }

                string rangeSection = string.Empty;
                switch (rangeType)
                {
                case VideoRangeType.Chapters:
                    if (startChapter > 1 || endChapter < totalChapters)
                    {
                        if (startChapter == endChapter)
                        {
                            rangeSection = " - Chapter " + startChapter;
                        }
                        else
                        {
                            rangeSection = " - Chapters " + startChapter + "-" + endChapter;
                        }
                    }

                    break;

                case VideoRangeType.Seconds:
                    if (startTime > TimeSpan.Zero || (endTime < titleDuration && (titleDuration - endTime >= TimeSpan.FromSeconds(1) || endTime.Milliseconds != 0)))
                    {
                        rangeSection = " - " + startTime.ToFileName() + "-" + endTime.ToFileName();
                    }

                    break;

                case VideoRangeType.Frames:
                    rangeSection = " - Frames " + startFrame + "-" + endFrame;
                    break;
                }

                fileName = sourceName + titleSection + rangeSection;
            }
            return(fileName);
        }
Пример #3
0
		public string BuildOutputFileName(
			string sourcePath, 
			string sourceName, 
			int title, 
			TimeSpan titleDuration, 
			VideoRangeType rangeType, 
			int startChapter, 
			int endChapter, 
			int totalChapters, 
			TimeSpan startTime, 
			TimeSpan endTime, 
			int startFrame, 
			int endFrame,
			string nameFormatOverride, 
			bool usesScan)
		{
			string fileName;
			if (Config.AutoNameCustomFormat || !string.IsNullOrWhiteSpace(nameFormatOverride))
			{
				string rangeString = string.Empty;
				switch (rangeType)
				{
					case VideoRangeType.Chapters:
						if (startChapter == endChapter)
						{
							rangeString = startChapter.ToString();
						}
						else
						{
							rangeString = startChapter + "-" + endChapter;
						}

						break;
					case VideoRangeType.Seconds:
						rangeString = startTime.ToFileName() + "-" + endTime.ToFileName();
						break;
					case VideoRangeType.Frames:
						rangeString = startFrame + "-" + endFrame;
						break;
				}

				if (!string.IsNullOrWhiteSpace(nameFormatOverride))
				{
					fileName = nameFormatOverride;
				}
				else
				{
					fileName = Config.AutoNameCustomFormatString;
				}

				fileName = fileName.Replace("{source}", sourceName);
				fileName = ReplaceTitles(fileName, title);
				fileName = fileName.Replace("{range}", rangeString);

				fileName = fileName.Replace("{titleduration}", titleDuration.ToFileName());

				// {chapters} is deprecated in favor of {range} but we replace here for backwards compatibility.
				fileName = fileName.Replace("{chapters}", rangeString);

				fileName = fileName.Replace("{preset}", this.PresetsVM.SelectedPreset.Preset.Name);
				fileName = ReplaceParents(fileName, sourcePath);

				DateTime now = DateTime.Now;
				if (fileName.Contains("{date}"))
				{
					fileName = fileName.Replace("{date}", now.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture));
				}

				if (fileName.Contains("{time}"))
				{
					fileName = fileName.Replace("{time}", string.Format("{0:d2}.{1:d2}.{2:d2}", now.Hour, now.Minute, now.Second));
				}

				if (fileName.Contains("{quality}"))
				{
					VCProfile profile = this.PresetsVM.SelectedPreset.Preset.EncodingProfile;
					double quality = 0;
					switch (profile.VideoEncodeRateType)
					{
                        case VCVideoEncodeRateType.ConstantQuality:
							quality = profile.Quality;
							break;
                        case VCVideoEncodeRateType.AverageBitrate:
							quality = profile.VideoBitrate;
							break;
                        case VCVideoEncodeRateType.TargetSize:
							quality = profile.TargetSize;
							break;
						default:
							break;
					}

					fileName = fileName.Replace("{quality}", quality.ToString());
				}
			}
			else
			{
				string titleSection = string.Empty;
				if (usesScan && this.main.SelectedSource != null && this.main.SelectedSource.Type != SourceType.File)
				{
					titleSection = " - Title " + title;
				}

				string rangeSection = string.Empty;
				switch (rangeType)
				{
					case VideoRangeType.Chapters:
						if (startChapter > 1 || endChapter < totalChapters)
						{
							if (startChapter == endChapter)
							{
								rangeSection = " - Chapter " + startChapter;
							}
							else
							{
								rangeSection = " - Chapters " + startChapter + "-" + endChapter;
							}
						}

						break;
					case VideoRangeType.Seconds:
						if (startTime > TimeSpan.Zero || endTime < titleDuration)
						{
							rangeSection = " - " + startTime.ToFileName() + "-" + endTime.ToFileName();
						}

						break;
					case VideoRangeType.Frames:
						rangeSection = " - Frames " + startFrame + "-" + endFrame;
						break;
				}

				fileName = sourceName + titleSection + rangeSection;
			}

			return Utilities.CleanFileName(fileName, allowBackslashes: true);
		}
Пример #4
0
		// Applies the encode job choices to the viewmodel. Part of editing a queued item,
		// assumes a scan has been done first with the data available.
		private void ApplyEncodeJobChoices(EncodeJobViewModel jobVM)
		{
			if (this.sourceData == null || this.sourceData.Titles.Count == 0)
			{
				return;
			}

			VCJob job = jobVM.Job;

			// Title
			Title newTitle = this.sourceData.Titles.FirstOrDefault(t => t.TitleNumber == job.Title);
			if (newTitle == null)
			{
				newTitle = this.sourceData.Titles[0];
			}

			this.selectedTitle = newTitle;

			// Angle
			this.PopulateAnglesList();

			if (job.Angle <= this.selectedTitle.AngleCount)
			{
				this.angle = job.Angle;
			}
			else
			{
				this.angle = 0;
			}

			// Range
			this.PopulateChapterSelectLists();
			this.rangeType = job.RangeType;
			if (this.rangeType == VideoRangeType.All)
			{
				if (this.selectedTitle.Chapters.Count > 1)
				{
					this.rangeType = VideoRangeType.Chapters;
				}
				else
				{
					this.rangeType = VideoRangeType.Seconds;
				}
			}

			switch (this.rangeType)
			{
				case VideoRangeType.Chapters:
					if (job.ChapterStart > this.selectedTitle.Chapters.Count ||
						job.ChapterEnd > this.selectedTitle.Chapters.Count ||
						job.ChapterStart == 0 ||
						job.ChapterEnd == 0)
					{
						this.selectedStartChapter = this.StartChapters.FirstOrDefault(c => c.Chapter == this.selectedTitle.Chapters[0]);
						this.selectedEndChapter = this.EndChapters.FirstOrDefault(c => c.Chapter == this.selectedTitle.Chapters[this.selectedTitle.Chapters.Count - 1]);
					}
					else
					{
						this.selectedStartChapter = this.StartChapters.FirstOrDefault(c => c.Chapter == this.selectedTitle.Chapters[job.ChapterStart - 1]);
						this.selectedEndChapter = this.EndChapters.FirstOrDefault(c => c.Chapter == this.selectedTitle.Chapters[job.ChapterEnd - 1]);
					}

					break;
				case VideoRangeType.Seconds:
					if (this.selectedTitle.Duration == TimeSpan.Zero)
					{
						throw new InvalidOperationException("Title's duration is 0, cannot continue.");
					}

					if (job.SecondsStart < this.selectedTitle.Duration.TotalSeconds + 1 &&
						job.SecondsEnd < this.selectedTitle.Duration.TotalSeconds + 1)
					{
						TimeSpan startTime = TimeSpan.FromSeconds(job.SecondsStart);
						TimeSpan endTime = TimeSpan.FromSeconds(job.SecondsEnd);

						if (endTime > this.selectedTitle.Duration)
						{
							endTime = this.selectedTitle.Duration;
						}

						if (startTime > endTime - Constants.TimeRangeBuffer)
						{
							startTime = endTime - Constants.TimeRangeBuffer;
						}

						if (startTime < TimeSpan.Zero)
						{
							startTime = TimeSpan.Zero;
						}

						this.SetRangeTimeStart(startTime);
						this.SetRangeTimeEnd(endTime);
					}
					else
					{
						this.SetRangeTimeStart(TimeSpan.Zero);
						this.SetRangeTimeEnd(this.selectedTitle.Duration);
					}

					// We saw a problem with a job getting seconds 0-0 after a queue edit, add some sanity checking.
					if (this.TimeRangeEnd == TimeSpan.Zero)
					{
						this.SetRangeTimeEnd(this.selectedTitle.Duration);
					}

					break;
				case VideoRangeType.Frames:
					if (job.FramesStart < this.selectedTitle.Frames + 1 &&
						job.FramesEnd < this.selectedTitle.Frames + 1)
					{
						this.framesRangeStart = job.FramesStart;
						this.framesRangeEnd = job.FramesEnd;
					}
					else
					{
						this.framesRangeStart = 0;
						this.framesRangeEnd = this.selectedTitle.Frames;
					}

					break;
				default:
					throw new ArgumentOutOfRangeException();
			}

			// Audio tracks
			this.AudioChoices.Clear();
			foreach (int chosenTrack in job.ChosenAudioTracks)
			{
				if (chosenTrack <= this.selectedTitle.AudioTracks.Count)
				{
					this.AudioChoices.Add(new AudioChoiceViewModel { SelectedIndex = chosenTrack - 1 });
				}
			}

			// Subtitles (standard+SRT)
			this.CurrentSubtitles.SourceSubtitles = new List<SourceSubtitle>();
			this.CurrentSubtitles.SrtSubtitles = new List<SrtSubtitle>();
			if (job.Subtitles.SourceSubtitles != null)
			{
				foreach (SourceSubtitle sourceSubtitle in job.Subtitles.SourceSubtitles)
				{
					if (sourceSubtitle.TrackNumber <= this.selectedTitle.Subtitles.Count)
					{
						this.CurrentSubtitles.SourceSubtitles.Add(sourceSubtitle);
					}
				}
			}

			if (job.Subtitles.SrtSubtitles != null)
			{
				foreach (SrtSubtitle srtSubtitle in job.Subtitles.SrtSubtitles)
				{
					this.CurrentSubtitles.SrtSubtitles.Add(srtSubtitle);
				}
			}

			// Custom chapter markers
			this.UseDefaultChapterNames = job.UseDefaultChapterNames;

			if (job.UseDefaultChapterNames)
			{
				this.CustomChapterNames = null;
			}
			else
			{
				if (this.CustomChapterNames != null && this.selectedTitle.Chapters.Count == this.CustomChapterNames.Count)
				{
					this.CustomChapterNames = job.CustomChapterNames;
				}
			}

			// Output path
			this.OutputPathVM.OutputPath = job.OutputPath;
			this.OutputPathVM.SourceParentFolder = jobVM.SourceParentFolder;
			this.OutputPathVM.ManualOutputPath = jobVM.ManualOutputPath;
			this.OutputPathVM.NameFormatOverride = jobVM.NameFormatOverride;

			// Encode profile handled above this in EditJob

			this.RaisePropertyChanged(() => this.SourceIcon);
			this.RaisePropertyChanged(() => this.SourceText);
			this.RaisePropertyChanged(() => this.SelectedTitle);
			this.RaisePropertyChanged(() => this.SelectedStartChapter);
			this.RaisePropertyChanged(() => this.SelectedEndChapter);
			this.RaisePropertyChanged(() => this.StartChapters);
			this.RaisePropertyChanged(() => this.EndChapters);
			this.RaisePropertyChanged(() => this.TimeRangeStart);
			this.RaisePropertyChanged(() => this.TimeRangeStartBar);
			this.RaisePropertyChanged(() => this.TimeRangeEnd);
			this.RaisePropertyChanged(() => this.TimeRangeEndBar);
			this.RaisePropertyChanged(() => this.FramesRangeStart);
			this.RaisePropertyChanged(() => this.FramesRangeEnd);
			this.RaisePropertyChanged(() => this.RangeType);
			this.RaisePropertyChanged(() => this.UsingChaptersRange);
			this.RaisePropertyChanged(() => this.RangeBarVisible);
			this.RaisePropertyChanged(() => this.SecondsRangeVisible);
			this.RaisePropertyChanged(() => this.FramesRangeVisible);
			this.RaisePropertyChanged(() => this.SubtitlesSummary);
			this.RaisePropertyChanged(() => this.ChapterMarkersSummary);
			this.RaisePropertyChanged(() => this.ShowChapterMarkerUI);
			this.RaisePropertyChanged(() => this.Angle);
			this.RaisePropertyChanged(() => this.Angles);

			this.RefreshRangePreview();
		}
Пример #5
0
        public string BuildOutputFileName(
            string sourcePath,
            string sourceName,
            int title,
            TimeSpan titleDuration,
            VideoRangeType rangeType,
            int startChapter,
            int endChapter,
            int totalChapters,
            TimeSpan startTime,
            TimeSpan endTime,
            int startFrame,
            int endFrame,
            string nameFormatOverride,
            bool usesScan)
        {
            string fileName;

            if (Config.AutoNameCustomFormat || !string.IsNullOrWhiteSpace(nameFormatOverride))
            {
                string rangeString = string.Empty;
                switch (rangeType)
                {
                case VideoRangeType.Chapters:
                    if (startChapter == endChapter)
                    {
                        rangeString = startChapter.ToString();
                    }
                    else
                    {
                        rangeString = startChapter + "-" + endChapter;
                    }

                    break;

                case VideoRangeType.Seconds:
                    rangeString = startTime.ToFileName() + "-" + endTime.ToFileName();
                    break;

                case VideoRangeType.Frames:
                    rangeString = startFrame + "-" + endFrame;
                    break;
                }

                if (!string.IsNullOrWhiteSpace(nameFormatOverride))
                {
                    fileName = nameFormatOverride;
                }
                else
                {
                    fileName = Config.AutoNameCustomFormatString;
                }

                fileName = fileName.Replace("{source}", sourceName);
                fileName = ReplaceTitles(fileName, title);
                fileName = fileName.Replace("{range}", rangeString);

                fileName = fileName.Replace("{titleduration}", titleDuration.ToFileName());

                // {chapters} is deprecated in favor of {range} but we replace here for backwards compatibility.
                fileName = fileName.Replace("{chapters}", rangeString);

                fileName = fileName.Replace("{preset}", this.PresetsVM.SelectedPreset.Preset.Name);
                fileName = ReplaceParents(fileName, sourcePath);

                DateTime now = DateTime.Now;
                if (fileName.Contains("{date}"))
                {
                    fileName = fileName.Replace("{date}", now.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture));
                }

                if (fileName.Contains("{time}"))
                {
                    fileName = fileName.Replace("{time}", string.Format("{0:d2}.{1:d2}.{2:d2}", now.Hour, now.Minute, now.Second));
                }

                if (fileName.Contains("{quality}"))
                {
                    VCProfile profile = this.PresetsVM.SelectedPreset.Preset.EncodingProfile;
                    double    quality = 0;
                    switch (profile.VideoEncodeRateType)
                    {
                    case VCVideoEncodeRateType.ConstantQuality:
                        quality = profile.Quality;
                        break;

                    case VCVideoEncodeRateType.AverageBitrate:
                        quality = profile.VideoBitrate;
                        break;

                    case VCVideoEncodeRateType.TargetSize:
                        quality = profile.TargetSize;
                        break;

                    default:
                        break;
                    }

                    fileName = fileName.Replace("{quality}", quality.ToString());
                }
            }
            else
            {
                string titleSection = string.Empty;
                if (usesScan && this.main.SelectedSource != null && this.main.SelectedSource.Type != SourceType.File)
                {
                    titleSection = " - Title " + title;
                }

                string rangeSection = string.Empty;
                switch (rangeType)
                {
                case VideoRangeType.Chapters:
                    if (startChapter > 1 || endChapter < totalChapters)
                    {
                        if (startChapter == endChapter)
                        {
                            rangeSection = " - Chapter " + startChapter;
                        }
                        else
                        {
                            rangeSection = " - Chapters " + startChapter + "-" + endChapter;
                        }
                    }

                    break;

                case VideoRangeType.Seconds:
                    if (startTime > TimeSpan.Zero || endTime < titleDuration)
                    {
                        rangeSection = " - " + startTime.ToFileName() + "-" + endTime.ToFileName();
                    }

                    break;

                case VideoRangeType.Frames:
                    rangeSection = " - Frames " + startFrame + "-" + endFrame;
                    break;
                }

                fileName = sourceName + titleSection + rangeSection;
            }

            return(Utilities.CleanFileName(fileName, allowBackslashes: true));
        }