Showing posts with label metadata. Show all posts
Showing posts with label metadata. Show all posts

Mp3tag and its useful actions like Replace with regular expression and Guess values

Every once in a while I’m in a situation where I need to refresh my mind about how to work with regular expressions and guess values in Mp3tag to batch process lots of MP3 in a single shot… I’ll try to keep this post as a reference for the artifices I use with Mp3tag so that I can get back here and see what and how I did to format my MP3 tags the way they should be.

Mp3tag - The Universal Tag EditorMp3tag is IMHO the best MP3 tag editor out there. I’m so satisfied with it that I stopped trying to find a better tool. Nonetheless, I’m open to recommendations…

Mp3tag is a powerful and yet easy-to-use tool to edit metadata of common audio formats where it supports ID3v1, ID3v2.3, ID3v2.4, iTunes MP4, WMA, Vorbis Comments and APE Tags.

It can rename files based on the tag information, replace characters or words in tags and filenames, import/export tag information, create playlists and more.

I’ve been writing about MP3 in this blog. If you’re interested, you can check past posts here

As I commented above, to refresh my mind I tend to look for this post I wrote some time ago: More MP3 guessing pattern with Mp3tag in Mac OS but I decided to compile future endeavors in this area in a single post. I hope you enjoy.

This time I’m using Mp3tag in the Windows 8 side inside a Parallels Desktop virtual machine.

OK. After some formalities, let’s complete these five basic steps needed in every use case I’ll present in this post:

1 - Click the change directory button and navigate to the folder where you store the MP3s you want to edit.

Mp3tag Change Directory button

2 - Select the files you want to edit. I just press Ctrl + A to select all the files. You can also hold Ctrl to select file by file.

3 - Click the Actions (Quick) button.

Mp3tag Actions (Quick) button

4 - Follow the use cases…

Removing year between parenthesis from file name

Guessing values for Artist and Title from file name

5 - DO NOT FORGET to click the Save button after executing the actions of each use case so that the changes get applied to the files; otherwise you’ll lose the edits. Confused smile

Mp3tag Save button

Use cases

Removing year between parenthesis from file name

Mp3tag Filename with Year between parenthesis

After clicking the Actions button, select Replace with regular expression, select the _FILENAME field and enter the regular expression \( 2o12 \). Press OK and you’re done:

Mp3tag File name with Year between parenthesis regex

Guessing values for Artist and Title from File name

Mp3tag Guess Values for Artist and Title from File name

As you see the MP3 files don’t have Artist and Title information. This is bad. If you use services like Last.fm to keep track of the music you’ve been listening to, you won’t be able to scrobble given the missing metadata. Of course you can fill the info by hand (Oh Lord! How boring and time consuming this task is). There’s Mp3tag to the rescue.

Taking the previous use case as a necessary step to format the file name accordingly…

After clicking the Actions button, select Guess values, in Source format enter %_filename%, in Guessing pattern enter \%artist% - %title%. Press OK and you’re done:

Mp3tag Guess Values for Artist and Title from File name regex

References

MP3 Tag - The Universal Tag Editor Help pages

Extract GPS coord from Google Maps to geotag photos

This is a quick tip related to something that I just tried today and that worked.

My camera SONY DSC-HX100V has GPS capability built-in but it won't work everywhere and it needs some time to acquire the satellite signal. This way if you just want to take a quick snap you may end with photos that don’t have GPS location in their Exif metadata. GPS is a recent capability when we talk about cameras.

SONY DSC-HX100V camera with built-in GPSFigure 1 - SONY DSC-HX100V camera with built-in GPS

Taking that into consideration, let’s say you have some photos in iPhoto (Mac OS) or whatever program you use to manage your photos. I mention iPhoto here since it’s the app I use. Those photos don't have a location set due to no GPS signal available where the photos were taken. So how can one add that missing GPS location info/data on those photos? By the way, this process is called geotagging.

This is what I’ve tried and what worked perfectly in my case:

1 - Open Google Maps and find the place/point where you’ve taken the photos.

2 - Right click that place/point you want in the map and select Center Map here.

3 - Click the Link button. Black mouse pointer is over it in the screenshot bellow.

Google Maps link popup box with URL that contains GPS coordinatesFigure 2 - Google Maps link popup box with URL that contains GPS coordinates

A popup box will open. Copy the text/URL and paste it in your preferred text editor app. The link will look something like this:

http://maps.google.com/maps/ms?msid=201266260819946046546.0004a0e1b939dec67f18e&msa=0&ll=-22.428568,-44.619633&spn=0.001983,0.004128

Pay attention to the highlighted part that correspond to the longitude and latitude data.

4 - Select the photos you want in iPhoto to apply Location information and press command+I to access the Assign a Place box. Copy the highlighted text above and paste it in the box. Press the enter key to finish the task.

Adding GPS coordinates to iPhoto Assign a Place boxFigure 3 - Adding GPS coordinates to iPhoto Assign a Place box

This procedure works great when you just want to add GPS coordinates in your photos no matter if your camera has a built-in GPS or not since any photo can be geotagged nowadays.

Hope it helps!

You can check my photos in this slideshow:

More MP3 guessing pattern with Mp3tag in Mac OS

I mentioned in my last MP3 series post that I had the material to write a new post regarding this topic and so today I’m fulfilling the promise I made. I’m going to show how you can use the powerful Swiss Army knife called Mp3tag (Windows “only” app) right within your Mac. Yes, you read it right. You can run Mp3tag using your Mac. Nowadays almost everything is possible… Open-mouthed smile

The great thing here is that there’s a way to use our beloved Mp3tag in Mac OS. I even asked a question at SuperUser where I was trying to find some similar software that I could use in Mac. Here’s the question: Alternative to mp3tag for Mac OS X. Well, after searching a little bit more I found a great site called PlayOnMac. What is PlayOnMac?

PlayOnMac is like wineskin, winebottler or crossover a piece of software which allows you to easily install and use in your Mac numerous games and software designed to run only with Microsoft®'s Windows®.

I then found Mp3tag bundle here. You get a .dmg file which contains Mp3 Tag.app (172.5 MB) on disk. Just mount the .dmg file with a double click and extract the .app file to your Applications folder in Mac OS dock. Doing this you have the power of Mp3tag right inside your Mac. No Windows virtual machine needed/no need to load your bootcamp Windows. It’s good because you’ll have more memory left for your Mac (in the case of a virtual machine) or you won’t spend your time changing the operating system (in the bootcamp case).

Ok, the bundle is a little bit lazy to load and the visual (retro) is Windows like but who mind?

There’s nothing better than a use case to showcase something. Today I need to organize some MP3 tags because their Track - Artist - Title fields are all a complete mess. Some data are already there and some are missing completely. I of course will use Mp3tag guessing pattern feature to solve this.

To get to the Guess values dialog window, click the Actions (Quick) icon in the toolbar and select Guess values in the dropdown menu. Screenshots can be seen here.

Here are the MP3 files before the process:

Mp3tag Guess Values for Track Artist and Title in FileName [ before ]Figure 1 - Mp3tag Guess Values Window for Track Artist and Title in File Name [ before ]

As you see most of the tracks have 1 in the Track field and Title and Artist fields are missing in most of cases. All the information that is missing is present in the Filename field. Really interesting fact.

Let’s take advantage of Filename info and fill the missing tags with that data. How? Using Mp3tag Guess values window.

Source format: %_filename%

Guessing pattern: %track% - %artist% - %title%

Really easy, isn’t it?

What the hell these % symbols are doing here? They are simple placeholders that tell Mp3tag about a specific pattern found in fields of MP3 files. In this specific case, Mp3tag will extract data from the Filename field ( source ). Looking at Figure 1 we see that all file names follow a pattern: Track # - Artist - Title. Such pattern is then passed to Mp3tag in the Guessing pattern field. With this input Mp3tag is able to infer/parse the file names and split them accordingly. Each part will then be used to fill the correct MP3 tags.

Here’s the post-processed MP3 files:

Mp3tag Guess Values Window for Track Artist and Title in File Name [ after ] Figure 2 - Mp3tag Guess Values Window for Track Artist and Title in File Name [ after ]

That’s a much better view and experience within your preferred Media Library software!

Things like this makes me really happy with computers…

Hope you find it as useful as it’s being to me in this hard task of keeping a MP3 collection organized. I at least try my best.

To see more ways of using the Guessing Pattern, check the MP3 series of posts.

Software to add Lyrics to MP3 files ID3 metadata

Take a look at the MP3 series. Probably you’ll find something interesting.

If you're like me, you also like to take a look at the lyrics of music that is currently playing in your computer or mobile device as the iPhone. I do it to learn a bit more of English since its not my main language and of course because I also want to sing along correctly. :)

The iPhone for example allows you to read the lyrics of the current song if the lyrics are present in the MP3 ID3 metadata container. This is pretty cool. If you already have lyrics embedded in your MP3 files you can see them while in a bus trip, waiting for a service, etc.

Every MP3 has a specific field (also know as frame) in its metadata to store lyrics information. It’s just a matter of filling this field with the correct lyrics. This is a hard work to do manually because you have to search for the lyrics and then copy/paste it in the right field. This sounds like a great thing to be done by software instead. Again, that’s what computers are for… save us time.

In iTunes (the media player/library software I use) for example, one would right-click a music file and then select the Get Info context menu option. Then you’d select the Lyrics tab and paste the lyrics in the white huge field making sure to click OK as seen in Figure 1 below:

Adding lyrics to an iTunes music file through the Lyrics tab
Figure 1 - Adding lyrics to an iTunes music file through the Lyrics tab

Some time ago I asked a question at SuperUser site: Software to add Lyrics to MP3 files ID3 metadata. It seems that there are a lot of people (3,356 to be precise as the time of this post) out there looking to accomplish what this post tries to clarify.

When I asked the question I was using Windows and I got good answers.

I also discovered other software by myself as MiniLyrics for Windows at that time. If you’re interested in MiniLyrics, here goes a small tutorial to save the lyrics to MP3 metadata!

MiniLyrics
Right click MiniLyrics icon in the system tray, choose Preferences and then select the Lyrics icon. Under the Save downloaded lyrics in: - select Save lyrics in mp3 file.

Other great feature MiniLyrics has is that while the music is playing the lyrics can be shown on your screen according to what is being sung, that is, the lyrics flows in your screen according to the music timing. Fantastic job from crintsoft people... :)

Besides saving the lyrics to MP3 metadata, there are lots of features and possibilities when it comes to lyrics in MiniLyrics software.

From the official site:

    MiniLyrics Display lyrics for your favorite music!

        * Lyrics plugin software for iTunes, Windows Media Player, MediaMonkey, Winamp, etc. You do not need to change the way you enjoy music.
        * Display scrolling lyrics, you can follow along with the artist and catch every word.
        * Automatically search and download lyrics.
        * Huge lyrics database, and it is expanding everyday.
        * Free Trial version that never expires.

Lyricator
Lyricator as suggested by merv is a fantastic/great/cool piece of software to go with MediaMonkey but it is having some problems currently as you can find in this thread.

I had to resort to other service while Lyricator is being repaired. I found other free software that does the job, but only on a Mac computer (that’s OK because I’ve switched to the Mac world). It's name is Get Lyrical.

Get Lyrical

Get Lyrical doing its job in the background
Figure 2 - Get Lyrical doing its job in the background

    Get Lyrical auto-magically add lyrics to songs in iTunes!

You can choose either a selection of tracks, or the current track. Or turn on "Active Tagging" to get lyrics for songs as you play them.

    You can also browse and edit the lyrics of your iTunes tracks right from Get Lyrical.

I highlighted in yellow above a powerful feature of Get Lyrical. You can even add lyrics to a selection of tracks at once. This is a batch processing feature really welcome when you want to add lyrics to an artist’s complete discography for example.

I’ve been using Get Lyrical for some time now and it is really competent in the job. I highly recommend it.

Manipulating Properties and Methods with Reflection

Today I’m going to write about a simple yet powerful way to manipulate properties and methods of a given type. We’ll set values to properties and invoke methods through the use of reflection.

Maybe you haven’t had the chance to use reflection or maybe you even don’t know what is reflection.

Reflection is one of the most powerful features a programming language has as is the case of C# programming language that I’ll be using in this post.

In just one phrase extracted from Wikipedia we can define what is reflection:

Reflection is the process by which a computer program can observe and modify its own structure and behavior. The programming paradigm driven by reflection is called reflective programming.

Our objective is to manipulate the property value and methods of a type by means of reflection, that is, we’ll have access to these properties and methods by looking at the type’s metadata.

Let’s exemplify with a specific case that I came into while I was working on my first project at Chemtech: we had our ASP.NET solution divided into specific projects in what we call the MVP pattern. I suggest that you to read the post Model View Presenter pattern with Castle in ASP.NET to get a grasp of it.

In a given task I had 15 static textboxes inside an .aspx page (View) and I needed to set their values inside the Presenter. What is the best way to do it? Should you hardcode each and every textbox setting their values? It’s not an elegant solution. So how to get over it? Using reflection to get the type’s metadata. Let’s see how it is easy.

Let’s get to the code:

private void BindProperty(string viewPropertyName, object propertyValue)
{
    // Getting the property I want to use.
    PropertyInfo propertyInfo = typeof(IMyView).GetProperty(viewPropertyName);

    // Verifying if the property was acquired with success.
    if (propertyInfo != null && propertyInfo.CanWrite)
    {
        // Set the property value.
        propertyInfo.SetValue(view, propertyValue, null);
    }
}

Reflection allows us to make a generic piece of code, that is, with only one method we can set the value of all the textboxes.

The above method receives the property name as a parameter and we also pass to the method the value we want to assign to the property.

This same approach can be used with methods. Let’s see an example:

private void BindMethod(string viewMethodName, object[] methodParameters)
{
    // Getting the method I want to use.
    MethodInfo methodInfo = typeof(IMyView).GetMethod(viewMethodName);

    if (methodInfo !=null)
    {
// Call/Invoke the method with the desired parameters. methodInfo.Invoke(view, methodParameters); } }

Again we have a generic piece of code that can be used to call whatever method we want passing whatever parameters we want.

To use PropertyInfo and MethodInfo we declare the namespace System.Reflection.

We could make these methods even more generic by passing the view object (type) we want as a parameter. Bellow I show a class named ReflectionUtil with such modifications:

/// <summary>
/// Utility class for Reflection operations.
/// </summary>
public class ReflectionUtil
{
    /// <summary>
    /// Sets a value to a property through the use of Reflection.
    /// </summary>
    /// <param name="obj">Object that owns the property</param>
    /// <param name="propertyName">Property name</param>
    /// <param name="propertyValue">Value to be set</param>
    public static void BindProperty(object obj, string propertyName, object propertyValue)
    {
        // Getting the property I want to use.
        PropertyInfo propertyInfo = obj.GetType().GetProperty(propertyName);

        // Verifying if the property was acquired with success.
        if (propertyInfo != null && propertyInfo.CanWrite)
        {
            // Set the property value.
            propertyInfo.SetValue(obj, propertyValue, null);
        }
    }

    /// <summary>
    /// Calls a method through the use of Reflection.
    /// </summary>
    /// <param name="obj">Object that owns the method</param>
    /// <param name="methodName">Method name</param>
    /// <param name="methodParameters">Method parameters</param>
    public static void BindMethod(object obj, string methodName, object[] methodParameters)
    {
        // Getting the method I want to use.
        MethodInfo methodInfo = obj.GetType().GetMethod(methodName);

        if (methodInfo != null)
        {
// Call/Invoke the method with the desired parameters. methodInfo.Invoke(obj, methodParameters); } } }

OK. Now that we have the methods defined, let’s use them.

I’ll use the application I’ve shown in Model View Presenter pattern with Castle in ASP.NET as the base for this post.

IMyView interface declares the following members:

public interface IMyView : IBaseView
{
    event EventHandler FirstLoading;

    void MyMethod();

    string TextBox1Text { set; }
    string TextBox2Text { set; }
    string TextBox3Text { set; }
    string TextBox4Text { set; }
    string TextBox5Text { set; }
    string TextBox6Text { set; }
    string TextBox7Text { set; }
    string TextBox8Text { set; }
    string TextBox9Text { set; }
    string TextBox10Text { set; }

    void FillGridView1(List<object> values);
    void FillGridView2(List<object> values);
}

MyView implements what’s in IMyView interface:

public partial class MyView : Page, IMyView
{
    private MyPresenter presenter;

    .
.
.
#region Implementation of IMyView public event EventHandler FirstLoading; public void MyMethod() { Response.Write("Reflection power"); } #region TextBoxes public string TextBox1Text { set { TextBox1.Text = value; } } public string TextBox2Text { set { TextBox2.Text = value; } }

.
.
. #endregion #region Methods public void FillGridView1(List<object> values) { GridView1.DataSource = values; GridView1.DataBind(); } public void FillGridView2(List<object> values) { GridView2.DataSource = values; GridView2.DataBind(); } #endregion #endregion }

Inside the Presenter MyPresenter I implement the logic with the following:

/// <summary>
/// Specific FirstLoading implemented by each inheritor
/// </summary>
protected override void FirstLoading()
{
    view.MyMethod();

    // Useful technique to avoid calling 10 lines of code.
    for (int i = 1; i <= 10; i++)
    {
        ReflectionUtil.BindProperty(view, string.Format("TextBox{0}Text", i), (i * i).ToString());
    }

    // Useful technique to avoid writing methods almost identical just to change a method call.
    for (int i = 1; i <= 2; i++)
    {
        // Do some common logic here...

        // Call a specific method with Reflection.
ReflectionUtil.BindMethod(view, string.Format("FillGridView{0}", i), new object[] { new List<object> { i * 2, i * 3, i * 4, i * 5 } }); // Do some common logic here... } }

When we run the web app, we get the following result:

Reflection result

I covered just a simple use case of reflection in this post but it’s useful in our day to day job.

The technique implemented in this post allows us to write clean and generic code. I have already used it in another project which allowed me to write as few lines of code as possible. Let’s say it decreased from 250 sloc to 25 sloc. A reduction of 10 times sloc.

Last note
I read the article Survival of the Fittest: Natural Selection with Windows Forms on MSDN Magazine when I was on the 9th period of the Computer Engineering course studying Artificial Intelligence. From this moment on I started to visualize the importance of reflection and how powerful it is. The referenced article discusses about Genetic Algorithms and the author’s sample code makes extensive use of reflection. Great read if you’re interested enough! Oh, I even translated this article to Portuguese at that time. I want to put it online so that others can benefit from it. :o)

Visual Studio 2010 C# ASP.NET Web Application
You can get the Microsoft Visual Studio Project at:

http://sites.google.com/site/leniel/blog/ReflectionWebApp.zip

To try out the code you can use the free Microsoft Visual Web Developer 2010 Express Edition that you can get at: http://www.microsoft.com/express/Web/

Mp3tag to batch process/edit MP3 tags

It’s always good to keep things organized even more when it comes to MP3 files. If you use to listen to MP3 music you know what I’m talking about.

I keep a timeline of music I listen to at Last.fm. Last.fm tries to help us correcting wrong MP3 tags, but corrections are only visible online and they don’t change MP3 metadata, that is, you still have wrongly tagged MP3 residing in your music library.

To overcome such situation I started looking for a piece of software that could resolve this misinformation. I got to know a free yet powerful small application called Mp3tag that allows the execution of various commands against MP3 metadata.

Excerpting from the official site:

Mp3tag is a powerful and yet easy-to-use tool to edit metadata of common audio formats where it supports ID3v1, ID3v2.3, ID3v2.4, iTunes MP4, WMA, Vorbis Comments and APE Tags.

It can rename files based on the tag information, replace characters or words in tags and filenames, import/export tag information, create playlists and more.

Mp3tag supports online database lookups from, e.g., Amazon, discogs, or freedb, allowing you to automatically gather proper tags and cover art for your music library.

One of the best features of Mp3tag is the Actions menu button that let’s you replace text within any MP3 tag field using simple find and replace or more advanced regular expressions. The following figure shows the options available:

Figure 1 – Options available through the Actions menu button
Figure 1 – Options available through the Actions menu button

I’ll briefly show how to edit the Title of some files all at once - what is known as batch processing.

I’ll remove with only one command (action) the text “ - TO BE REMOVED” that is part of the Title tag of 10 MP3 files:

Figure 2 – Mp3tag listing 10 MP3 files before the batch processing
Figure 2 – Mp3tag listing 10 MP3 files before the batch processing

Click on the Action menu button (mouse pointer is over it in the following picture) and select the action type as Replace and click OK:

Figure 3 – Mp3tag action type selection
Figure 3 – Mp3tag action type selection

Now select the MP3 tag field you’d like to change. In this case I’m going to modify the content of the Title tag field. Enter the text “ - TO BE REMOVED” inside the Original field. As I want to remove the text I’ll let the Replace with field blank/empty.

Figure 4 – Mp3tag Replace action window
Figure 4 – Mp3tag Replace action window

Click OK and voila:

Figure 5 – Mp3tag listing 10 MP3 files after the batch processing
Figure 5 – Mp3tag listing 10 MP3 files after the batch processing

Now you know where to look for a versatile MP3 tag editor. It comes to the rescue allowing you to avoid spending your time editing MP3 by MP3. You can do lots of things related to MP3 metadata. You can batch process all your MP3 with only one action easy as pie.

It would be good if popular media players as Windows Media Player, iTunes, etc could let us do things like this simple task I demonstrated in this post. Maybe someday they will. I hope.

References
Mp3tag online Help
Mp3tag group at Last.fm
Mp3tag at Twitter