此代码是否可以找到具有合法名称的图像并将该图像应用于同一文件夹中的每个音乐文件? [英] Can this code find an image with a secified name and apply that image to every music file in the same folder?

查看:59
本文介绍了此代码是否可以找到具有合法名称的图像并将该图像应用于同一文件夹中的每个音乐文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个巨大的音乐库,其专辑封面名为folder.jpg。许多玩家过去习惯将此视为专辑封面,但我希望文件夹中的每个音乐文件都有一个带有2个名称之一的图像,以使该图像文件名标记有该文件夹中的图像。这个软件是这样做的,还是可以的?



我尝试了什么:



我没多尝试过;只是蛮力。

I have a huge music library with album art named either folder.jpg, for instance. Many players used to use consider this as album art, but I'd like every music file within a folder that has an image with one of 2 names to have that image filename tagged with the image that resides in that folder. Does this software do this, or can it?

What I have tried:

I haven't tried much; just brute force.

推荐答案

谷歌是你的朋友,试着搜索:
Google is your friend, try searching for :
tagging mp3 files


这是一个非常受欢迎的元数据阅读器&作家,不仅仅是MP3: GitHub - mono / taglib-sharp:用于在媒体文件中读取和编写元数据的图书馆 [< a href =https://github.com/mono/taglib-sharptarget =_ blanktitle =新窗口> ^ ]



刚试了一下lib。以下是我使用的测试代码:

This is a very popular metadata reader & writer, not just for MP3s: GitHub - mono/taglib-sharp: LIbrary for reading and writing metadata in media files[^]

Just gave the lib a try. Here is my test code used:
private static void Main(string[] args)
{
    var path = @"E:\Music";
    foreach (var file in System.IO.Directory.GetFiles(path))
    {
        ProcessFile(file);
    }
    Console.ReadKey();
}

static void ProcessFile(string Filename)
{
    Console.WriteLine("Filename: ", Filename);

    TagLib.File file = TagLib.File.Create(Filename);
    Console.WriteLine("Name: ", file.Name);
    Console.WriteLine("Current picture count: " + file.Tag.Pictures.Length);
    for (int i = 0; i < file.Tag.Pictures.Length; i++)
    {
        var pic = file.Tag.Pictures[i];
        Console.WriteLine("{0} Description: {1} / {2}", i + 1, pic.Description, pic.Type);
    }
}



更新:

这是添加的递归目录:


Update:
Here is recursive directory added:

internal static class Program
{
    private static void Main(string[] args)
    {
        var path = @"E:\music";
        ProcessDirectories(path);

        Console.ReadKey();
    }

    private static void ProcessDirectories(string startPath)
    {
        foreach (string dir in System.IO.Directory.GetDirectories(startPath))
        {
            Console.WriteLine("Dir: {0}", dir);
            ProcessFiles(dir);
            ProcessDirectories(dir);
        }
    }

    private static void ProcessFiles(string dir)
    {
        foreach (var file in System.IO.Directory.GetFiles(dir))
        {
            if (System.IO.Path.GetExtension(file).Equals(".mp3", StringComparison.InvariantCultureIgnoreCase))
            {
                ProcessFile(file);
            }
        }
    }

    private static void ProcessFile(string Filename)
    {
        // do processing here...
        Console.WriteLine(" - File: {0}", Filename);

        TagLib.File file = TagLib.File.Create(Filename);
        Console.WriteLine("   Name: ", file.Name);
        Console.WriteLine("   Picture count: " + file.Tag.Pictures.Length);
        for (int i = 0; i < file.Tag.Pictures.Length; i++)
        {
            var pic = file.Tag.Pictures[i];
            Console.WriteLine("   {0} Description: {1} / {2}", i + 1, pic.Description, pic.Type);
        }
    }
}


这篇关于此代码是否可以找到具有合法名称的图像并将该图像应用于同一文件夹中的每个音乐文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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