Example #1
0
bool ReadTag(const musik::Core::String& fn, musik::Core::SongInfo& target)
{
    bool ret = true;

    musik::Core::Filename mfn(fn);

    target.SetFilename(fn);
    target.SetFormat("Ogg Vorbis");

    try
    {
#if defined (WIN32)
        TagLib::FileRef tag_file(fn.c_str());
#else    
        TagLib::FileRef tag_file(utf16to8(fn, true).c_str());
#endif
        if (!tag_file.isNull())
        {
            if (tag_file.tag())
            {
                TagLib::Tag *tag = tag_file.tag();        

                target.SetArtist(musik::Core::utf8to16(tag->artist().to8Bit(true)));
                target.SetAlbum(musik::Core::utf8to16(tag->album().to8Bit(true)));
                target.SetTitle(musik::Core::utf8to16(tag->title().to8Bit(true)));
                target.SetGenre(musik::Core::utf8to16(tag->genre().to8Bit(true)));
                target.SetNotes(musik::Core::utf8to16(tag->comment().to8Bit(true)));

                target.SetYear(musik::Core::IntToString(tag->year()));
                target.SetTrackNum(musik::Core::IntToString(tag->track()));
            }

            if (tag_file.audioProperties())
            {
                TagLib::AudioProperties *properties = tag_file.audioProperties();
                int duration = properties->length() * 1000;
                target.SetBitrate(musik::Core::IntToString(properties->bitrate()));
                target.SetDuration(musik::Core::IntToString(duration));
            }
        }

        // if the title is empty, then use the
        // filename...
        if (target.GetTitle().IsEmpty())
        {
            musik::Core::Filename MFN(fn);
            target.SetTitle(MFN.GetJustFilename());
        }
    }
    catch (...)
    {
        ret = false;
        cout << "taglib crashed reading: " << fn.c_str() << endl;
    }

    return ret;
}
Example #2
0
bool ReadTag(const musik::Core::String& fn, musik::Core::SongInfo& target)
{
    WmaMetadataEditor editor(fn.c_str());

    if (editor.IsValid())
    {
        try
        {
            target.SetArtist(editor.GetStrAttribute(g_wszWMAlbumArtist));

            if (target.GetArtist() == L"")
            {
                target.SetArtist(editor.GetStrAttribute(g_wszWMAuthor));
            }

            target.SetAlbum(editor.GetStrAttribute(g_wszWMAlbumTitle));
            target.SetTitle(editor.GetStrAttribute(g_wszWMTitle));
            target.SetGenre(editor.GetStrAttribute(g_wszWMGenre));
            target.SetYear(editor.GetStrAttribute(g_wszWMYear));
            target.SetNotes(editor.GetStrAttribute(g_wszWMDescription));

            // track number can be stored as an int OR a string!
            //
            // also: it appears track numbers are stored 0 based if they
            // are stored as strings?
            //
            std::wstring strTrackNum = editor.GetStrAttribute(g_wszWMTrackNumber);
            int trackNum = musik::Core::StringToInt(strTrackNum);
            //
            if (trackNum <= 0)
            {
                target.SetTrackNum(musik::Core::IntToString(
                    editor.GetDWORDAttribute(g_wszWMTrackNumber) + 1));
            }
            else
            {
                target.SetTrackNum(musik::Core::IntToString(trackNum));
            }

            target.SetBitrate(musik::Core::IntToString(
                editor.GetDWORDAttribute(g_wszWMBitrate) / 1000));
            //
            target.SetDuration(musik::Core::IntToString(
                editor.GetDWORDAttribute(g_wszWMDuration) / 10000));

            // if the title is empty, then use the
            // filename...
            if (target.GetTitle().IsEmpty())
            {
                musik::Core::Filename MFN(fn);
                target.SetTitle(MFN.GetJustFilename());
            }

            target.SetFormat("Windows Media Audio");

            return true;
        }
        catch(...)
        {
            std::wstring error = L"Caught unhandled exception while reading WMA file: " + fn;
            ::OutputDebugString(error.c_str());
        }
    }

    return false;
}