正在获取歌曲元数据

本文关键字:元数据 获取 | 更新日期: 2023-09-27 18:25:40

我正在尝试从歌曲的绝对URL获取元数据,例如http://www.<url>.com/<file>.mp3

我该怎么做呢。我对C#api有点陌生,所以我有点不知道该使用什么类。

我在附近搜索时发现了这段代码:

StorageFile newFile = //file
var prop =await  newFile.Properties.GetMusicPropertiesAsync();
string album = prop.Album;

我想知道//文件字段里有什么?StorageFile类型的哪些类将接受URI?

谢谢。

正在获取歌曲元数据

首先,您可以使用以下方法将mp3文件下载到本地:

WebClient Client = new WebClient ();
Client.DownloadFile("http://myserver.com/indie/band1.mp3", "band1.mp3");

然后,使用TagLibSharphttps://github.com/mono/taglib-sharp

//Local reference to the file
TagLib.File file = TagLib.File.Create("band1.mp3");
//Get the file metadata
Console.WriteLine("Tags on disk: " + file.TagTypesOnDisk);
Console.WriteLine("Tags in object: " + file.TagTypes);
Write ("Grouping", file.Tag.Grouping);
Write ("Title", file.Tag.Title);
Write ("Album Artists", file.Tag.AlbumArtists);
Write ("Performers", file.Tag.Performers);
Write ("Composers", file.Tag.Composers);
Write ("Conductor", file.Tag.Conductor);
Write ("Album", file.Tag.Album);
Write ("Genres", file.Tag.Genres);
Write ("BPM", file.Tag.BeatsPerMinute);
Write ("Year", file.Tag.Year);
Write ("Track", file.Tag.Track);
Write ("TrackCount", file.Tag.TrackCount);
Write ("Disc", file.Tag.Disc);
Write ("DiscCount", file.Tag.DiscCount);