【问题标题】:Getting song tags and adding to the ID3 tag list获取歌曲标签并添加到 ID3 标签列表
【发布时间】:2012-11-10 16:03:57
【问题描述】:

我的问题解决了^^

以下代码扫描一个文件夹及其子目录,并为每个 .mp3 和 .wav 使用其 ID3 标签从 last.fm 中查找所有标签。

我需要添加更多文字来解释我的代码:

您可以使用 main 中的 args 来添加额外的选项,例如自定义位置,不做子目录,....

使用 2 个参考:

• lastfm-sharp.dll
• taglib-sharp.dll

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Lastfm.Services;

namespace AddTags {

    /// <summary>
    /// Class made for scanning a folder and giving all mp3s more 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();
        }
    }
}

【问题讨论】:

    标签: c# json xml id3 last.fm


    【解决方案1】:

    相同的东西见第一篇文章xD

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using Lastfm.Services;
    
    namespace 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("94b659f1b129a3f110a0faa269b4be68", "649461398a675e38870c07b1614085e4");
    
                // Authenticate it with a username and password to be able
                // to perform write operations and access this user's profile
                // private data.
                session.Authenticate("cskiwi", Lastfm.Utilities.md5("Cskiwi147963"));
    
                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();
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-02
      • 1970-01-01
      • 1970-01-01
      • 2013-08-24
      • 1970-01-01
      • 2015-07-21
      • 2016-06-11
      • 1970-01-01
      相关资源
      最近更新 更多