Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,22 @@
"IsReadOnly": false,
"ID": null
},
{
"NameResource": "PropertyPreviewAudioEncodingBitrate",
"SectionResource": "PropertySectionAudio",
"Property": "System.Audio.EncodingBitrate",
"IsReadOnly": true,
"DisplayFunctionName": "FormatEncodingBitrate",
"ID": null
},
{
"NameResource": "PropertyPreviewVideoEncodingBitrate",
"SectionResource": "PropertySectionVideo",
"Property": "System.Video.EncodingBitrate",
"IsReadOnly": true,
"DisplayFunctionName": "FormatEncodingBitrate",
"ID": null
},
{
"NameResource": "PropertyDuration",
"SectionResource": "PropertySectionMedia",
Expand Down
2 changes: 2 additions & 0 deletions src/Files.App/Assets/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
6 changes: 6 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,12 @@
<data name="PropertyEncodingBitrate" xml:space="preserve">
<value>Encoding Bitrate</value>
</data>
<data name="PropertyPreviewAudioEncodingBitrate" xml:space="preserve">
<value>Audio Encoding Bitrate</value>
</data>
<data name="PropertyPreviewVideoEncodingBitrate" xml:space="preserve">
<value>Video Encoding Bitrate</value>
</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" };
var order = (int)Math.Floor(Math.Log((uint)input, 1000));
var readableSpeed = (uint)input / Math.Pow(1000, order);
return $"{readableSpeed:0.##} {sizes[order]}";
}
}
}