使用taglib-sharp和Powershell更新歌曲元数据 [英] Update a song metadata with taglib-sharp and Powershell

查看:97
本文介绍了使用taglib-sharp和Powershell更新歌曲元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用taglib-sharppowershell更新歌曲元数据. 对于大多数文件来说,它都可以正常工作,但是某些wma文件存在错误(尽管我可以播放这些文件).

I am trying to update a song metadata with taglib-sharp and powershell. It works fine for most of the files but there are errors on some wma files (I can play these files though).

# Load the tag-lib assembly
[Reflection.Assembly]::LoadFrom( (Resolve-Path ("D:\zic\lib\taglib-sharp.dll")))

# Load up the song file and its metadata
$path_file="‪D:\zic\misc\Artist_Title.wma"
$song = [TagLib.File]::Create((resolve-path $path_file))
$file_name = [System.IO.Path]::GetFileNameWithoutExtension($path_file) 
$file_name_array=$file_name.Split("_")
$artist=$file_name_array[0]
$title=$file_name_array[1]

#set the artist and title (metadata)
$song.Tag.Artists = $artist 
$song.Tag.AlbumArtists = $artist 
$song.Tag.Title = $title

# Save the metadata 
$song.Save() 

保存文件时出现错误:

The error appears when the file is saved:

这是powershell问题吗? taglib-sharp问题? 我正在使用taglib_sharp版本2.0.50727和powershell版本5.1.16299.248.

Is it a powershell problem? A taglib-sharp problem? I am using taglib_sharp version 2.0.50727 and powershell version 5.1.16299.248.

编辑

尝试捕获以显示错误:

# Save the metadata
try
{
    $song.Save() 
}
catch [Exception]
{
    Write-Host $_.Exception|format-list -force
}

控制台显示:

编辑2

如果我手动编辑标签(右键单击文件->属性)或重命名文件,则程序会正常运行,并且标签会更新.奇怪!

If I edit the tags manually (right click on the file -> properties) or rename the file, the program runs without problem and the tags are updated. Weird!

推荐答案

正如@tukan所建议的那样,某些标签的长度是问题所在.

As @tukan suggested, the length of some tags was the problem.

让我们显示一首歌曲的所有标签:

Let's display all the tags of a song:

$song = [TagLib.File]::Create((resolve-path $path_file))
foreach ($tag in $song.Tag)
{
    Write-Host "tag:" $tag
}

输出:

tag:
tag: {D1607DBC-E323-4BE2-86A1-48A42A28441E}
tag: 10.00.00.3802
tag: 0.0.0.0000
tag: 0
tag: 2007
tag: 128317523430000000
tag: AMGa_id=R  1411185;AMGp_id=VA;AMGt_id=T 14593744
tag: Éri Tabuhci
tag: Universal
tag: World
tag: Les 100 Plus Grands Tubes Disc 3
tag: Unknown Artist
tag: 14+96+34B7+ADE8+E42D+11DF5+15230+196F2+1C2D1+1FC01+257E9+29612+2D100+30FB0+34ECE+3923F+3D39B+40CF6+454FF+49162+4D5D0+521B0
tag: AMG
tag: World
tag: 5

末尾的第四个标签太长,是导致问题的原因. 解决方案是加载文件,删除所有现有标签,保存,再次加载,然后设置所需的标签. 例如:

The fourth tag from the end is too long and is the cause of the problem. The solution is to load the file, remove all the existing tags, save it, load it again and then set the tags you want. For example:

$song = [TagLib.File]::Create((resolve-path $path_file))
$song.RemoveTags($song.TagTypes)
$song.Save()

$song = [TagLib.File]::Create((resolve-path $path_file))
$song.Tag.Artists = "blabla"
...

希望这会有所帮助!

这篇关于使用taglib-sharp和Powershell更新歌曲元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