Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Added audio bitrate to the Details Pane #15304

Merged
merged 5 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Files.App/Resources/PreviewPanePropertiesInformation.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,14 @@
"IsReadOnly": false,
"ID": null
},
{
"NameResource": "PropertyPreviewAudioEncodingBitrate",
"SectionResource": "PropertySectionAudio",
"Property": "System.Audio.EncodingBitrate",
"IsReadOnly": true,
"DisplayFunctionName": "FormatEncodingBitrate",
"ID": null
},
{
"NameResource": "PropertyDuration",
"SectionResource": "PropertySectionMedia",
Expand Down
2 changes: 2 additions & 0 deletions src/Files.App/Resources/PropertiesInformation.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
"SectionResource": "PropertySectionAudio",
"Property": "System.Audio.EncodingBitrate",
"IsReadOnly": true,
"DisplayFunctionName": "FormatEncodingBitrate",
"ID": null
},
{
Expand Down Expand Up @@ -499,6 +500,7 @@
"SectionResource": "PropertySectionVideo",
"Property": "System.Video.EncodingBitrate",
"IsReadOnly": true,
"DisplayFunctionName": "FormatEncodingBitrate",
"ID": null
},
{
Expand Down
3 changes: 3 additions & 0 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,9 @@
<data name="PropertyEncodingBitrate" xml:space="preserve">
<value>Encoding Bitrate</value>
</data>
<data name="PropertyPreviewAudioEncodingBitrate" xml:space="preserve">
<value>Audio Encoding Bitrate</value>
Artoryn marked this conversation as resolved.
Show resolved Hide resolved
</data>
<data name="Compression" xml:space="preserve">
<value>Compression</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,6 @@ await LocationHelpers.GetAddressFromCoordinatesAsync((double?)list.Find(
x => x.Property == "System.GPS.LatitudeDecimal").Value,
(double?)list.Find(x => x.Property == "System.GPS.LongitudeDecimal").Value);

// Find Encoding Bitrate property and convert it to kbps
var encodingBitrate = list.Find(x => x.Property == "System.Audio.EncodingBitrate");

if (encodingBitrate?.Value is null)
encodingBitrate = list.Find(x => x.Property == "System.Video.EncodingBitrate");

if (encodingBitrate?.Value is not null)
{
var sizes = new string[] { "Bps", "KBps", "MBps", "GBps" };
var order = (int)Math.Floor(Math.Log((uint)encodingBitrate.Value, 1024));
var readableSpeed = (uint)encodingBitrate.Value / Math.Pow(1024, order);
encodingBitrate.Value = $"{readableSpeed:0.##} {sizes[order]}";
}

return list
.Where(fileProp => !(fileProp.Value is null && fileProp.IsReadOnly))
.GroupBy(fileProp => fileProp.SectionResource)
Expand Down
14 changes: 0 additions & 14 deletions src/Files.App/ViewModels/Properties/Items/FileProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,6 @@ await LocationHelpers.GetAddressFromCoordinatesAsync((double?)list.Find(
x => x.Property == "System.GPS.LatitudeDecimal").Value,
(double?)list.Find(x => x.Property == "System.GPS.LongitudeDecimal").Value);

// Find Encoding Bitrate property and convert it to kbps
var encodingBitrate = list.Find(x => x.Property == "System.Audio.EncodingBitrate");

if (encodingBitrate?.Value is null)
encodingBitrate = list.Find(x => x.Property == "System.Video.EncodingBitrate");

if (encodingBitrate?.Value is not null)
{
var sizes = new string[] { "Bps", "KBps", "MBps", "GBps" };
var order = Math.Min((int)Math.Floor(Math.Log((uint)encodingBitrate.Value, 1024)), 3);
var readableSpeed = (uint)encodingBitrate.Value / Math.Pow(1024, order);
encodingBitrate.Value = $"{readableSpeed:0.##} {sizes[order]}";
}

var query = list
.Where(fileProp => !(fileProp.Value is null && fileProp.IsReadOnly))
.GroupBy(fileProp => fileProp.SectionResource)
Expand Down
13 changes: 13 additions & 0 deletions src/Files.App/ViewModels/Properties/Items/FileProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,22 @@ public async static Task<List<FileProperty>> RetrieveAndInitializePropertiesAsyn
{ "AddISO" , input => $"ISO-{(UInt16)input}"},
{ "RoundDouble" , input => $"{Math.Round((double)input)}"},
{ "UnitMM" , input => $"{(double)input} mm"},
{ "FormatEncodingBitrate", FormatEncodingBitrate }
};

private static string TimeSpanToString(TimeSpan t)
=> t.Days > 0 ? (t.Days * 24 + t.Hours) + t.ToString("':'mm':'ss") : t.ToString("hh':'mm':'ss");

private static string FormatEncodingBitrate(object input)
{
// For cases when multiple files are selected and it has a string value
if (input.GetType() != typeof(uint))
return input?.ToString() ?? string.Empty;

var sizes = new string[] { "bps", "kbps", "mbps", "gbps" };
Artoryn marked this conversation as resolved.
Show resolved Hide resolved
var order = (int)Math.Floor(Math.Log((uint)input, 1000));
var readableSpeed = (uint)input / Math.Pow(1000, order);
return $"{readableSpeed:0.##} {sizes[order]}";
}
}
}
Loading