Example #1
0
bool WriteTag(const musik::Core::SongInfo& info)
{
    WmaMetadataEditor editor(info.GetFilename().c_str());

    if (editor.IsValid())
    {
        try
        {
            TRY_SET_STRING_ATTRIBUTE(g_wszWMAlbumArtist, info.GetArtist().c_str());
            TRY_SET_STRING_ATTRIBUTE(g_wszWMAuthor, info.GetArtist().c_str());
            TRY_SET_STRING_ATTRIBUTE(g_wszWMAlbumTitle, info.GetAlbum().c_str());
            TRY_SET_STRING_ATTRIBUTE(g_wszWMTitle, info.GetTitle().c_str());
            TRY_SET_STRING_ATTRIBUTE(g_wszWMGenre, info.GetGenre().c_str());
            TRY_SET_STRING_ATTRIBUTE(g_wszWMYear, info.GetYear().c_str());
            TRY_SET_STRING_ATTRIBUTE(g_wszWMTrackNumber, info.GetTrackNum().c_str());
            TRY_SET_STRING_ATTRIBUTE(g_wszWMDescription, info.GetNotes().c_str());

            return editor.Write();
        }
        catch(...)
        {
            std::wstring error = L"Caught unhandled exception while writing WMA file: " + info.GetFilename();
            ::OutputDebugString(error.c_str());
        }
    }

    return false;
}
Example #2
0
bool WriteTag(const musik::Core::SongInfo& info)
{
    bool ret = true;

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

            tag->setArtist(info.GetArtist().c_str());
            tag->setAlbum(info.GetAlbum().c_str());
            tag->setTitle(info.GetTitle().c_str());
            tag->setGenre(info.GetGenre().c_str());
            tag->setYear(musik::Core::StringToInt(info.GetYear()));
            tag->setTrack(musik::Core::StringToInt(info.GetTrackNum()));
            tag->setComment(info.GetNotes().c_str());

            tag_file.save();
        }
    }
    catch (...)
    {
        ret = false;
        cout << "taglib crashed trying to write: " << info.GetFilename().c_str() << endl;
    }

    return ret;
}