Skip to content

Commit

Permalink
Fixed removal of property "part" and "movement"
Browse files Browse the repository at this point in the history
  • Loading branch information
sandreas committed Oct 31, 2024
1 parent 2b2cf91 commit b0f4a4b
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*/obj/
*/bin/
*/tmp/
*/var/
!*/var/*.gitkeep
*/dist/
Expand Down
18 changes: 18 additions & 0 deletions CliTester/CliTester.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Sandreas.AudioMetadata\Sandreas.AudioMetadata.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="tmp\" />
</ItemGroup>

</Project>
32 changes: 32 additions & 0 deletions CliTester/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// See https://aka.ms/new-console-template for more information

using ATL;
using Sandreas.AudioMetadata;


var src = "/home/andreas/projects/DotnetLibAudioMetadata/CliTester/samples/sample.mp3";
var dst = "/home/andreas/projects/DotnetLibAudioMetadata/CliTester/tmp/sample.mp3";
/*
if (File.Exists(dst))
{
File.Delete(dst);
}
File.Copy(
src,
dst
);
*/
/*
var track = new Track(dst);
track.AdditionalFields.Clear();
track.SeriesPart = null;
await track.SaveAsync();
return await Task.FromResult(0);
*/

var track = new MetadataTrack(dst);

track.RemoveMetadataPropertyValue(MetadataProperty.Part);
await track.SaveAsync();
return await Task.FromResult(0);
Binary file added CliTester/samples/sample.flac
Binary file not shown.
Binary file added CliTester/samples/sample.m4a
Binary file not shown.
Binary file added CliTester/samples/sample.mp3
Binary file not shown.
6 changes: 6 additions & 0 deletions DotnetLibAudioMetadata.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sandreas.AudioMetadata", "S
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sandreas.AudioMetadata.Tests", "Sandreas.AudioMetadata.Tests\Sandreas.AudioMetadata.Tests.csproj", "{680C5977-EB3D-4D9C-AA31-2DA323749779}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CliTester", "CliTester\CliTester.csproj", "{6C35B672-75F8-4217-8C54-E5ED4966C0D3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -18,5 +20,9 @@ Global
{680C5977-EB3D-4D9C-AA31-2DA323749779}.Debug|Any CPU.Build.0 = Debug|Any CPU
{680C5977-EB3D-4D9C-AA31-2DA323749779}.Release|Any CPU.ActiveCfg = Release|Any CPU
{680C5977-EB3D-4D9C-AA31-2DA323749779}.Release|Any CPU.Build.0 = Release|Any CPU
{6C35B672-75F8-4217-8C54-E5ED4966C0D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6C35B672-75F8-4217-8C54-E5ED4966C0D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6C35B672-75F8-4217-8C54-E5ED4966C0D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6C35B672-75F8-4217-8C54-E5ED4966C0D3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
21 changes: 12 additions & 9 deletions Sandreas.AudioMetadata/AudioMetadata/IMetadataExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,19 @@ public static class MetadataExtensions
_ => null
};

public static void RemoveMetadataPropertyValue(this IMetadata metadata, MetadataProperty property)
{
metadata.SetMetadataPropertyValue(property, metadata.GetPropertyValueThatLeadsToRemoval(property));
public static void RemoveMetadataPropertyValue(this IMetadata metadata, MetadataProperty property) {
switch(property) {
case MetadataProperty.Movement:
metadata.Movement = "";
break;
case MetadataProperty.Part:
metadata.Part = "";
break;
default:
metadata.SetMetadataPropertyValue(property, metadata.GetPropertyValueThatLeadsToRemoval(property));
break;
}
}

public static object? GetMetadataPropertyValue(this IMetadata metadata, MetadataProperty property) =>
property switch
{
Expand Down Expand Up @@ -175,11 +183,6 @@ public static void SetMetadataPropertyValue(this IMetadata metadata, MetadataPro
/// <returns></returns>
private static object? GetPropertyValueThatLeadsToRemoval(this IMetadata metadata, MetadataProperty property)
{
if (property == MetadataProperty.Movement)
{
return null;
}

if (metadata.GetMetadataPropertyType(property) == typeof(string))
{
return "";
Expand Down
20 changes: 14 additions & 6 deletions Sandreas.AudioMetadata/AudioMetadata/MetadataTrack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,17 @@ public string? Movement
{
get => SeriesPart;
set {
// movement MUST contain an integer value, which leads to an exception, if a string like 1.5 is stored
// movement MUST contain a valid integer value, which leads to an exception, if a string like 1.5 is provided
// to store a non-integer value, use Part instead
if (value == "")
if (string.IsNullOrEmpty(value))
{
value = null;
// SeriesPart only gets removed with an empty string
// null does not work
SeriesPart = "";
}
if (value == null || int.TryParse(value, out _))
else if ( int.TryParse(value, out var intValue))
{
SeriesPart = value;
SeriesPart = intValue.ToString();
}
}
}
Expand All @@ -134,8 +136,14 @@ public string? Part
get => GetAdditionalField(StringField) ?? Movement;
set
{
// empty values will remove movement property,
// otherwise, movement should be set same as part only
// if they already have the same value
if (!string.IsNullOrEmpty(value) && GetAdditionalField(StringField) == Movement)
{
Movement = value;
}
SetAdditionalField(value);
Movement = value;
}
}

Expand Down

0 comments on commit b0f4a4b

Please sign in to comment.