always save and read id3 tags in unicode

This commit is contained in:
Andrzej Rybczak
2009-01-11 15:43:12 +01:00
parent 0d9aea79c2
commit 73c166a029
4 changed files with 21 additions and 23 deletions

View File

@@ -764,7 +764,7 @@ void GetInfo(Song &s, Scrollpad &info)
path_to_file += s.GetFile(); path_to_file += s.GetFile();
TagLib::FileRef f(path_to_file.c_str()); TagLib::FileRef f(path_to_file.c_str());
if (!f.isNull()) if (!f.isNull())
s.SetComment(f.tag()->comment().to8Bit(UNICODE)); s.SetComment(f.tag()->comment().to8Bit(1));
# endif // HAVE_TAGLIB_H # endif // HAVE_TAGLIB_H
info << fmtBold << Config.color1 << "Filename: " << fmtBoldEnd << Config.color2 << s.GetName() << "\n" << clEnd; info << fmtBold << Config.color1 << "Filename: " << fmtBoldEnd << Config.color2 << s.GetName() << "\n" << clEnd;

View File

@@ -2571,7 +2571,7 @@ int main(int argc, char *argv[])
success = 0; success = 0;
break; break;
} }
f.tag()->setAlbum(TO_WSTRING(new_album)); f.tag()->setAlbum(ToWString(new_album));
f.save(); f.save();
} }
if (success) if (success)

View File

