Ejemplo n.º 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 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);
		}