From 3a1afc550b24da9b0c3a8bf37d8eeb0b55c96723 Mon Sep 17 00:00:00 2001
From: Julian Rother <julianr@fsmpi.rwth-aachen.de>
Date: Mon, 27 Nov 2017 01:11:51 +0100
Subject: [PATCH] Added json_filenifo function

---
 remux.c              | 3 ++-
 transcode.c          | 4 ++--
 util.h               | 1 +
 util/json_fileinfo.c | 7 +++++++
 4 files changed, 12 insertions(+), 3 deletions(-)
 create mode 100644 util/json_fileinfo.c

diff --git a/remux.c b/remux.c
index 1297bfc..d50aa6f 100644
--- a/remux.c
+++ b/remux.c
@@ -77,6 +77,7 @@ int main(int argc, char *argv[])
 	if (rename(tmp, path))
 		job_failed("Overwriting output file failed: %s", strerror(errno));
 	unlink(tmp);
-	ping_job(jobid, "finished", "{\"log\": \"%s\"}", jescape(get_avlogbuf()));
+	ping_job(jobid, "finished", "{%s, \"log\": \"%s\"}", json_fileinfo(path),
+			jescape(get_avlogbuf()));
 	return 0;
 }
diff --git a/transcode.c b/transcode.c
index 42f179b..7dae08b 100644
--- a/transcode.c
+++ b/transcode.c
@@ -359,7 +359,7 @@ int main(int argc, char *argv[])
 	if (rename(tmppath, outpath))
 		job_failed("Overwriting output file \"%s\" failed: %s", outpath, strerror(errno));
 	unlink(tmppath);
-	ping_job(jobid, "finished", "{\"hash\": \"%s\", \"duration\": %f, \"filesize\": %i, \"log\": \"%s\"}",
-			hashfile(outpath), fileduration(outpath), filesize(outpath), jescape(get_avlogbuf()));
+	ping_job(jobid, "finished", "{%s, \"log\": \"%s\"}", json_fileinfo(outpath),
+			jescape(get_avlogbuf()));
 	return 0;
 }
diff --git a/util.h b/util.h
index d9e9da1..aa000f8 100644
--- a/util.h
+++ b/util.h
@@ -15,6 +15,7 @@ void *xmalloc(size_t size);
 char *hashfile(char *path);
 double fileduration(char *path);
 size_t filesize(char *path);
+char *json_fileinfo(char *path);
 
 /* JSON av parsing */
 void parse_dict(AVDictionary **d, char *s);
diff --git a/util/json_fileinfo.c b/util/json_fileinfo.c
new file mode 100644
index 0000000..b03f564
--- /dev/null
+++ b/util/json_fileinfo.c
@@ -0,0 +1,7 @@
+#include "../util.h"
+
+char *json_fileinfo(char *path)
+{
+	return mprintf("\"hash\": \"%s\", \"duration\": %f, \"filesize\": %i",
+			hashfile(path), fileduration(path), filesize(path));
+}
-- 
GitLab