@@ -274,31 +274,31 @@ void ReadTagsFromFile(mpd_Song *s)
TagLib::MPEG::File *mpegf = dynamic_cast<TagLib::MPEG::File *>(f.file()); TagLib::MPEG::File *mpegf = dynamic_cast<TagLib::MPEG::File *>(f.file());
s->artist = !f.tag()->artist().isEmpty() ? str_pool_get(f.tag()->artist().toCString(UNICODE)) : 0; s->artist = !f.tag()->artist().isEmpty() ? str_pool_get(f.tag()->artist().toCString(1)) : 0;
s->title = !f.tag()->title().isEmpty() ? str_pool_get(f.tag()->title().toCString(UNICODE)) : 0; s->title = !f.tag()->title().isEmpty() ? str_pool_get(f.tag()->title().toCString(1)) : 0;
s->album = !f.tag()->album().isEmpty() ? str_pool_get(f.tag()->album().toCString(UNICODE)) : 0; s->album = !f.tag()->album().isEmpty() ? str_pool_get(f.tag()->album().toCString(1)) : 0;
s->track = f.tag()->track() ? str_pool_get(IntoStr(f.tag()->track()).c_str()) : 0; s->track = f.tag()->track() ? str_pool_get(IntoStr(f.tag()->track()).c_str()) : 0;
s->date = f.tag()->year() ? str_pool_get(IntoStr(f.tag()->year()).c_str()) : 0; s->date = f.tag()->year() ? str_pool_get(IntoStr(f.tag()->year()).c_str()) : 0;
s->genre = !f.tag()->genre().isEmpty() ? str_pool_get(f.tag()->genre().toCString(UNICODE)) : 0; s->genre = !f.tag()->genre().isEmpty() ? str_pool_get(f.tag()->genre().toCString(1)) : 0;
if (mpegf) if (mpegf)
{ {
s->composer = !mpegf->ID3v2Tag()->frameListMap()["TCOM"].isEmpty() s->composer = !mpegf->ID3v2Tag()->frameListMap()["TCOM"].isEmpty()
? (!mpegf->ID3v2Tag()->frameListMap()["TCOM"].front()->toString().isEmpty() ? (!mpegf->ID3v2Tag()->frameListMap()["TCOM"].front()->toString().isEmpty()
? str_pool_get(mpegf->ID3v2Tag()->frameListMap()["TCOM"].front()->toString().toCString(UNICODE)) ? str_pool_get(mpegf->ID3v2Tag()->frameListMap()["TCOM"].front()->toString().toCString(1))
: 0) : 0)
: 0; : 0;
s->performer = !mpegf->ID3v2Tag()->frameListMap()["TOPE"].isEmpty() s->performer = !mpegf->ID3v2Tag()->frameListMap()["TOPE"].isEmpty()
? (!mpegf->ID3v2Tag()->frameListMap()["TOPE"].front()->toString().isEmpty() ? (!mpegf->ID3v2Tag()->frameListMap()["TOPE"].front()->toString().isEmpty()
? str_pool_get(mpegf->ID3v2Tag()->frameListMap()["TOPE"].front()->toString().toCString(UNICODE)) ? str_pool_get(mpegf->ID3v2Tag()->frameListMap()["TOPE"].front()->toString().toCString(1))
: 0) : 0)
: 0; : 0;
s->disc = !mpegf->ID3v2Tag()->frameListMap()["TPOS"].isEmpty() s->disc = !mpegf->ID3v2Tag()->frameListMap()["TPOS"].isEmpty()
? (!mpegf->ID3v2Tag()->frameListMap()["TPOS"].front()->toString().isEmpty() ? (!mpegf->ID3v2Tag()->frameListMap()["TPOS"].front()->toString().isEmpty()
? str_pool_get(mpegf->ID3v2Tag()->frameListMap()["TPOS"].front()->toString().toCString(UNICODE)) ? str_pool_get(mpegf->ID3v2Tag()->frameListMap()["TPOS"].front()->toString().toCString(1))
: 0) : 0)
: 0; : 0;
} }
s->comment = !f.tag()->comment().isEmpty() ? str_pool_get(f.tag()->comment().toCString(UNICODE)) : 0; s->comment = !f.tag()->comment().isEmpty() ? str_pool_get(f.tag()->comment().toCString(1)) : 0;
s->time = f.audioProperties()->length(); s->time = f.audioProperties()->length();
} }
@@ -312,7 +312,7 @@ bool GetSongTags(Song &s)
TagLib::FileRef f(path_to_file.c_str()); TagLib::FileRef f(path_to_file.c_str());
if (f.isNull()) if (f.isNull())
return false; return false;
s.SetComment(f.tag()->comment().to8Bit(UNICODE)); s.SetComment(f.tag()->comment().to8Bit(1));
string ext = s.GetFile(); string ext = s.GetFile();
ext = ext.substr(ext.find_last_of(".")+1); ext = ext.substr(ext.find_last_of(".")+1);
@@ -372,13 +372,13 @@ bool WriteTags(Song &s)
FileRef f(path_to_file.c_str()); FileRef f(path_to_file.c_str());
if (!f.isNull()) if (!f.isNull())
{ {
f.tag()->setTitle(TO_WSTRING(s.GetTitle())); f.tag()->setTitle(ToWString(s.GetTitle()));
f.tag()->setArtist(TO_WSTRING(s.GetArtist())); f.tag()->setArtist(ToWString(s.GetArtist()));
f.tag()->setAlbum(TO_WSTRING(s.GetAlbum())); f.tag()->setAlbum(ToWString(s.GetAlbum()));
f.tag()->setYear(StrToInt(s.GetYear())); f.tag()->setYear(StrToInt(s.GetYear()));
f.tag()->setTrack(StrToInt(s.GetTrack())); f.tag()->setTrack(StrToInt(s.GetTrack()));
f.tag()->setGenre(TO_WSTRING(s.GetGenre())); f.tag()->setGenre(ToWString(s.GetGenre()));
f.tag()->setComment(TO_WSTRING(s.GetComment())); f.tag()->setComment(ToWString(s.GetComment()));
f.save(); f.save();
string ext = s.GetFile(); string ext = s.GetFile();
@@ -388,16 +388,16 @@ bool WriteTags(Song &s)
{ {
MPEG::File file(path_to_file.c_str()); MPEG::File file(path_to_file.c_str());
ID3v2::Tag *tag = file.ID3v2Tag(); ID3v2::Tag *tag = file.ID3v2Tag();
String::Type encoding = UNICODE ? String::UTF8 : String::Latin1; String::Type encoding = String::UTF8;
ByteVector Composer("TCOM"); ByteVector Composer("TCOM");
ByteVector Performer("TOPE"); ByteVector Performer("TOPE");
ByteVector Disc("TPOS"); ByteVector Disc("TPOS");
ID3v2::Frame *ComposerFrame = new ID3v2::TextIdentificationFrame(Composer, encoding); ID3v2::Frame *ComposerFrame = new ID3v2::TextIdentificationFrame(Composer, encoding);
ID3v2::Frame *PerformerFrame = new ID3v2::TextIdentificationFrame(Performer, encoding); ID3v2::Frame *PerformerFrame = new ID3v2::TextIdentificationFrame(Performer, encoding);
ID3v2::Frame *DiscFrame = new ID3v2::TextIdentificationFrame(Disc, encoding); ID3v2::Frame *DiscFrame = new ID3v2::TextIdentificationFrame(Disc, encoding);
ComposerFrame->setText(TO_WSTRING(s.GetComposer())); ComposerFrame->setText(ToWString(s.GetComposer()));
PerformerFrame->setText(TO_WSTRING(s.GetPerformer())); PerformerFrame->setText(ToWString(s.GetPerformer()));
DiscFrame->setText(TO_WSTRING(s.GetDisc())); DiscFrame->setText(ToWString(s.GetDisc()));
tag->removeFrames(Composer); tag->removeFrames(Composer);
tag->addFrame(ComposerFrame); tag->addFrame(ComposerFrame);
tag->removeFrames(Performer); tag->removeFrames(Performer);
@@ -599,7 +599,7 @@ void __deal_with_filenames(SongList &v)
int last_dot = file.find_last_of("."); int last_dot = file.find_last_of(".");
string extension = file.substr(last_dot); string extension = file.substr(last_dot);
basic_buffer<my_char_t> new_file; basic_buffer<my_char_t> new_file;
new_file << TO_WSTRING(GenerateFilename(s, Config.pattern)); new_file << ToWString(GenerateFilename(s, Config.pattern));
if (new_file.Str().empty()) if (new_file.Str().empty())
{ {
if (preview) if (preview)

View File

@@ -34,14 +34,12 @@
#include <cstring> #include <cstring>
#ifdef _UTF8 #ifdef _UTF8
# define UNICODE 1
# define my_char_t wchar_t # define my_char_t wchar_t
# define my_string_t wstring # define my_string_t wstring
# define UTF_S_FMT "%ls" # define UTF_S_FMT "%ls"
# define TO_STRING(x) ToString(x) # define TO_STRING(x) ToString(x)
# define TO_WSTRING(x) ToWString(x) # define TO_WSTRING(x) ToWString(x)
#else #else
# define UNICODE 0
# define my_char_t char # define my_char_t char
# define my_string_t string # define my_string_t string
# define UTF_S_FMT "%s" # define UTF_S_FMT "%s"