summaryrefslogtreecommitdiffstats
path: root/taglib-sharp/extractKey.cpp
blob: 859ea736361a088f4b953096869af9722998b333 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <exiv2/image.hpp>
#include <exiv2/exif.hpp>
#include <iostream>
#include <iomanip>
#include <cassert>

int main(int argc, char* const argv[])

try {
    if (argc != 3) {
        std::cout << "Usage: " << argv[0] << " file key\n";
        return 1;
    }

    Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(argv[1]);
    assert(image.get() != 0);
    image->readMetadata();

	try {
		Exiv2::ExifData &exifData = image->exifData();
		const Exiv2::Value &value = exifData[argv[2]].value();
		std::cout << value;
	} catch (Exiv2::AnyError &e) {}

	try {
		Exiv2::IptcData &iptcData = image->iptcData();
		const Exiv2::Value &value = iptcData[argv[2]].value();
		std::cout << value;
	} catch (Exiv2::AnyError &e) {}

	try {
		Exiv2::XmpData &xmpData = image->xmpData();
		const Exiv2::Value &value = xmpData[argv[2]].value();
		std::cout << value;
	} catch (Exiv2::AnyError &e) {}

    return 0;
} catch (Exiv2::AnyError& e) {
    std::cout << "Caught Exiv2 exception '" << e << "'\n";
    return -1;
}