Question

I'm trying to update the label/publisher field using Taglib-sharp, but I can't see it anywhere in its Object Hierarchy using Object Browser.

I've searched through google and the documentation and it looks like it's a field that's not catered for.

Before I look for alternatives (can any one suggest any?) that can edit those field, I thought I'd have one last crack and ask within the StackOverflow community who is familiar with TagLib-sharp that had a more informed opinion?

Thanks in Advance,

Francis

Update : I've investigated other libraries such as mpg123 & UltraID3Lib but they seem to have the same limitations.

Was it helpful?

Solution

Well, Daniel Fuchs answer didn't work for me. But, it was a beginning.

The step by step to add a field in the TagLib-sharp code is:

  1. Download Source

  2. Open the File TagLib/Tag.cs and insert the following code (I inserted it below PerformersSort, line 250):

    public virtual string Publisher
    {
        get { return ""; }
        set { }
    }
    
  3. Open the File TagLib/Id3v2/Tag.cs and insert the following code (I inserted it below PerformersSort, line 1292):

    public override string Publisher
    {
        get { return GetTextAsString(FrameType.TPUB); }
        set { SetTextFrame(FrameType.TPUB, value); }
    }
    
  4. Open the File TagLib/Id3v2/FrameTypes.cs and insert the following code (I inserted it below TPOS, line 71):

    public static readonly ReadOnlyByteVector TPUB = "TPUB";
    
  5. Now comes the "Aha" thing. Open the File TagLib/CombinedTag.cs and insert the following code (I inserted it below PerformersSort, line 318):

    public override string Publisher
    {
        get
        {
            foreach (Tag tag in tags)
            {
                if (tag == null)
                    continue;
    
                string value = tag.Publisher;
    
                if (value != null)
                    return value;
            }
    
            return null;
        }
    
        set
        {
            foreach (Tag tag in tags)
                if (tag != null)
                    tag.Publisher = value;
        }
    }
    
  6. Finally, compile the code.

IMPORTANT: I had problems compiling the code, as well. You must download the SharpZipLib dll (.NET 2.0) and include this dll in the taglib project. Also, I needed to install NUnit, which I made with Nuget. At last, I commented the GDK lib and all its errors inside the test code, since in production it won't be used.

OTHER TIPS

Well TagLib# is not able to to read the publisher tag. Even the newest version (2.1.0.0) as of now won't be able to do that. As an alternative you can add this functionality yourself using the source code of TagLib#, which is freely available.

To do so, open the file TagLib/Id3v2/FrameTypes.cs and add the following line somewhere:

public static readonly ReadOnlyByteVector TPUB = "TPUB";  // Publisher field

And in the file TagLib/Id3v2/Tag.cs:

public string Publisher {
    get {return GetTextAsString (FrameType.TPUB);}
    set {SetTextFrame (FrameType.TPUB, value);}
}

You can then access the Publisher field using something like this

TagLib.File tf = TagLib.File.Create(...);   // open file
tf.Tag.Publisher = "Label XY";              // write new Publisher
tf.Save();                                  // save tags

Please note, that this is an ugly hack but will work for MP3 files.

I'm not used to TagLib#, but I'm using TagLib in a Qt project, where I retrieve this information inspecting TagLib::File::properties. Take a look at the documentation, it is just a string map with every property and values.

Hope TagLib# has this method.

Update 2019-12-30:

It looks like the main taglib project has included the publisher field, so you should just use the latest version instead. I've updated to the latest TagLib from my fork and can attest that it works as expected.

Tip : If you want to change the framework version that TagLib compiles to (at time of writing it defaults to 462 and .NET STD 2.0), you need to change the Directory.Build.Props file located in the Solutions folder.

<Project>
<PropertyGroup>
    <ReleaseVersion>2.2.0.0-beta</ReleaseVersion>
    <RepositoryUrl>https://github.com/mono/taglib-sharp</RepositoryUrl>
    <RepositoryType>git</RepositoryType>
    <TaglibSharpTargetFramework>net472;netstandard2.0</TaglibSharpTargetFramework>
    <LangVersion>latest</LangVersion>
</PropertyGroup>
</Project>

I've pasted my version above which shows that I've changed it to compile to .NET 4.7.2 instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top