public void ProcessFile() { _log = new LoggerConfiguration() .WriteTo.File($"logs\\{DateTime.UtcNow.ToString("yyyyMMdd-HHmm")}-{_inputVideoFileName}.log") .WriteTo.Console() .CreateLogger(); _attributes = GetAttributes(); _log.Information("Media attributes:{@attributes}", _attributes); _metadata = GetMetadata(); _log.Information("Media tags:{@metadata}", _metadata.Text); _episode = new TvEpisode() .Defaults() .FromFileName(_inputVideoFileName) .FromJsonMetadata(_metadata) .FromMediaCenterAttributes(_attributes) .FromDescription() .FixTitleAndShowName() .MapShowName(_appContext.ShowNameMap) .SetSafeShowName().Log(_log, "Episode"); _outputFileName = _episode.GetOutputFileName(); _log.Information("Output file name:\"{OutputFileName}\"", _outputFileName); var outputFile = GetOutputFile(_inputVideoFileExtension); _log.Information("Output file:\"{OutputFile}\"", outputFile); if (File.Exists(outputFile) == false) { _log.Information("Copying input file \"{Input}\" to \"{Output}\"", _inputVideoFile, outputFile); if (_appContext.WhatIf == false) { if (_appContext.CreateSymbolicLink) { NativeHelpers.CreateSymbolicFileLink(_inputVideoFile, outputFile); } else { File.Copy(_inputVideoFile, outputFile); } _log.Information("Finished copying input file \"{Input}\" to \"{Output}\"", _inputVideoFile, outputFile); } var thumbnailFile = GetOutputFile(".jpg"); if (TryCreateThumbnailFile(thumbnailFile)) { _episode.ThumbnailFile = thumbnailFile; } NfoFileHandler(); } else { _log.Information("Not processing input file because the output file already exists"); } }
public void ProcessFile() { _log = new LoggerConfiguration() .WriteTo.File($"logs\\{DateTime.UtcNow.ToString("yyyyMMdd-HHmm")}-{_inputVideoFileName}.log") .WriteTo.Console() .CreateLogger(); _attributes = GetAttributes(); _log.Information("Media attributes:{@attributes}", _attributes); _metadata = GetMetadata(); _log.Information("Media tags:{@metadata}", _metadata.Text); _episode = new TvEpisode() .Defaults() .FromFileName(_inputVideoFileName) .FromJsonMetadata(_metadata) .FromMediaCenterAttributes(_attributes) .FromDescription() .FixTitleAndShowName() .SetSafeShowName().Log(_log, "Episode"); _outputFileName = _episode.GetOutputFileName(); _log.Information("Output file name:\"{OutputFileName}\"", _outputFileName); var outputFile = GetOutputFile(".mp4"); _log.Information("Output file:\"{OutputFile}\"", outputFile); if (File.Exists(outputFile) == false) { var tempFile = GetTemporaryFile(); _log.Information("Temporary file:\"{TempFile}\"", tempFile); bool tempFileCreated = false; bool tempFileExists = File.Exists(tempFile); if (tempFileExists == false) { tempFileCreated = tempFileExists = _appContext.WhatIf; if (_appContext.WhatIf == false) { _appContext.FfmpegCommand.ConvertWtvToMp4File(_inputVideoFile, tempFile); _log.Information("ConvertWtvToMp4File:{@ffmpeg}", _appContext.FfmpegCommand); tempFileCreated = tempFileExists = _appContext.FfmpegCommand.ExitCode == 0 && File.Exists(tempFile); } } else { _log.Information("Not converting input file because the converted file already exists"); } if (tempFileExists) { var thumbnailFile = GetOutputFile(".jpg"); if (TryCreateThumbnailFile(thumbnailFile)) { _episode.ThumbnailFile = thumbnailFile; } if (_appContext.WhatIf == false) { _appContext.AtomicParsleyCommand.SetMp4FileMetadata(_episode, tempFile, outputFile); _log.Information("SetMp4FileMetadata:{@AtomicParsley}", _appContext.AtomicParsleyCommand); } NfoFileHandler(); if (_appContext.DeleteTempFile && tempFileCreated) { if (_appContext.WhatIf == false) { _log.Information("Deleting temporary file:\"{TempFile}\"", tempFile); File.Delete(tempFile); } } } } else { _log.Information("Not processing input file because the output file already exists"); } }