简体   繁体   English

taglib-sharp 中是否有与 Label/Publisher 等效的字段?

[英]Is there an equivalent field to Label/Publisher in taglib-sharp?

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.我正在尝试使用 Taglib-sharp 更新标签/发布者字段,但我无法使用对象浏览器在其对象层次结构中的任何地方看到它。

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?在我寻找可以编辑这些字段的替代方案(有人可以提出任何建议吗?)之前,我想我会最后一次破解并在 StackOverflow 社区中询问熟悉 TagLib-sharp 的人有更明智的意见吗?

Thanks in Advance,提前致谢,

Francis弗朗西斯

Update : I've investigated other libraries such as mpg123 & UltraID3Lib but they seem to have the same limitations.更新:我调查了其他库,例如 mpg123 和 UltraID3Lib,但它们似乎有相同的限制。

Well, Daniel Fuchs answer didn't work for me.好吧,Daniel Fuchs 的回答对我不起作用。 But, it was a beginning.但是,这是一个开始。

The step by step to add a field in the TagLib-sharp code is:在 TagLib-sharp 代码中添加字段的步骤是:

  1. Download Source下载

  2. Open the File TagLib/Tag.cs and insert the following code (I inserted it below PerformersSort, line 250) :打开文件TagLib/Tag.cs并插入以下代码(我将其插入到 PerformersSort 下方,第 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) :打开文件TagLib/Id3v2/Tag.cs并插入以下代码(我将其插入到 PerformersSort 下方,第 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) :打开文件TagLib/Id3v2/FrameTypes.cs并插入以下代码(我将其插入到 TPOS 下方,第 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) :打开文件TagLib/CombinedTag.cs并插入以下代码(我将其插入到 PerformersSort 下方,第 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.您必须下载SharpZipLib dll (.NET 2.0) 并将此 dll 包含在 taglib 项目中。 Also, I needed to install NUnit, which I made with Nuget.另外,我需要安装我用 Nuget 制作的 NUnit。 At last, I commented the GDK lib and all its errors inside the test code, since in production it won't be used.最后,我在测试代码中评论了 GDK 库及其所有错误,因为在生产中不会使用它。

Well TagLib# is not able to to read the publisher tag.那么 TagLib# 无法读取发布商标签。 Even the newest version (2.1.0.0) as of now won't be able to do that.即使是目前最新的版本 (2.1.0.0) 也无法做到这一点。 As an alternative you can add this functionality yourself using the source code of TagLib#, which is freely available.作为替代方案,您可以使用免费提供的 TagLib# 源代码自行添加此功能。

To do so, open the file TagLib/Id3v2/FrameTypes.cs and add the following line somewhere:为此,请打开文件TagLib/Id3v2/FrameTypes.cs并在某处添加以下行:

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

And in the file TagLib/Id3v2/Tag.cs :在文件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然后,您可以使用类似的方法访问 Publisher 字段

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.请注意,这是一个丑陋的黑客,但适用于 MP3 文件。

I'm not used to TagLib#, but I'm using TagLib in a Qt project, where I retrieve this information inspecting TagLib::File::properties .我不习惯 TagLib#,但我在 Qt 项目中使用 TagLib,在那里我通过检查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.希望 TagLib# 有这个方法。

Update 2019-12-30: 2019-12-30 更新:

It looks like the main taglib project has included the publisher field, so you should just use the latest version instead.看起来主要的taglib项目已经包含了publisher 字段,所以你应该只使用最新版本。 I've updated to the latest TagLib from my fork and can attest that it works as expected.我已经从我的 fork 更新到最新的 TagLib,可以证明它按预期工作。

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.提示:如果您想更改 TagLib 编译到的框架版本(在编写时默认为 462 和 .NET STD 2.0),您需要更改位于 Solutions 文件夹中的 Directory.Build.Props 文件。

<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.我在上面粘贴了我的版本,这表明我已将其更改为编译为 .NET 4.7.2。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM