Scott Hanselman

Automating Adding iTunes Album Art to MP3 ID3 tags from the Command Line in C#

April 17, '07 Comments [6] Posted in Podcast | Programming | Tools
Sponsored By

It's been bugging me that the album art for my podcast doesn't appear in Windows Media Player, iTunes, or in iPods.

I assumed, incorrectly, that this was an iTunes meta-tagging problem, but then I realized that this was an MP3 problem, not an AAC or WMA problem, although both formats support adding art to the file.

The ID3 format is pretty extensive. You can put a great deal of meta-information into an MP3. The Attached picture or APIC "Frame" in ID lets you embed in PNGs or JPGs, along with their respective mime/types. 

I googled around over lunch and couldn't find a simple, free, command-line program that would let me easily add pictures to not only the existing MP3s for our show on the server-side, but also could be integrated into our existing audio file production workflow.

I ended up finding this great little library from 2004 called the tagnetlib project source was offered for free from the Nancy Street Blog. I converted it to .NET 2.0.

Now, note that the tagnetlib project is currently deprecated in lieu of the NTag product that Greg Keogh started in 2005 and released in May of 2006. The NTag project is much more interesting and appears to be well thought-out. He intends to support WMA and OGG and turn the project info a "Meta Tag Tagging" project that would support all popular audio formats.

I used the Tagnetlib because it was quick, incredibly easy, and I only had my lunch hour to do this. However, he's pretty clear that Tagnetlib is, again, totally deprecated and unsupported. Perhaps one day I'll get to spend more time with the NTag library. For now, my little hack is used like this:

embedid3.exe file.mp3 file.jpg [optionally "mime/type", default is "image/jpeg"]

Disclaimer: This app does one thing. It adds images to MP3 files that don't have them. It has no error handling or checking and it doesn't care about you or your MP3 collection. Don't even think about running it over your collection or using it for any purpose. It's useful for one thing. It's useful to me. Your Mileage WILL Vary. You have been warned.

Do make sure you checkout NTag and what Greg's working on over there. It's really pretty fun code to read.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Expose and Vista-specific Alt-Tab Task Switchers

April 17, '07 Comments [11] Posted in Reviews | Tools
Sponsored By

I love the Exposé feature of Mac OSX. On Windows XP I ran TopDesk, an Exposé clone for a few years. Now that I'm on Vista and I find Flip3D to be a virtually useless way to switch tasks, I'm looking for a better task switcher again. I hope TopDesk jumps back into the party with new DWM support for Vista.

I still like TaskSwitchXP, but it's needed less with Vista's default ALT-TAB behavior.

When Vista runs Aero, the new Desktop Composition Engine, the possibilities for new Task Switchers becomes virtually unlimited. Early entries into the fray include:

  • My Exposé (Source Available!)- Released a CTP last November, and he's meaning to get a new one out, but has been busy. It's a LOT like Mac Exposé but it's got a LOT of screen-flickering and doesn't work well when your secondary monitor is taller (has coordinates ABOVE) than the primary monitor. Still, it's working good considering it was written BEFORE Vista RTM'ed
  • Switcher (Switcher Blog)- I was initially disappointed by this Task Switcher because its default mode is a strange "dock all running thumbnails to the top of the screen" place. And, there's no initial animation or transition. Then, I RTFM'ed, and noticed that you can switch between "dock" mode and "Exposé" mode using Page Down. Doh! After that, the choice is ssticky and you have the best Exposé in Vista I've seen. Brilliant and recommended. I hope he keeps developing it. I'm definitely using this one all day long.

With these two apps to choose from, and more, no doubt, on the way, the micro-market of Task Switching Software for Vista is looking pretty sweet.

If you're not sure if your TaskSwitcher is really using the Vista Aero DesktopComposition Engine, do a little test. Find a web page with a video or animated graphic or flash. Do a task switch and while in that "task switching mode" see if the animation is running inside the thumbnail. If it is, and running smoothly, that TaskSwitcher is using the DWM rather than static screenshots.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

XmlSerializing a Generic List<>

April 17, '07 Comments [10] Posted in Programming | XmlSerializer
Sponsored By

There's lots of good techniques out there for using the XmlSerializer to serialize a Generic List<> type. You can implement IXmlSerializable and some other trickiness.

Here's the simplest possible thing I could do to make it work while working on a hobby project over lunch today with a friend.

UPDATE: I'm a dork and didn't see the forest for the trees on this one. I don't need a parallel array at all. That's my old 1.1 brain creeping in. Thanks to folks in the comments. It works fine just like this. I'm not sure why I thought it didn't work when I tried it before. Thanks folks!

namespace Poo
{
    public class Foo
    {
        public Foo() { FooReadings = new List(); }

        [XmlArray("FooReadings")] //Even this attribute isn't really needed if you accept the default.
public List<FooReading> FooReadings; } public class FooReading { public FooReading() { } public FooReading(DateTime date, decimal thing2) { this.Thing2 = thing2; this.Date = date; } public decimal Thing2; public DateTime Date; } }

The technique below is useful for other things, but not in this instance.

namespace Poo
{
    public class Foo
    {
        public Foo() { FooReadings = new List(); }

        [XmlIgnore]
        public List<FooReading> FooReadings;

        [XmlArray("FooReadings")]
        public FooReading[] ArrayFooReadings
        {
            get { return FooReadings.ToArray(); }
            set { FooReadings = new List(value); }
        }
    }

    public class FooReading
    {
        public FooReading() { }

