Skip to content

Commit

Permalink
More robust file extension assumption for CLI videodownload
Browse files Browse the repository at this point in the history
  • Loading branch information
ScrubN committed Feb 3, 2024
1 parent 18e1949 commit 94971a4
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions TwitchDownloaderCLI/Modes/DownloadVideo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,20 @@ private static VideoDownloadOptions GetDownloadOptions(VideoDownloadArgs inputOp
}

var vodIdMatch = TwitchRegex.MatchVideoId(inputOptions.Id);
if (vodIdMatch is not { Success: true})
if (vodIdMatch is not { Success: true })
{
Console.WriteLine("[ERROR] - Unable to parse Vod ID/URL.");
Environment.Exit(1);
}

if (!Path.HasExtension(inputOptions.OutputFile) && inputOptions.Quality is { Length: > 0 })
{
if (char.IsDigit(inputOptions.Quality[0]))
inputOptions.OutputFile += ".mp4";
else if (char.ToLower(inputOptions.Quality[0]) is 'a')
if (inputOptions.Quality.Contains("audio", StringComparison.OrdinalIgnoreCase))
inputOptions.OutputFile += ".m4a";
else if (char.IsDigit(inputOptions.Quality[0])
|| inputOptions.Quality.Contains("source", StringComparison.OrdinalIgnoreCase)
|| inputOptions.Quality.Contains("chunked", StringComparison.OrdinalIgnoreCase))
inputOptions.OutputFile += ".mp4";
}

VideoDownloadOptions downloadOptions = new()
Expand All @@ -70,4 +72,4 @@ private static VideoDownloadOptions GetDownloadOptions(VideoDownloadArgs inputOp
return downloadOptions;
}
}
}
}

0 comments on commit 94971a4

Please sign in to comment.