コード例 #1
0
ファイル: tagwriter.cpp プロジェクト: jamesyan84/zbase
/* LOAD UP THE FILE'S TAG
 * Search each file type individually so we can get individual tags for
 * custom tagging.
 */
TagDatac * tag_data_load (char *url, int *pvalid)
{
    TagData * data;
    TagLib::String s = url;
    int mtime;
    struct stat buf;
    if (!stat (url, &buf))
        mtime = (int) buf.st_mtime;


   /* FIXME: Using filename to find media type. GStreamer probe instead?
   */
    if(s.size() > 4) {
        if(s.substr(s.size() - 4, 4).upper() == ".OGG")
        {
            TagLib::Vorbis::File * f = new TagLib::Vorbis::File(url);
            if (! f->isValid ())
                return NULL;
            data = (TagData*) malloc (sizeof (TagData));
            data->file = new TagLib::FileRef (f);
            data->id3v2 = NULL;
            data->id3v1 = NULL;
            data->ape   = NULL;
            data->xiph  = f->tag ();
            data->mime  = "application/ogg";
            data->mtime = mtime;
            return reinterpret_cast<TagDatac *> (data);
        }
        if(s.substr(s.size() - 4, 4).upper() == ".MP3")
        {
            TagLib::MPEG::File * f = new TagLib::MPEG::File(url);
            if (! f->isValid ())
                return NULL;
            data = (TagData*) malloc (sizeof (TagData));
            data->file = new TagLib::FileRef (f);
            data->id3v2 = f->ID3v2Tag ();
            data->id3v1 = f->ID3v1Tag ();
            data->ape   = f->APETag ();
            data->xiph  = NULL;
            data->mime  = "audio/mpeg";
            data->mtime = mtime;
            return reinterpret_cast<TagDatac *>(data);
        }
        if(s.substr(s.size() - 5, 5).upper() == ".FLAC")
        {
            TagLib::FLAC::File * f = new TagLib::FLAC::File(url);
            if ((! f->isValid ())&& (pvalid != NULL)){
				*pvalid = -1;//paul add on 080827 merge from Olive
                return NULL;
			}
            data = (TagData*) malloc (sizeof (TagData));
            data->file = new TagLib::FileRef (f);
            data->id3v2 = f->ID3v2Tag ();
            data->id3v1 = f->ID3v1Tag ();
            data->ape   = NULL;
            data->xiph  = f->xiphComment ();
            data->mime  = "audio/x-flac";
            data->mtime = mtime;
            return reinterpret_cast<TagDatac *>(data);
        }
        if(s.substr(s.size() - 4, 4).upper() == ".MPC" || s.substr(s.size() - 4, 4).upper() == ".AAC")
        {
            TagLib::MPC::File * f = new TagLib::MPC::File(url);
            if (! f->isValid ())
                return NULL;
            data = (TagData*) malloc (sizeof (TagData));
            data->file = new TagLib::FileRef (f);
            data->id3v2 = NULL;
            data->id3v1 = f->ID3v1Tag ();
            data->ape   = f->APETag ();
            data->xiph  = NULL;
            data->mime  = "audio/x-musepack";
            data->mtime = mtime;
            return reinterpret_cast<TagDatac *>(data);
        }
    }
    return NULL;
}
コード例 #2
0
ファイル: tagreader.cpp プロジェクト: dibowei/taglib
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;
}