Skip to content

Commit

Permalink
Rename SanitizeKeyValue to EscapeMetadataValue
Browse files Browse the repository at this point in the history
  • Loading branch information
ScrubN committed Aug 11, 2024
1 parent 4be2a5f commit 934e031
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions TwitchDownloaderCore/Tools/FfmpegMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,23 @@ private static async Task SerializeGlobalMetadata(StreamWriter sw, [AllowNull] s
{
// ReSharper disable once StringLiteralTypo
await sw.WriteLineAsync(";FFMETADATA1");
await sw.WriteLineAsync($"title={SanitizeKeyValue(title)} ({SanitizeKeyValue(id)})");
await sw.WriteLineAsync($"title={EscapeMetadataValue(title)} ({EscapeMetadataValue(id)})");
if (!string.IsNullOrWhiteSpace(streamer))
await sw.WriteLineAsync($"artist={SanitizeKeyValue(streamer)}");
await sw.WriteLineAsync($"artist={EscapeMetadataValue(streamer)}");
await sw.WriteLineAsync($"date={createdAt:yyyy}"); // The 'date' key becomes 'year' in most formats
if (!string.IsNullOrWhiteSpace(game))
await sw.WriteLineAsync($"genre={game}");
await sw.WriteAsync(@"comment=");
if (!string.IsNullOrWhiteSpace(description))
{
// We could use the 'description' key, but so few media players support mp4 descriptions that users would probably think it was missing
await sw.WriteLineAsync(@$"{SanitizeKeyValue(description.TrimEnd())}\");
await sw.WriteLineAsync(@$"{EscapeMetadataValue(description.TrimEnd())}\");
await sw.WriteLineAsync(@"------------------------\");
}
if (!string.IsNullOrWhiteSpace(clipper))
await sw.WriteLineAsync($@"Clipped by: {SanitizeKeyValue(clipper)}\");
await sw.WriteLineAsync(@$"Created at: {SanitizeKeyValue(createdAt.ToString("u"))}\");
await sw.WriteLineAsync(@$"Video id: {SanitizeKeyValue(id)}\");
await sw.WriteLineAsync($@"Clipped by: {EscapeMetadataValue(clipper)}\");
await sw.WriteLineAsync(@$"Created at: {EscapeMetadataValue(createdAt.ToString("u"))}\");
await sw.WriteLineAsync(@$"Video id: {EscapeMetadataValue(id)}\");
await sw.WriteLineAsync(@$"Views: {viewCount}");
}

Expand Down Expand Up @@ -102,7 +102,7 @@ private static async Task SerializeChapters(StreamWriter sw, IEnumerable<VideoMo
await sw.WriteLineAsync("TIMEBASE=1/1000");
await sw.WriteLineAsync($"START={startMillis}");
await sw.WriteLineAsync($"END={startMillis + lengthMillis}");
await sw.WriteLineAsync($"title={SanitizeKeyValue(gameName)}");
await sw.WriteLineAsync($"title={EscapeMetadataValue(gameName)}");
}
}

Expand All @@ -128,7 +128,9 @@ private static string GetUserName([AllowNull] string displayName, [AllowNull] st
}

// https://trac.ffmpeg.org/ticket/11096 The Ffmpeg documentation is outdated and =;# do not need to be escaped.
private static string SanitizeKeyValue(string str)
// TODO: Use nameof(filename) when C# 11+
[return: NotNullIfNotNull("str")]
private static string EscapeMetadataValue([AllowNull] string str)
{
if (string.IsNullOrWhiteSpace(str))
{
Expand Down

0 comments on commit 934e031

Please sign in to comment.