From 6067fa7d0c3efc2fb3dccfbba3f4bc05cd83f79f Mon Sep 17 00:00:00 2001 From: Zhong Yang Date: Wed, 2 Sep 2020 12:58:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Eaiff=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E4=B8=93=E8=BE=91=E5=B0=81=E9=9D=A2=E7=9A=84=E8=AF=BB=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MusicPlayer2/AudioTag.cpp | 7 +++++-- MusicPlayer2/TagLibHelper.cpp | 30 ++++++++++++++++++++++++++++++ MusicPlayer2/TagLibHelper.h | 2 ++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/MusicPlayer2/AudioTag.cpp b/MusicPlayer2/AudioTag.cpp index 7f5b6d96..78a60800 100644 --- a/MusicPlayer2/AudioTag.cpp +++ b/MusicPlayer2/AudioTag.cpp @@ -130,6 +130,9 @@ wstring CAudioTag::GetAlbumCover(int & image_type, wchar_t* file_name, size_t* f case AU_SPX: image_contents = CTagLibHelper::GetSpxAlbumCover(m_song_info.file_path, image_type); break; + case AU_AIFF: + image_contents = CTagLibHelper::GetAiffAlbumCover(m_song_info.file_path, image_type); + break; case AU_CUE: break; case AU_MIDI: @@ -245,7 +248,7 @@ bool CAudioTag::WriteAlbumCover(const wstring & album_cover_path) case AU_APE: return CTagLibHelper::WriteApeAlbumCover(m_song_info.file_path, album_cover_path); case AU_AIFF: - break; + return CTagLibHelper::WriteAiffAlbumCover(m_song_info.file_path, album_cover_path); case AU_FLAC: return CTagLibHelper::WriteFlacAlbumCover(m_song_info.file_path, album_cover_path); case AU_WAV: @@ -285,6 +288,6 @@ bool CAudioTag::IsFileTypeCoverWriteSupport(const wstring& ext) CCommon::StringTransform(_ext, false); AudioType type = CAudioCommon::GetAudioTypeByFileExtension(_ext); return type == AU_MP3 || type == AU_FLAC || type == AU_MP4 || type == AU_WMA_ASF || type == AU_WAV || type == AU_APE - || type == AU_OGG || type == AU_OPUS || type == AU_SPX; + || type == AU_OGG || type == AU_OPUS || type == AU_SPX || type == AU_AIFF; } diff --git a/MusicPlayer2/TagLibHelper.cpp b/MusicPlayer2/TagLibHelper.cpp index 9c5b5b3e..c26e023b 100644 --- a/MusicPlayer2/TagLibHelper.cpp +++ b/MusicPlayer2/TagLibHelper.cpp @@ -408,6 +408,16 @@ string CTagLibHelper::GetSpxAlbumCover(const wstring& file_path, int& type) return cover_contents; } +string CTagLibHelper::GetAiffAlbumCover(const wstring& file_path, int& type) +{ + string cover_contents; + RIFF::AIFF::File file(file_path.c_str()); + auto id3v2 = file.tag(); + GetId3v2AlbumCover(id3v2, cover_contents, type); + return cover_contents; + +} + void CTagLibHelper::GetFlacTagInfo(SongInfo& song_info) { FLAC::File file(song_info.file_path.c_str()); @@ -870,6 +880,26 @@ bool CTagLibHelper::WriteSpxAlbumCover(const wstring& file_path, const wstring& return false; } +bool CTagLibHelper::WriteAiffAlbumCover(const wstring& file_path, const wstring& album_cover_path, bool remove_exist /*= true*/) +{ + RIFF::AIFF::File file(file_path.c_str()); + if (!file.isValid()) + return false; + + //先删除专辑封面 + auto id3v2tag = file.tag(); + if (remove_exist) + { + DeleteId3v2AlbumCover(id3v2tag); + } + if (!album_cover_path.empty()) + { + WriteId3v2AlbumCover(id3v2tag, album_cover_path); + } + bool saved = file.save(); + return saved; +} + bool CTagLibHelper::WriteMpegTag(SongInfo & song_info) { MPEG::File file(song_info.file_path.c_str()); diff --git a/MusicPlayer2/TagLibHelper.h b/MusicPlayer2/TagLibHelper.h index 3f872d95..f4ead7a5 100644 --- a/MusicPlayer2/TagLibHelper.h +++ b/MusicPlayer2/TagLibHelper.h @@ -19,6 +19,7 @@ public: static string GetOggAlbumCover(const wstring& file_path, int& type); static string GetOpusAlbumCover(const wstring& file_path, int& type); static string GetSpxAlbumCover(const wstring& file_path, int& type); + static string GetAiffAlbumCover(const wstring& file_path, int& type); //读标签信息 static void GetFlacTagInfo(SongInfo& song_info); @@ -54,6 +55,7 @@ public: static bool WriteOggAlbumCover(const wstring& file_path, const wstring& album_cover_path, bool remove_exist = true); static bool WriteOpusAlbumCover(const wstring& file_path, const wstring& album_cover_path, bool remove_exist = true); static bool WriteSpxAlbumCover(const wstring& file_path, const wstring& album_cover_path, bool remove_exist = true); + static bool WriteAiffAlbumCover(const wstring& file_path, const wstring& album_cover_path, bool remove_exist = true); //写标签信息 static bool WriteMpegTag(SongInfo& song_info);