本文整理汇总了C++中taglib::Tag::year方法的典型用法代码示例。如果您正苦于以下问题:C++ Tag::year方法的具体用法?C++ Tag::year怎么用?C++ Tag::year使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类taglib::Tag
的用法示例。
在下文中一共展示了Tag::year方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readTags
void Track::readTags()
{
QByteArray fileName = QFile::encodeName( p->url.toLocalFile() );
const char * encodedName = fileName.constData();
TagLib::FileRef fileref = TagLib::FileRef( encodedName, true, TagLib::AudioProperties::Fast);
if ( !fileref.isNull() )
{
if( fileref.tag() )
{
TagLib::Tag *tag = fileref.tag();
p->title = !tag->title().isNull() ? TStringToQString( tag->title() ).trimmed() : QObject::tr("Unknown");
p->artist = !tag->artist().isNull() ? TStringToQString( tag->artist() ).trimmed() : QObject::tr("Unknown");
p->album = !tag->album().isNull() ? TStringToQString( tag->album() ).trimmed() : QObject::tr("Unknown");
p->comment = TStringToQString( tag->comment() ).trimmed();
p->genre = !tag->genre().isNull() ? TStringToQString( tag->genre() ).trimmed() : QObject::tr("Unknown");
p->year = tag->year() ? QString::number( tag->year() ) : QString::null;
p->tracknumber = tag->track() ? QString::number( tag->track() ) : QString::null;
p->length = fileref.audioProperties()->length();
p->counter = 0;
p->rate = 0;
//polish up empty tags
if( p->title == QObject::tr("Unknown") ) {
QFileInfo fileInfo(p->url.toLocalFile());
p->title = fileInfo.fileName().replace( '_', ' ' ).replace('.' + fileInfo.suffix(),"") ;
}
}
}
}
示例2: parseAndWrite
bool parseAndWrite(const char* location, Json::Writer& writer)
{
Json::Value metadata;
metadata[LOCATION] = location;
TagLib::FileRef f(location);
if (f.isNull()){
return false;
}
if (f.tag() && !f.tag()->isEmpty()){
TagLib::Tag* tag = f.tag();
TagLib::String artist = tag->artist();
TagLib::String album = tag->artist();
TagLib::String title = tag->title();
uint track = tag->track();
uint year = tag->year();
metadata[TITLE] = title.toCString(true);
metadata[ARTIST] = artist.toCString(true);
metadata[ALBUM] = album.toCString(true);
metadata[TRACK] = track;
metadata[YEAR] = year;
}
std::cout << writer.write(metadata);
return true;
}
示例3: 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;
}
}
}
示例4: f
bool MP3::readID3v2(const std::string& filename, Metadata& meta) {
// After reading http://mail.kde.org/pipermail/taglib-devel/2008-March/000902.html
// adding a big lock seems reasonable
try {
taglib_mutex.lock();
TagLib::MPEG::File f(filename.c_str());
if (f.isValid() && f.tag()) {
TagLib::Tag* pTag = f.tag();
meta.interpret = pTag->artist().isNull() ? "" : pTag->artist().to8Bit(true);
meta.album = pTag->album().isNull() ? "" : pTag->album().to8Bit(true);
meta.title = pTag->title().isNull() ? "" : pTag->title().to8Bit(true);
meta.genre = pTag->genre().isNull() ? "" : pTag->genre().to8Bit(true);
meta.track_no = pTag->track();
meta.year = pTag->year();
taglib_mutex.unlock();
return meta.complete();
}
} catch (const std::exception&) {
taglib_mutex.unlock();
// ...
}
return false;
}
示例5: 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;
}
示例6: 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);
}
}
}
示例7: 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;
}
示例8: MetaData
bool MetaData(const char* filepath, cFields& fields, cRow& props)
{
#define ADD(x, t) do { if (t) { fields.push_back(x); props.push_back(t); } } while(0)
#define ADDSTRING(x, t) do { if (!t.empty()) { fields.push_back(x); props.push_back(t); } } while(0)
#define ADDINT(x, t) do { std::string c = *itoa(t); if (!c.empty()){ fields.push_back(x); props.push_back(c);} } while(0)
TagLib::FileRef f(filepath);
fields.clear();
props.clear();
//cTag t;
//const char* tmp = NULL;
std::string tmp;
if (f.isNull())
{
std::cerr<< "Taglib failed on " << filepath << std::endl;
ADD("metadata_needs_update", "2"); // failure
return false;
}
TagLib::Tag *tag = f.tag();
if (tag)
{
#if 0
tmp = toString(tag->title()).c_str(); ADD("title", tmp);
tmp = toString(tag->artist()).c_str(); ADD("artist", tmp);
tmp = toString(tag->album()).c_str(); ADD("album", tmp);
tmp = toString(tag->comment()).c_str(); ADD("comment", tmp);
tmp = toString(tag->genre()).c_str(); ADD("genre", tmp);
#else
tmp = toString(tag->title()); ADDSTRING("title", tmp);
tmp = toString(tag->artist()); ADDSTRING("artist", tmp);
tmp = toString(tag->album()); ADDSTRING("album", tmp);
tmp = toString(tag->comment()); ADDSTRING("comment", tmp);
tmp = toString(tag->genre()); ADDSTRING("genre", tmp);
#endif
//ADDINT("track", tag->track());
ADDINT("year", tag->year());
}
TagLib::AudioProperties *prop = f.audioProperties();
if (prop)
{
ADDINT("bitrate", prop->bitrate());
ADDINT("samplerate", prop->sampleRate());
// ADDINT("channels", prop->channels());
ADDINT("length" , prop->length());
}
ADD("metadata_needs_update", "0");
return true;
}
示例9: 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;
}
示例10: scan
void FileStore::scan(const string & a_path) {
if (!fs::exists(a_path))
return;
if (fs::is_directory(a_path)) {
fs::directory_iterator end; // default construction yields past-the-end
for (fs::directory_iterator curr(a_path); curr != end; ++curr) {
fs::path p = curr->path();
string s = p.string();
scan(s);
}
} else if (fs::is_regular_file(a_path)) {
if (pathExists(a_path))
return;
TagLib::FileRef file_ref(a_path.c_str(), false);
if (!file_ref.isNull() && file_ref.tag()) {
cerr << "indexing " << a_path << endl;
TagLib::Tag *t = file_ref.tag();
string artist = t->artist().to8Bit(true);
string album = t->album().to8Bit(true);
string title = t->title().to8Bit(true);
string genre = t->genre().to8Bit(true);
string year = t->year() > 0 ? lexical_cast<string>(t->year()) : "";
string track = t->track() > 0 ? lexical_cast<string>(t->track()) : "";
string uri = "file://" + a_path;
shared_ptr<UUID> fileID(generateID());
addField(*fileID, ARTIST, artist);
addField(*fileID, ARTIST, artist);
addField(*fileID, ALBUM, album);
addField(*fileID, YEAR, year);
addField(*fileID, TITLE, title);
addField(*fileID, GENRE, genre);
addField(*fileID, TRACK, track);
addField(*fileID, URI, uri);
}
}
}
示例11: main
int main(int argc, char *argv[])
{
if (argc < 3) return 1;
string what(argv[1]);
TagLib::FileRef f(argv[2]);
if(!f.isNull() && f.tag()) {
TagLib::Tag *tag = f.tag();
if (what == "title") cout << tag->title() << endl;
if (what == "artist") cout << tag->artist() << endl;
if (what == "album") cout << tag->album() << endl;
if (what == "year") cout << tag->year() << endl;
}
return 0;
}
示例12: 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 --" << 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;
}
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 << ":" << formatSeconds(seconds) << endl;
}
}
return 0;
}
示例13: mediaTag
bool mediaTag(Artwork *art, TagLib::File *f)
{
Q_ASSERT(f != NULL);
Q_ASSERT(f->tag());
TagLib::Tag *tag = f->tag();
art->filetype = FILETYPE_UNKNOWN;
// The basic stuff!!!
art->artist = TStringToQString(tag->artist()).trimmed();
art->album = TStringToQString(tag->album()).trimmed();
art->track = TStringToQString(tag->title()).trimmed();
art->genre = TStringToQString(tag->genre()).trimmed();
art->year = tag->year();
art->trackNo = tag->track();
// we need something to search on!
if (art->artist == "" && art->album == "" && art->track == "") {
return false;
}
// Any audio properties???
if (f->audioProperties()) {
TagLib::AudioProperties *properties = f->audioProperties();
int seconds = properties->length() % 60;
int minutes = (properties->length() - seconds) / 60;
art->duration = minutes * 60 + seconds;
art->bitRate = properties->bitrate();
art->sampleRate = properties->sampleRate();
art->channels = properties->channels();
}
art->makeSearchable();
return true;
}
示例14: ReadFile
void TagReader::ReadFile(const QString& filename,
pb::tagreader::SongMetadata* song) const {
const QByteArray url(QUrl::fromLocalFile(filename).toEncoded());
const QFileInfo info(filename);
qLog(Debug) << "Reading tags from" << filename;
song->set_basefilename(DataCommaSizeFromQString(info.fileName()));
song->set_url(url.constData(), url.size());
song->set_filesize(info.size());
song->set_mtime(info.lastModified().toTime_t());
song->set_ctime(info.created().toTime_t());
std::unique_ptr<TagLib::FileRef> fileref(factory_->GetFileRef(filename));
if (fileref->isNull()) {
qLog(Info) << "TagLib hasn't been able to read " << filename << " file";
return;
}
TagLib::Tag* tag = fileref->tag();
if (tag) {
Decode(tag->title(), nullptr, song->mutable_title());
Decode(tag->artist(), nullptr, song->mutable_artist()); // TPE1
Decode(tag->album(), nullptr, song->mutable_album());
Decode(tag->genre(), nullptr, song->mutable_genre());
song->set_year(tag->year());
song->set_track(tag->track());
song->set_valid(true);
}
QString disc;
QString compilation;
// Handle all the files which have VorbisComments (Ogg, OPUS, ...) in the same
// way;
// apart, so we keep specific behavior for some formats by adding another
// "else if" block below.
if (TagLib::Ogg::XiphComment* tag =
dynamic_cast<TagLib::Ogg::XiphComment*>(fileref->file()->tag())) {
ParseOggTag(tag->fieldListMap(), nullptr, &disc, &compilation, song);
}
if (TagLib::MPEG::File* file =
dynamic_cast<TagLib::MPEG::File*>(fileref->file())) {
if (file->ID3v2Tag()) {
const TagLib::ID3v2::FrameListMap& map = file->ID3v2Tag()->frameListMap();
if (!map["TPOS"].isEmpty())
disc = TStringToQString(map["TPOS"].front()->toString()).trimmed();
if (!map["TBPM"].isEmpty())
song->set_bpm(TStringToQString(map["TBPM"].front()->toString())
.trimmed()
.toFloat());
if (!map["TCOM"].isEmpty())
Decode(map["TCOM"].front()->toString(), nullptr,
song->mutable_composer());
if (!map["TIT1"].isEmpty()) // content group
Decode(map["TIT1"].front()->toString(), nullptr,
song->mutable_grouping());
// Skip TPE1 (which is the artist) here because we already fetched it
if (!map["TPE2"].isEmpty()) // non-standard: Apple, Microsoft
Decode(map["TPE2"].front()->toString(), nullptr,
song->mutable_albumartist());
if (!map["TCMP"].isEmpty())
compilation =
TStringToQString(map["TCMP"].front()->toString()).trimmed();
if (!map["APIC"].isEmpty()) song->set_art_automatic(kEmbeddedCover);
// Find a suitable comment tag. For now we ignore iTunNORM comments.
for (int i = 0; i < map["COMM"].size(); ++i) {
const TagLib::ID3v2::CommentsFrame* frame =
dynamic_cast<const TagLib::ID3v2::CommentsFrame*>(map["COMM"][i]);
if (frame && TStringToQString(frame->description()) != "iTunNORM") {
Decode(frame->text(), nullptr, song->mutable_comment());
break;
}
}
// Parse FMPS frames
for (int i = 0; i < map["TXXX"].size(); ++i) {
const TagLib::ID3v2::UserTextIdentificationFrame* frame =
dynamic_cast<const TagLib::ID3v2::UserTextIdentificationFrame*>(
map["TXXX"][i]);
if (frame && frame->description().startsWith("FMPS_")) {
ParseFMPSFrame(TStringToQString(frame->description()),
TStringToQString(frame->fieldList()[1]), song);
}
}
// Check POPM tags
// We do this after checking FMPS frames, so FMPS have precedence, as we
//.........这里部分代码省略.........
示例15: 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 --" << endl;
cout << "title - \"" << tag->title() << "\"" << endl;
cout << "artist - \"" << tag->artist() << "\"" << endl;
cout << "album artist - \"" << tag->albumArtist() << "\"" << 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;
cout << "grouping - \"" << tag->grouping() << "\"" << endl;
TagLib::Ogg::XiphComment *comment = NULL;
TagLib::FLAC::File *flac = dynamic_cast<TagLib::FLAC::File *>(f.file());
if (flac) {
cout << "flac:" << endl;
cout << "id3v1 - \"" << flac->ID3v1Tag() << "\"" << endl;
cout << "id3v2 - \"" << flac->ID3v2Tag() << "\"" << endl;
cout << "xiph - \"" << flac->xiphComment() << "\"" << endl;
comment = flac->xiphComment();
}
if (!comment) {
comment = dynamic_cast<TagLib::Ogg::XiphComment *>(tag);
}
if (comment) {
TagLib::Ogg::FieldListMap fields = comment->fieldListMap();
for(TagLib::Ogg::FieldListMap::ConstIterator it = fields.begin(), end = fields.end(); it != end; it++) {
if (!it->second.isEmpty())
cout << "xiph:" << it->first << " \"" << it->second[0].substr(0,3) << "\"" << endl;
}
}
cout << "pictures- \"" << f.file()->pictures().size() << "\"" << endl;
TagLib::File::PictureList l = f.file()->pictures();
for (TagLib::File::_PictureList::ConstIterator i = l.begin(), end = l.end(); i != end; i++) {
cout << "\t" << (*i)->typeName() << ' ' << (*i)->mimeType() << ' ' << (*i)->base64data().size() << endl;
}
cout << "pictures- \"" << tag->pictures().size() << "\"" << 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 << ":" << formatSeconds(seconds) << endl;
}
}
return 0;
}