Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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.
Posted
Updated 4-Mar-20 15:46pm
Comments
Graeme_Grant 31-Jul-17 7:15am    
Umm... what code?

Google is your friend, try searching for :
tagging mp3 files
 
Share this answer
 
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:
C#
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:
C#
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);
        }
    }
}
 
Share this answer
 
v4
Comments
Member 13337539 31-Jul-17 18:57pm    
sorry. wasn't awake enough. I thought I was commenting on some code I had just seen. I have say 100 folders of mp3s already tagged well. BUT not tagged w image art. However in each folder there is an image named "folder.jpg." So I need to recursively search through ^0GB or so of folders and apply the folder.jpg image to all audio files in that one folder as a tag then move on. Thanks for the advice so far..long weekend, long day. Will look at this w fresh eyes tomorrow, been coding all day.
Graeme_Grant 31-Jul-17 19:38pm    
Added recursive directory support... I'll leave the remaining file processing to you ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900