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; }
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; }
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; }
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; }