xref: /MusicPlayer2/MusicPlayer2/TagLibHelper.h (revision 5a85e7a264ad6ed41734aa73a89d74ca02b54bf5)
1 #pragma once
2 #include "SongInfo.h"
3 #include "taglib/id3v2tag.h"
4 
5 //
6 class CTagLibHelper
7 {
8 public:
9     CTagLibHelper();
10     ~CTagLibHelper();
11 
12     static void SetWriteId3V2_3(bool write_id3v2_3);    //设置是否写入ID3V2.3,否则写入ID2V2.4
13 
14     //读专辑封面
15     static string GetM4aAlbumCover(const wstring& file_path, int& type);
16     static string GetFlacAlbumCover(const wstring& file_path, int& type);
17     static string GetMp3AlbumCover(const wstring& file_path, int& type);
18     static string GetAsfAlbumCover(const wstring& file_path, int& type);
19     static string GetWavAlbumCover(const wstring& file_path, int& type);
20     static string GetTtaAlbumCover(const wstring& file_path, int& type);
21     static string GetApeAlbumCover(const wstring& file_path, int& type);
22     static string GetOggAlbumCover(const wstring& file_path, int& type);
23     static string GetOpusAlbumCover(const wstring& file_path, int& type);
24     static string GetSpxAlbumCover(const wstring& file_path, int& type);
25     static string GetAiffAlbumCover(const wstring& file_path, int& type);
26     static string GetMpcAlbumCover(const wstring& file_path, int& type);
27     static string GetWavePackAlbumCover(const wstring& file_path, int& type);
28 
29     //读标签信息
30     static void GetFlacTagInfo(SongInfo& song_info);
31     static void GetM4aTagInfo(SongInfo& song_info);
32     static void GetMpegTagInfo(SongInfo& song_info);
33     static void GetAsfTagInfo(SongInfo& song_info);
34     static void GetApeTagInfo(SongInfo& song_info);
35     static void GetWavTagInfo(SongInfo& song_info);
36     static void GetOggTagInfo(SongInfo& song_info);
37     static void GetMpcTagInfo(SongInfo& song_info);
38     static void GetOpusTagInfo(SongInfo& song_info);
39     static void GetWavPackTagInfo(SongInfo& song_info);
40     static void GetTtaTagInfo(SongInfo& song_info);
41     static void GetAiffTagInfo(SongInfo& song_info);
42     static void GetSpxTagInfo(SongInfo& song_info);
43 
44     static void GetAnyFileTagInfo(SongInfo& song_info);
45 
46     //读取所有标签属性
47     static void GetFlacPropertyMap(const wstring& file_path, std::map<wstring, wstring>& property_map);
48     static void GetM4aPropertyMap(const wstring& file_path, std::map<wstring, wstring>& property_map);
49     static void GetMpegPropertyMap(const wstring& file_path, std::map<wstring, wstring>& property_map);
50     static void GetAsfPropertyMap(const wstring& file_path, std::map<wstring, wstring>& property_map);
51     static void GetApePropertyMap(const wstring& file_path, std::map<wstring, wstring>& property_map);
52     static void GetWavPropertyMap(const wstring& file_path, std::map<wstring, wstring>& property_map);
53     static void GetOggPropertyMap(const wstring& file_path, std::map<wstring, wstring>& property_map);
54     static void GetMpcPropertyMap(const wstring& file_path, std::map<wstring, wstring>& property_map);
55     static void GetOpusPropertyMap(const wstring& file_path, std::map<wstring, wstring>& property_map);
56     static void GetWavPackPropertyMap(const wstring& file_path, std::map<wstring, wstring>& property_map);
57     static void GetTtaPropertyMap(const wstring& file_path, std::map<wstring, wstring>& property_map);
58     static void GetAiffPropertyMap(const wstring& file_path, std::map<wstring, wstring>& property_map);
59     static void GetSpxPropertyMap(const wstring& file_path, std::map<wstring, wstring>& property_map);
60 
61     static void GetAnyFilePropertyMap(const wstring& file_path, std::map<wstring, wstring>& property_map);
62 
63     //读取歌词
64     static wstring GetMpegLyric(const wstring& file_path);
65     static wstring GetM4aLyric(const wstring& file_path);
66     static wstring GetFlacLyric(const wstring& file_path);
67     static wstring GetAsfLyric(const wstring& file_path);
68     static wstring GetWavLyric(const wstring& file_path);
69 
70     //写入歌词
71     static bool WriteMpegLyric(const wstring& file_path, const wstring& lyric_contents);
72     static bool WriteFlacLyric(const wstring& file_path, const wstring& lyric_contents);
73     static bool WriteM4aLyric(const wstring& file_path, const wstring& lyric_contents);
74     static bool WriteAsfLyric(const wstring& file_path, const wstring& lyric_contents);
75     static bool WriteWavLyric(const wstring& file_path, const wstring& lyric_contents);
76 
77     //写专辑封面
78     static bool WriteMp3AlbumCover(const wstring& file_path, const wstring& album_cover_path, bool remove_exist = true);
79     static bool WriteFlacAlbumCover(const wstring& file_path, const wstring& album_cover_path, bool remove_exist = true);
80     static bool WriteM4aAlbumCover(const wstring& file_path, const wstring& album_cover_path, bool remove_exist = true);
81     static bool WriteAsfAlbumCover(const wstring& file_path, const wstring& album_cover_path, bool remove_exist = true);
82     static bool WriteWavAlbumCover(const wstring& file_path, const wstring& album_cover_path, bool remove_exist = true);
83     static bool WriteTtaAlbumCover(const wstring& file_path, const wstring& album_cover_path, bool remove_exist = true);
84     static bool WriteApeAlbumCover(const wstring& file_path, const wstring& album_cover_path, bool remove_exist = true);
85     static bool WriteOggAlbumCover(const wstring& file_path, const wstring& album_cover_path, bool remove_exist = true);
86     static bool WriteOpusAlbumCover(const wstring& file_path, const wstring& album_cover_path, bool remove_exist = true);
87     static bool WriteSpxAlbumCover(const wstring& file_path, const wstring& album_cover_path, bool remove_exist = true);
88     static bool WriteAiffAlbumCover(const wstring& file_path, const wstring& album_cover_path, bool remove_exist = true);
89     static bool WriteMpcAlbumCover(const wstring& file_path, const wstring& album_cover_path, bool remove_exist = true);
90     static bool WriteWavePackAlbumCover(const wstring& file_path, const wstring& album_cover_path, bool remove_exist = true);
91 
92     //写标签信息
93     static bool WriteMpegTag(const SongInfo& song_info);
94     static bool WriteFlacTag(const SongInfo& song_info);
95     static bool WriteM4aTag(const SongInfo& song_info);
96     static bool WriteWavTag(const SongInfo& song_info);
97     static bool WriteOggTag(const SongInfo& song_info);
98     static bool WriteApeTag(const SongInfo& song_info);
99     static bool WriteMpcTag(const SongInfo& song_info);
100     static bool WriteOpusTag(const SongInfo& song_info);
101     static bool WriteWavPackTag(const SongInfo& song_info);
102     static bool WriteTtaTag(const SongInfo& song_info);
103     static bool WriteAiffTag(const SongInfo& song_info);
104     static bool WriteAsfTag(const SongInfo& song_info);
105     static bool WriteSpxTag(const SongInfo& song_info);
106 
107     //读取内嵌cue
108     static wstring GetApeCue(const wstring& file_path);
109 
110     //读取分级信息。返回1~5为分级,返回0表示未分级
111     static int GetMepgRating(const wstring& file_path);
112     static int GetFlacRating(const wstring& file_path);
113     static int GetWmaRating(const wstring& file_path);
114 
115     //写入分级信息
116     static bool WriteMpegRating(const wstring& file_path, int rate);
117     static bool WriteFlacRating(const wstring& file_path, int rate);
118     static bool WriteWmaRating(const wstring& file_path, int rate);
119 
120 private:
121     //获取要写入的ID3V2版本
122     static TagLib::ID3v2::Version GetWriteId3v2Version();
123 
124 private:
125     static bool m_write_id3v2_3;   //写入ID3V2标签时是否使用2.3版本,否则使用2.4
126 };
127