        public FooReading(DateTime date, decimal thing2)
        {
            this.Thing2 = thing2;
            this.Date = date;
        }

        public decimal Thing2;
        public DateTime Date;
    }
}

The "Real List<>" is ignored and the "fake" one is presented as an Array in the Getters/Setter. Not pretty, to be sure.

What better ways are there that you prefer?

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Speeding up a Slow Outlook 2007

April 15, '07 Comments [10] Posted in Tools
Sponsored By

Outlook 2007 has been pretty slow for me since I installed it. If you've got RSS Feeds Enabled and/or if you're a packrat, Outlook 2007 can be a downright performance pig. I've got internal contacts that say that the Office team is hot on the tail of a number of really interesting issues.

What can you do today? A patch KB933493 went live yesterday to help speed up access to large PSTs and OSTs. For now, you have to go get it. We'll see what the future holds for this, but I suspect that Office SP1, whenever it comes out, is going to be a very snappy performer.

Initial reports on this patch are positive. Searches are faster, Undos are faster, moving messages is faster, and moving quickly while reading in the preview pane is faster. The future bright on this one...I was really starting to get bummed about Outlook's performance.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Custom Cultures - WinForms Font Embedding Code with Ethiopian Amharic for Vista and XP

April 14, '07 Comments [4] Posted in Africa | Internationalization
Sponsored By

Even though my wife is Ndebele (Zulu) and we are trying to teach Z that particular Bantu Language, my first Linguistic African Love was Ethiopian Amharic. I almost majored in this stuff and I actually met my wife while I was speaking Amharic to one of her longtime college friends. Here's a small primer on Amharic I did in 2005 and there's a good basic Amharic Dictionary online here, that will exercise your fonts and mind as well. If you want to hear the languages, there's an Amharic audio dictionary here, or if you know me in person, I'll teach you some. Heck, if you know me, you know that'll be a long conversation because I love this stuff.

If you're running Windows Vista, you already have the Amharic Unicode Font "Nyala" and Input Method Editor installed! You can visit this test page to see that the Amharic support is quite complete on Vista. Here's my name in Amharic: ስካተ. If you aren't running Vista then you'll likely see black squares.

If you're running Vista, try this out. Go to the Control Panel and run the Regional and Language Options. Go to the Keyboards and Languages tab and click Change Keyboards. Don't worry, I won't break anything on your system, promise. Amharic is am-ET, by the way, compared to en-US or en-GB.

Click over to the Language Bar tab and make sure that Docked in the Taskbar or Floating on the Desktop is checked. You'll see your existing culture appear in the Language Bar - mine is in the tray.

Run Notepad, then go back to this menu and click Amharic.

You can always remove this by going BACK to the Control Panel and just Removing the Amharic Language.

While you're in Notepad, you're going to type "Thank You" in Amharic, which is pronounced (roughly) "Amäsägnalähu." Amharic is an "abugida" አቡጊዳ (not quite a syllabary) kind of like Katakana in Japanese, and with most Input Method Editors for languages with a lot of characters that are entered with an English keyboard, there's a mapping. You type and English Transliteration, and the IME gives you possible characters.

Amharic has no official transliteration, so this IME is kind of the standard, but there's always been arguments about the best way to describe the vowels. There are more vowels than in English, including a non-vowel-vowel.

Back to the point. In Notepad, type, using an English Keyboard:

  1. a-downarrow-space (this is a special character, that I can't see how to type without the down-arrow)
  2. m-e
  3. s-e
  4. g-'
  5. n-a
  6. l-e (the "e" is pronounced like "ay," by the way.
  7. h-u-space

You've just typed አመሰግናለሁ (ameseg'nalehu) which is one of the ways to say Thank You in Amharic. If you speak Japanese or another Asian languages you're likely used to using an IME like this. Notice how Notepad's support for Unicode means that it doesn't care about this new languages. It's just rolling with it.

Evil Black Squares

Be sure to know the details in Joel's classic Unicode post if you're doing international work and check out my Internationalization (i18n) Category. This "black square" issue is common when the system doesn't have a font available to render a Unicode code point, and since it's not legal to distribute that Ethiopian Nyala Vista Font outside the operating system by just copying it, how would an Ethiopian write and application and have it work on Windows XP. Surely a company in Ethiopia might want to defer upgrading to Vista (even though it includes all this great support for Amharic, including the custom IME (Input Method Editor)) for a while to save costs. This issue of course, applies to many languages beyond Amharic, and that's why I'm interested.

I've been bugging Michael Kaplan about this for as long as I've known him. It should be easier to create WinForms applications with cultures that don't include as much support as the Asian Languages. Plus, when a new OS like Vista comes out, how can we pass on the benefits to XP?

 At my urging Michael has created a great multi-part series on Font Embedding such that a person could develop on Vista and a downlevel OS could still work - even without the font installed, without violating the EULA.

In the screenshot above, we see a WinForms app running on XP. The OS doesn't have the font, but the font HAS come along for the ride as the app was built on Vista using this Font Embedding Technique.

 This will allow folks to develop Amharic Language (and other language) applications under Windows Vista and run them elsewhere. This is a huge accomplishment, in my opinion. Thanks Michael for your work!

I hope that folks tell Michael and Microsoft that this is a significant business scenario and encourage them to advance Michael's Sample Code into a full-fledge and supported feature in WinForms.

NOTE: You'll have to build the sample on Vista first in order to get the font. To get this sample running on XP, build it on Vista - note the creating of the font .bin file - and then run it on an XP box.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.