[SCM] libgroove/upstream: fingerprint example: accept --raw parameter

andrewrk-guest at users.alioth.debian.org andrewrk-guest at users.alioth.debian.org
Mon Apr 21 07:10:45 UTC 2014


The following commit has been merged in the upstream branch:
commit bf235a687a017c03849157aba9b5c95128444151
Author: Andrew Kelley <superjoe30 at gmail.com>
Date:   Sun Apr 20 23:39:18 2014 -0700

    fingerprint example: accept --raw parameter

diff --git a/example/fingerprint.c b/example/fingerprint.c
index 4172004..c9fb37b 100644
--- a/example/fingerprint.c
+++ b/example/fingerprint.c
@@ -3,12 +3,17 @@
 #include <groovefingerprinter/fingerprinter.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+
+static int usage(char *arg0) {
+    fprintf(stderr, "Usage: %s [--raw] file1 file2 ...\n", arg0);
+    return 1;
+}
 
 int main(int argc, char * argv[]) {
-    if (argc < 2) {
-        fprintf(stderr, "Usage: %s file1 file2 ...\n", argv[0]);
-        return 1;
-    }
+    if (argc < 2)
+        return usage(argv[0]);
 
     groove_init();
     atexit(groove_finish);
@@ -16,14 +21,25 @@ int main(int argc, char * argv[]) {
 
     struct GroovePlaylist *playlist = groove_playlist_create();
 
+    int raw = 0;
+
     for (int i = 1; i < argc; i += 1) {
-        char * filename = argv[i];
-        struct GrooveFile * file = groove_file_open(filename);
-        if (!file) {
-            fprintf(stderr, "Unable to open %s\n", filename);
-            continue;
+        char *arg = argv[i];
+        if (arg[0] == '-' && arg[1] == '-') {
+            arg += 2;
+            if (strcmp(arg, "raw") == 0) {
+                raw = 1;
+            } else {
+                return usage(argv[0]);
+            }
+        } else {
+            struct GrooveFile * file = groove_file_open(arg);
+            if (!file) {
+                fprintf(stderr, "Unable to open %s\n", arg);
+                continue;
+            }
+            groove_playlist_insert(playlist, file, 1.0, NULL);
         }
-        groove_playlist_insert(playlist, file, 1.0, NULL);
     }
 
     struct GrooveFingerprinter *printer = groove_fingerprinter_create();
@@ -32,10 +48,19 @@ int main(int argc, char * argv[]) {
     struct GrooveFingerprinterInfo info;
     while (groove_fingerprinter_info_get(printer, &info, 1) == 1) {
         if (info.item) {
-            fprintf(stdout, "\nduration: %f: %s\n",
+            printf("\nduration: %f: %s\n",
                     info.duration,
                     info.item->file->filename);
-            fprintf(stdout, "%s\n", info.fingerprint);
+            if (raw) {
+                int size;
+                uint32_t *raw_fingerprint;
+                groove_fingerprinter_decode(info.fingerprint, (void*)&raw_fingerprint, &size);
+                for (int i = 0; i < size; i += 1) {
+                    printf("%"PRIu32"\n", raw_fingerprint[i]);
+                }
+            } else {
+                printf("%s\n", info.fingerprint);
+            }
             groove_fingerprinter_free_info(&info);
         } else {
             break;

-- 
libgroove packaging



More information about the pkg-multimedia-commits mailing list