mirror of
https://github.com/taglib/taglib.git
synced 2025-07-21 06:24:19 -04:00
Examples: adds picture handling
This commit is contained in:
@ -28,6 +28,7 @@
|
||||
|
||||
#include <fileref.h>
|
||||
#include <tag.h>
|
||||
#include <tpicturemap.h>
|
||||
#include <tpropertymap.h>
|
||||
|
||||
using namespace std;
|
||||
@ -45,13 +46,15 @@ int main(int argc, char *argv[])
|
||||
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;
|
||||
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(!tag->pictures().isEmpty())
|
||||
cout << "pictures -" << tag->pictures() << endl;
|
||||
|
||||
TagLib::PropertyMap tags = f.file()->properties();
|
||||
|
||||
|
@ -22,7 +22,9 @@
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string.h>
|
||||
|
||||
#include <stdio.h>
|
||||
@ -33,6 +35,8 @@
|
||||
#include <tlist.h>
|
||||
#include <fileref.h>
|
||||
#include <tfile.h>
|
||||
#include <tpicturemap.h>
|
||||
|
||||
#include <tag.h>
|
||||
|
||||
using namespace std;
|
||||
@ -65,6 +69,7 @@ void usage()
|
||||
cout << " -g <genre>" << endl;
|
||||
cout << " -y <year>" << endl;
|
||||
cout << " -T <track>" << endl;
|
||||
cout << " -p <picture(jpg only, file between double quotes)>" << endl;
|
||||
cout << endl;
|
||||
|
||||
exit(1);
|
||||
@ -87,14 +92,16 @@ int main(int argc, char *argv[])
|
||||
if(fileList.isEmpty())
|
||||
usage();
|
||||
|
||||
if(argv[argc-1][1] == 'p')
|
||||
argc++;
|
||||
|
||||
for(int i = 1; i < argc - 1; i += 2) {
|
||||
|
||||
if(isArgument(argv[i]) && i + 1 < argc && !isArgument(argv[i + 1])) {
|
||||
|
||||
char field = argv[i][1];
|
||||
TagLib::String value = argv[i + 1];
|
||||
|
||||
TagLib::List<TagLib::FileRef>::ConstIterator it;
|
||||
TagLib::List<TagLib::FileRef>::Iterator it;
|
||||
for(it = fileList.begin(); it != fileList.end(); ++it) {
|
||||
|
||||
TagLib::Tag *t = (*it).tag();
|
||||
@ -121,6 +128,33 @@ int main(int argc, char *argv[])
|
||||
case 'T':
|
||||
t->setTrack(value.toInt());
|
||||
break;
|
||||
case 'p':
|
||||
{
|
||||
if(!isFile(value.toCString()))
|
||||
{
|
||||
cout << value.toCString() << " not found." << endl;
|
||||
return 1;
|
||||
}
|
||||
ifstream picture;
|
||||
picture.open(value.toCString());
|
||||
stringstream buffer;
|
||||
buffer << picture.rdbuf();
|
||||
picture.close();
|
||||
TagLib::String buf(buffer.str());
|
||||
TagLib::ByteVector data(buf.data(TagLib::String::Latin1));
|
||||
if(!data.find("JFIF"))
|
||||
{
|
||||
cout << value.toCString() << " is not a JPEG." << endl;
|
||||
return 1;
|
||||
}
|
||||
TagLib::Picture pic(data,
|
||||
TagLib::Picture::FrontCover,
|
||||
"image/jpeg",
|
||||
"Added with taglib");
|
||||
TagLib::PictureMap picMap(pic);
|
||||
t->setPictures(picMap);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
break;
|
||||
|
Reference in New Issue
Block a user