[gexiv2] Add option to print unknown tags in gexiv2-tool



commit 26b6323c4e9d5096b58d158b9cfa84af0b9b1706
Author: postscript-dev <43813-postscript-dev users noreply gitlab gnome org>
Date:   Tue Jul 13 18:18:02 2021 +0100

    Add option to print unknown tags in gexiv2-tool
    
    Changes:
    + Add `-u` switch to optionally remove unknown tags from output
      (e.g. `Exif.Sony2Fp.0x018f`). Default is to remove the tags (which is
      the same as `exiv2.exe`).
    + Fix indenting and spelling mistake

 tools/gexiv2-tool.vala | 47 +++++++++++++++++++++++++++++------------------
 1 file changed, 29 insertions(+), 18 deletions(-)
---
diff --git a/tools/gexiv2-tool.vala b/tools/gexiv2-tool.vala
index 54c32bc..1cedd35 100644
--- a/tools/gexiv2-tool.vala
+++ b/tools/gexiv2-tool.vala
@@ -7,13 +7,14 @@
  * This is free software. See COPYING for details.
  */
 
-// Global variables used in parsing program paramters
+// Global variables used in parsing program parameters
 bool print_exif_tags = false;
 bool print_iptc_tags = false;
 bool print_xmp_tags = false;
 bool print_xmp_ns = false;
 bool print_tag_details = false;
 string print_single_tag;
+bool print_unknown_tags = false;
 
 // Command line optional parameters
 const GLib.OptionEntry[] options = {
@@ -35,6 +36,9 @@ const GLib.OptionEntry[] options = {
     // [-tag TAG]
     {"tag", 't', 0, OptionArg.STRING, ref print_single_tag, "Only print a specific tag's data from FILE 
(overrides -e, -i and -x)", null},
 
+    // [-u]
+    {"tag", 'u', 0, OptionArg.NONE, ref print_unknown_tags, "Include unknown tags when printing (e.g. 
Exif.Sony2Fp.0x018f)", null},
+
     // list terminator
     {null}
 };
@@ -74,6 +78,7 @@ int main(string[] args) {
         desc = desc + " \n";
         desc = desc + "Examples:\n";
         desc = desc + "  " + program_name + " FILE                         - Print all the tags in FILE 
(\"-e -i -x\")\n";
+        desc = desc + "  " + program_name + " -u FILE                      - Print all the tags (including 
unknown ones) in FILE (\"-u -d -e -i -x\")\n";
         desc = desc + "  " + program_name + " -d FILE                      - Print all the tag details in 
FILE (\"-d -e -i -x\")\n";
         desc = desc + "  " + program_name + " -x -n FILE                   - Print the Xmp namespaces and 
Xmp tag values in FILE\n";
         desc = desc + "  " + program_name + " -d -e -i FILE                - Print the Exif and Iptc tag 
details in FILE\n";
@@ -123,7 +128,7 @@ int main(string[] args) {
                     string[] tags = {print_single_tag};
                     print_all_xmp_namespaces(tags);
                 }
-                print_tag(metadata, print_single_tag, print_tag_details);
+                print_tag(metadata, print_single_tag, print_unknown_tags, print_tag_details);
             } else {
                 string error_message = "Tag `" + print_single_tag + "' not found in metadata";
                 throw new GLib.Error(Quark.from_string(program_name), 1, error_message);
@@ -134,19 +139,19 @@ int main(string[] args) {
             }
             if (print_exif_tags) {
                 foreach (var tag in exif_tags) {
-                    print_tag(metadata, tag, print_tag_details);
+                    print_tag(metadata, tag, print_unknown_tags, print_tag_details);
                 }
             }
             if (print_iptc_tags) {
                 foreach (var tag in iptc_tags) {
-                    print_tag(metadata, tag, print_tag_details);
+                    print_tag(metadata, tag, print_unknown_tags, print_tag_details);
                 }
             }
             if (print_xmp_tags) {
-               foreach (var tag in xmp_tags) {
-                    print_tag(metadata, tag, print_tag_details);
+                foreach (var tag in xmp_tags) {
+                    print_tag(metadata, tag, print_unknown_tags, print_tag_details);
                 }
-             }
+            }
         }
     } catch (OptionError e) {
         printerr("%s error: %s\n", program_name, e.message);
@@ -168,22 +173,28 @@ int main(string[] args) {
  * print_tag:
  * @metadata: An instance of #GExiv2Metadata
  * @tag: The tag to print out
+ * @print_unknown_tags: Whether to include unknown tags in the output
  * @print_details: Whether to print the tag details in addition to the tag value
  *
- * Prints out either the tag values or the tag details for the tag
+ * Prints out either the tag values or the tag details for the tag. If the tag
+ * is unknown (e.g. Exif.Sony2Fp.0x018f) then printing is optionally filtered 
+ * out. 
  *
  * Returns:
  */
-void print_tag(GExiv2.Metadata metadata, string tag, bool print_details) throws Error {
-    if (print_details) {
-        print("%-64s%s\n", "Tag", tag);
-        print("%-64s%s\n", "  Value", metadata.try_get_tag_string(tag));
-        print("%-64s%s\n", "  Interpreted value", metadata.try_get_tag_interpreted_string(tag));
-        print("%-64s%s\n", "  Label", GExiv2.Metadata.try_get_tag_label(tag));
-        print("%-64s%s\n", "  Type", GExiv2.Metadata.try_get_tag_type(tag));
-        print("%-64s%s\n", "  Description", GExiv2.Metadata.try_get_tag_description(tag));
-    } else {
-        print("%-64s%s\n", tag, metadata.try_get_tag_interpreted_string(tag));
+void print_tag(GExiv2.Metadata metadata, string tag, bool print_unknown_tags, bool print_details) throws 
Error {
+
+    if (print_unknown_tags || !(".0x" in tag)) {
+        if (print_details) {
+            print("%-64s%s\n", "Tag", tag);
+            print("%-64s%s\n", "  Value", metadata.try_get_tag_string(tag));
+            print("%-64s%s\n", "  Interpreted value", metadata.try_get_tag_interpreted_string(tag));
+            print("%-64s%s\n", "  Label", GExiv2.Metadata.try_get_tag_label(tag));
+            print("%-64s%s\n", "  Type", GExiv2.Metadata.try_get_tag_type(tag));
+            print("%-64s%s\n", "  Description", GExiv2.Metadata.try_get_tag_description(tag));
+        } else {
+            print("%-64s%s\n", tag, metadata.try_get_tag_interpreted_string(tag));
+        }
     }
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]