0
解決我的問題^^ 下面的代碼掃描一個文件夾+子目錄,並使用每個.MP3 & .WAV他的ID3標籤從last.fm獲取歌曲的標籤,並增加了ID3標籤列表
發現所有的標籤哎呀我需要添加更多的文字來解釋我的代碼:
您可以使用ARGS從主,以增加額外的選項,如俗loactions,沒有做子目錄,....
使用2個引用:
- LastFM等-sharp.dll
標籤庫-sharp.dll使用System
; using System.Collections.Generic;使用System.IO的 ;使用System.Linq的 ; 使用Lastfm.Services;
命名空間AddTags {
/// <summary> /// Class made for scanning a folder and giving al mp3's moar tags /// </summary> internal class Program { public static void Main(string[] args) { Session session = new Session("<api>", "<secret>"); // Authenticate it with a username and password to be able // to perform write operations and access this user's profile // private data. session.Authenticate("<username>", Lastfm.Utilities.md5("<password>")); DirectoryInfo dir = new DirectoryInfo("C:\\Users\\kiwi\\Dropbox\\music\\Mk3"); Console.WriteLine("Setting genretags for directory: " + dir.FullName); foreach (FileInfo file in dir.GetFiles("*.*", SearchOption.AllDirectories).Where(file => file.Extension.Equals(".mp3") || file.Extension.Equals(".wav"))) { Console.WriteLine(); Console.WriteLine(" --- " + file.Name + " ---"); TagLib.File TagFile = TagLib.File.Create(file.FullName); // Create an Artist object. if (TagFile.Tag.Performers.Length > 0) { Artist artist = new Artist(TagFile.Tag.Performers[0], session); // Display your current tags for system of a down. List<string> tags = new List<string>(); try { foreach (TopTag tag in artist.GetTopTags(20)) tags.Add(tag.Item.Name.ToString()); if (tags.Count == 0) Console.WriteLine("No tags found"); } catch (Exception e) { Console.WriteLine("Artist not found"); } TagFile.Tag.Genres = tags.ToArray(); TagFile.Save(); foreach (string tag in TagFile.Tag.Genres) { Console.Write(" " + tag); } } else { Console.WriteLine("No artist found in tags"); } Console.WriteLine(); } Console.Write("press any key to exit"); Console.ReadLine(); } }
}