tagreader.cpp

Go to the documentation of this file.
00001 // g++ tagreader.cpp `taglib-config --cflags --libs` -o tagreader
00002 
00003 
00004 /* Copyright (C) 2003 Scott Wheeler <wheeler@kde.org>
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  *
00010  * 1. Redistributions of source code must retain the above copyright
00011  *    notice, this list of conditions and the following disclaimer.
00012  * 2. Redistributions in binary form must reproduce the above copyright
00013  *    notice, this list of conditions and the following disclaimer in the
00014  *    documentation and/or other materials provided with the distribution.
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00017  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00018  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00019  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00020  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00021  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00022  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00023  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00025  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  */
00027 
00028 #include <iostream>
00029 #include <stdio.h>
00030 
00031 #include <fileref.h>
00032 #include <tag.h>
00033 
00034 using namespace std;
00035 
00036 TagLib::String formatSeconds(int seconds)
00037 {
00038   char secondsString[3];
00039   sprintf(secondsString, "%02i", seconds);
00040   return secondsString;
00041 }
00042 
00043 int main(int argc, char *argv[])
00044 {
00045   for(int i = 1; i < argc; i++) {
00046 
00047     cout << "******************** \"" << argv[i] << "\" ********************" << endl;
00048 
00049     TagLib::FileRef f(argv[i]);
00050 
00051     if(!f.isNull() && f.tag()) {
00052 
00053       TagLib::Tag *tag = f.tag();
00054 
00055       cout << "-- TAG --" << endl;
00056       cout << "title - " << tag->title()   << endl;
00057       cout << "artist - " << tag->artist()  << endl;
00058       cout << "album - " << tag->album()   << endl;
00059       cout << "year - " << tag->year()    << endl;
00060       cout << "comment - " << tag->comment() << endl;
00061       cout << "track - " << tag->track()   << endl;
00062       cout << "genre - " << tag->genre()   << endl;
00063     }
00064 
00065     if(!f.isNull() && f.audioProperties()) {
00066 
00067       TagLib::AudioProperties *properties = f.audioProperties();
00068 
00069       int seconds = properties->length() % 60;
00070       int minutes = (properties->length() - seconds) / 60;
00071 
00072       cout << "-- AUDIO --" << endl;
00073       cout << "bitrate     - " << properties->bitrate() << endl;
00074       cout << "sample rate - " << properties->sampleRate() << endl;
00075       cout << "channels    - " << properties->channels() << endl;
00076       cout << "length      - " << minutes << ":" << formatSeconds(seconds) << endl;
00077     }    
00078   }
00079   return 0;
00080 }

Generated on Mon Aug 6 21:24:20 2007 for plai by  doxygen 1.5.1