Skip to content
This repository has been archived by the owner on Apr 13, 2024. It is now read-only.

Commit

Permalink
Use final file extension in temporary file
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcos Cordeiro committed Nov 13, 2023
1 parent e8183a5 commit 5175fd0
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions Wasari.FFmpeg/FFmpegService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,22 +171,21 @@ private static Command CreateCommand()
.WithWorkingDirectory(Environment.CurrentDirectory);
}

private string? GetTemporaryFile(string? baseFilePath = null)
private string? GetTemporaryFile(string extension, string? baseFilePath = null)
{
if (baseFilePath != null)
{
var fileName = Path.GetFileNameWithoutExtension(baseFilePath);
var fileExtension = Path.GetExtension(baseFilePath);
var fileDirectory = Path.GetDirectoryName(baseFilePath);

return $"{fileDirectory}{Path.DirectorySeparatorChar}{fileName}_wasari_tmp.{fileExtension}";
return $"{fileDirectory}{Path.DirectorySeparatorChar}{fileName}_wasari_tmp{extension}";
}

if (!Options.Value.UseTemporaryEncodingPath)
return null;

var tempFileName = Path.GetFileNameWithoutExtension(Path.GetTempFileName());
return Path.Combine(Path.GetTempPath(), $"{tempFileName}.mp4");
return Path.Combine(Path.GetTempPath(), $"{tempFileName}.{extension}");
}

public TimeSpan? GetVideoDuration(IMediaAnalysis mediaAnalysis)
Expand Down Expand Up @@ -247,7 +246,7 @@ public async Task<bool> CheckIfVideoStreamIsValid(string filePath)

public async Task DownloadEpisode<T>(T episode, string filePath, IProgress<FFmpegProgressUpdate>? progress) where T : IWasariEpisode
{
var tempFileName = GetTemporaryFile();
var tempFileName = GetTemporaryFile(Path.GetExtension(filePath));
var arguments = await BuildArgumentsForEpisode(episode, tempFileName ?? filePath).ToArrayAsync();
var ffmpegCommand = CreateCommand()
.WithValidation(CommandResultValidation.None)
Expand Down

0 comments on commit 5175fd0

Please sign in to comment.