本文整理汇总了C++中taglib::Tag类的典型用法代码示例。如果您正苦于以下问题:C++ Tag类的具体用法?C++ Tag怎么用?C++ Tag使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Tag类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fileref
Tag::Tag(const QString &filename)
: m_filename(filename)
{
TagLib::MPEG::File mpegfile(filename.toLocal8Bit().constData());
TagLib::ID3v2::Tag* id3v2 = mpegfile.ID3v2Tag();
if (id3v2 && !id3v2->isEmpty()) {
readRegularTag(id3v2, m_data);
int picnum = 0;
TagLib::ID3v2::FrameList frames = id3v2->frameListMap()["APIC"]; // attached picture
TagLib::ID3v2::FrameList::ConstIterator it = frames.begin();
while (it != frames.end()) {
TagLib::ID3v2::AttachedPictureFrame* apic = static_cast<TagLib::ID3v2::AttachedPictureFrame*>(*it);
TagLib::ByteVector bytes = apic->picture();
QImage img = QImage::fromData(reinterpret_cast<const uchar*>(bytes.data()), bytes.size());
if (!img.isNull()) {
m_data[QLatin1String("picture") + QString::number(picnum++)] = QVariant(img);
}
++it;
}
} else {
TagLib::FileRef fileref(filename.toLocal8Bit().constData());
if (fileref.isNull())
return;
TagLib::Tag* tag = fileref.tag();
if (!tag || tag->isEmpty())
return;
readRegularTag(tag, m_data);
}
}
示例2: f
void
M3uLoader::getTags( const QFileInfo& info )
{
QByteArray fileName = QFile::encodeName( info.canonicalFilePath() );
const char *encodedName = fileName.constData();
TagLib::FileRef f( encodedName );
TagLib::Tag *tag = f.tag();
QString artist = TStringToQString( tag->artist() ).trimmed();
QString album = TStringToQString( tag->album() ).trimmed();
QString track = TStringToQString( tag->title() ).trimmed();
if ( artist.isEmpty() || track.isEmpty() )
{
qDebug() << "Error parsing" << info.fileName();
return;
}
else
{
qDebug() << Q_FUNC_INFO << artist << track << album;
Tomahawk::query_ptr q = Tomahawk::Query::get( artist, track, album, uuid(), !m_createNewPlaylist );
if ( !q.isNull() )
m_tracks << q;
}
}
示例3: file
QVector<bool> TagsManager::writeTags(const QVector<SongFile>& songs)
{
QVector<bool> result;
for (SongFile const& song : songs)
{
bool success = false;
if (!song.getAuthors().isEmpty() || !song.getTitle().isEmpty())
{
const QString songFilePath = song.getFilepath();
TagLib::FileRef file(songFilePath.toStdString().c_str());
if (!file.isNull() && file.tag())
{
TagLib::Tag *tag = file.tag();
tag->setArtist(song.getAuthors().join(";").toStdString());
tag->setTitle(song.getTitle().toStdString());
success = file.save();
}
}
result.append(success);
}
return result;
}
示例4: f
cFileInfoMenu::cFileInfoMenu(std::string mrl) : cOsdMenu( tr("File Info:"), 12)
{
//set title
//SetTitle(tr("mediaplayer - Id3 Info:"));
mrl_ = mrl;
fileInfoVec_ = GetFileInfo(mrl_);
// Get title
std::string title;
TagLib::FileRef f( mrl.c_str() );
if(!f.isNull() && f.tag())
{
TagLib::Tag *tag = f.tag();
// unicode = false
title = tag->title().stripWhiteSpace().toCString(false) ;
if (title.size())
{
char buffer[128];
snprintf(buffer, 127, "File Info: %s", title.c_str());
SetTitle(buffer);
printf("setting title to : %s\n", buffer);
}
}
ShowInfo();
}
示例5: cueFile
QList<QByteArray> MetaDetector::detectEncodings(const MetaPtr meta)
{
if (meta->localPath.isEmpty()) {
return QList<QByteArray>() << "UTF-8";
}
QByteArray detectByte;
if (!meta->cuePath.isEmpty()) {
QFile cueFile(meta->cuePath);
if (cueFile.open(QIODevice::ReadOnly)) {
detectByte = cueFile.readAll();
return detectEncodings(detectByte);
}
}
#ifdef _WIN32
TagLib::FileRef f(meta->localPath.toStdWString().c_str());
#else
TagLib::FileRef f(meta->localPath.toStdString().c_str());
#endif
TagLib::Tag *tag = f.tag();
if (tag) {
detectByte += tag->title().toCString();
detectByte += tag->artist().toCString();
detectByte += tag->album().toCString();
}
return detectEncodings(detectByte);
}
示例6: f
JNIEXPORT jstring JNICALL Java_TagLibReader_getTitle (JNIEnv *env, jobject thisObj, jstring path) {
const jchar *pathCStr = env->GetStringChars(path, NULL);
TagLib::FileRef f(reinterpret_cast<const wchar_t*>(pathCStr));
if(!f.isNull() && f.tag()) {
TagLib::Tag *tag = f.tag();
return env->NewStringUTF(tag->title().toCString(true));
}
else {
return NULL;
}
}
示例7: WriteTag
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;
}
示例8: getMp3Info
void getMp3Info(const WCHAR* fileName, MP3Info &info)
{
TagLib::FileRef f(fileName);
if (!f.isNull() && f.tag())
{
TagLib::Tag *tag = f.tag();
info.tag[0] = tag->title().toWString();
info.tag[1] = tag->artist().toWString();
info.tag[2] = tag->album().toWString();
info.tag[3] = tag->comment().toWString();
info.tag[4] = tag->genre().toWString();
info.year = tag->year();
info.track = tag->track();
TagLib::PropertyMap tags = f.file()->properties();
if (!f.isNull() && f.audioProperties())
{
TagLib::AudioProperties *properties = f.audioProperties();
int seconds = properties->length() % 60;
int minutes = (properties->length() - seconds) / 60;
info.bitrate = properties->bitrate();
info.sample_rate = properties->sampleRate();
info.channels = properties->channels();
info.length_minutes = minutes;
info.length_seconds = seconds;
}
}
}
示例9: handle_file
int handle_file(const char* filepath, const char* filekey, AudioFileRecordStore& record_store)
{
bool record_exists = record_store.find_record(filekey) != NULL;
// Scanning a file for tags is expensive, so only do it if required.
if(record_exists
&& !record_store.record_update_required(filekey))
{
// no update reqquired so has been handled.
return 1;
}
TagLib::FileRef f(filepath);
if (!f.isNull() && f.tag())
{
AudioFileRecord &record = record_store.get_record(filekey);
record.update_start();
if (verbose)
{
TagLib::Tag *tag = f.tag();
std::cout << filepath << endl;
std::cout << filekey << endl;
std::cout << "-- TAG (basic) --" << endl;
std::cout << "title - \"" << tag->title() << "\"" << endl;
std::cout << "artist - \"" << tag->artist() << "\"" << endl;
std::cout << "album - \"" << tag->album() << "\"" << endl;
std::cout << "year - \"" << tag->year() << "\"" << endl;
std::cout << "comment - \"" << tag->comment() << "\"" << endl;
std::cout << "track - \"" << tag->track() << "\"" << endl;
std::cout << "genre - \"" << tag->genre() << "\"" << endl;
}
TagLib::PropertyMap tags = f.file()->properties();
for(TagLib::PropertyMap::ConstIterator i = tags.begin(); i != tags.end(); ++i)
{
for(TagLib::StringList::ConstIterator j = i->second.begin(); j != i->second.end(); ++j)
{
record.update(i->first.toCString(true), j->toCString(true));
}
}
if (f.audioProperties())
{
TagLib::AudioProperties *properties = f.audioProperties();
record.update(audio_tags::BITRATE, properties->bitrate());
record.update(audio_tags::LENGTH, properties->length());
record.update(audio_tags::SAMPLERATE, properties->sampleRate());
record.update(audio_tags::CHANNELS, properties->channels());
}
record.update_complete();
return 1;
}
return 0;
}
示例10: urlObj
TagLibTokenizer::TagLibTokenizer(const Document *pDocument) :
Tokenizer(NULL),
m_pTagDocument(NULL)
{
if (pDocument != NULL)
{
Url urlObj(pDocument->getLocation());
string pseudoContent;
if ((urlObj.isLocal() == true) &&
(urlObj.getFile().empty() == false))
{
string location(urlObj.getLocation());
string trackTitle;
location += "/";
location += urlObj.getFile();
TagLib::FileRef fileRef(location.c_str(), false);
if (fileRef.isNull() == false)
{
TagLib::Tag *pTag = fileRef.tag();
if ((pTag != NULL) &&
(pTag->isEmpty() == false))
{
char yearStr[64];
trackTitle = pTag->title().to8Bit();
trackTitle += " ";
trackTitle += pTag->artist().to8Bit();
pseudoContent = trackTitle;
pseudoContent += " ";
pseudoContent += pTag->album().to8Bit();
pseudoContent += " ";
pseudoContent += pTag->comment().to8Bit();
pseudoContent += " ";
pseudoContent += pTag->genre().to8Bit();
snprintf(yearStr, 64, " %u", pTag->year());
pseudoContent += yearStr;
}
}
else
{
trackTitle = pseudoContent = pDocument->getTitle();
}
m_pTagDocument = new Document(trackTitle, pDocument->getLocation(),
pDocument->getType(), pDocument->getLanguage());
m_pTagDocument->setData(pseudoContent.c_str(), pseudoContent.length());
m_pTagDocument->setTimestamp(pDocument->getTimestamp());
m_pTagDocument->setSize(pDocument->getSize());
// Give the result to the parent class
setDocument(m_pTagDocument);
}
}
}
示例11: ReadTag
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;
}
示例12: metaDataChanged
void MediaController::metaDataChanged()
{
QString extra_data;
QByteArray encoded = QFile::encodeName(current_file.path());
TagLib::FileRef ref(encoded.data(), true, TagLib::AudioProperties::Fast);
if (ref.isNull())
{
info_label->setText(i18n("Playing: <b>%1</b>", current_file.name()));
return;
}
TagLib::Tag* tag = ref.tag();
if (!tag)
{
info_label->setText(i18n("Playing: <b>%1</b>", current_file.name()));
return;
}
QString artist = t2q(tag->artist());
QString title = t2q(tag->title());
QString album = t2q(tag->album());
bool has_artist = !artist.isEmpty();
bool has_title = !title.isEmpty();
bool has_album = !album.isEmpty();
if (has_artist && has_title && has_album)
{
extra_data = i18n("<b>%2</b> - <b>%1</b> (Album: <b>%3</b>)", title, artist, album);
info_label->setText(extra_data);
}
else if (has_title && has_artist)
{
extra_data = i18n("<b>%2</b> - <b>%1</b>", title, artist);
info_label->setText(extra_data);
}
else if (has_title)
{
extra_data = i18n("<b>%1</b>", title);
info_label->setText(extra_data);
}
else
{
info_label->setText(i18n("<b>%1</b>", current_file.name()));
}
}
示例13: main
int main(int argc, char *argv[])
{
for(int i = 1; i < argc; i++) {
cout << "******************** \"" << argv[i] << "\" ********************" << endl;
TagLib::FileRef f(argv[i]);
if(!f.isNull() && f.tag()) {
TagLib::Tag *tag = f.tag();
cout << "-- TAG (basic) --" << endl;
cout << "title - \"" << tag->title() << "\"" << endl;
cout << "artist - \"" << tag->artist() << "\"" << endl;
cout << "album - \"" << tag->album() << "\"" << endl;
cout << "year - \"" << tag->year() << "\"" << endl;
cout << "comment - \"" << tag->comment() << "\"" << endl;
cout << "track - \"" << tag->track() << "\"" << endl;
cout << "genre - \"" << tag->genre() << "\"" << endl;
TagLib::PropertyMap tags = f.file()->properties();
unsigned int longest = 0;
for(TagLib::PropertyMap::ConstIterator i = tags.begin(); i != tags.end(); ++i) {
if (i->first.size() > longest) {
longest = i->first.size();
}
}
cout << "-- TAG (properties) --" << endl;
for(TagLib::PropertyMap::ConstIterator i = tags.begin(); i != tags.end(); ++i) {
for(TagLib::StringList::ConstIterator j = i->second.begin(); j != i->second.end(); ++j) {
cout << left << std::setw(longest) << i->first << " - " << '"' << *j << '"' << endl;
}
}
}
if(!f.isNull() && f.audioProperties()) {
TagLib::AudioProperties *properties = f.audioProperties();
int seconds = properties->length() % 60;
int minutes = (properties->length() - seconds) / 60;
cout << "-- AUDIO --" << endl;
cout << "bitrate - " << properties->bitrate() << endl;
cout << "sample rate - " << properties->sampleRate() << endl;
cout << "channels - " << properties->channels() << endl;
cout << "length - " << minutes << ":" << setfill('0') << setw(2) << seconds << endl;
}
}
return 0;
}
示例14: main
int main(int argc, char *argv[])
{
for(int i = 1; i < argc; i++) {
cout << "path:" << argv[i] << endl;
TagLib::FileRef f(argv[i]);
if(!f.isNull() && f.tag()) {
TagLib::Tag *tag = f.tag();
cout << "title:" << (tag->title()).toCString(true) << endl;
cout << "artist:" << (tag->artist()).toCString(true) << endl;
cout << "album:" << (tag->album()).toCString(true) << endl;
cout << "albumartist:" << (tag->albumArtist()).toCString(true) << endl;
cout << "track:" << tag->track() << endl;
cout << "disc:" << tag->cdNr() << endl;
}
if(!f.isNull() && f.audioProperties()) {
TagLib::AudioProperties *properties = f.audioProperties();
cout << "bitrate:" << properties->bitrate() << endl;
cout << "length:" << properties->length() << endl;
}
if(i!=argc-1)
cout << "---" << endl;
}
return 0;
}
示例15: scan_file
string scan_file(const char* path)
{
TagLib::FileRef f(path);
if (!f.isNull() && f.tag()) {
TagLib::Tag *tag = f.tag();
int filesize = boost::filesystem::file_size(path);
int bitrate = 0;
int duration = 0;
if (f.audioProperties()) {
TagLib::AudioProperties *properties = f.audioProperties();
duration = properties->length();
bitrate = properties->bitrate();
}
string artist = tag->artist().toCString(true);
string album = tag->album().toCString(true);
string track = tag->title().toCString(true);
boost::trim(artist);
boost::trim(album);
boost::trim(track);
if (artist.length()==0 || track.length()==0) {
return "{\"error\" : \"no tags\"}\n";
}
string ext(toUtf8(boost::filesystem::extension(path)));
string mimetype = ext2mime(boost::to_lower_copy(ext));
// turn it into a url by prepending file://
// because we pass all urls to curl:
string urlpath = urlify( toUtf8(path) );
ostringstream os;
os << "{ \"url\" : \"" << urlpath << "\","
" \"filesize\" : " << filesize << ","
" \"mimetype\" : \"" << mimetype << "\","
" \"artist\" : \"" << tidy(artist) << "\","
" \"album\" : \"" << tidy(album) << "\","
" \"track\" : \"" << tidy(track) << "\","
" \"duration\" : " << duration << ","
" \"bitrate\" : " << bitrate << ","
" \"trackno\" : " << tag->track()
<< "}\n";
return os.str();
}
return "{\"error\" : \"no tags\"}\n";
}