Skip to content

Commit f439ab2

Browse files
Merge pull request #796 from g-maxime/json
Add JSON output for MediaConch reports
2 parents 705b57f + ec20513 commit f439ab2

15 files changed

+1615
-7
lines changed

Source/CLI/CLI.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ void __stdcall Event_CallBackFunction(unsigned char* Data_Content, size_t Data_S
240240
format = MediaConchLib::format_Html;
241241
else if (filename.size() >= 4 && filename.rfind(".csv") == filename.size() - 4)
242242
format = MediaConchLib::format_CSV;
243+
else if (filename.size() >= 5 && filename.rfind(".json") == filename.size() - 5)
244+
format = MediaConchLib::format_Json;
243245
else
244246
format = MediaConchLib::format_Simple;
245247

@@ -659,6 +661,8 @@ void __stdcall Event_CallBackFunction(unsigned char* Data_Content, size_t Data_S
659661
return set_format(MediaConchLib::format_Simple);
660662
else if (f == "CSV" || f == "csv")
661663
return set_format(MediaConchLib::format_CSV);
664+
else if (f == "JSON" || f == "json")
665+
return set_format(MediaConchLib::format_Json);
662666
else
663667
mi_inform = f;
664668

@@ -908,6 +912,8 @@ void __stdcall Event_CallBackFunction(unsigned char* Data_Content, size_t Data_S
908912
f = MediaConchLib::format_Html;
909913
else if (format == "csv")
910914
f = MediaConchLib::format_CSV;
915+
else if (format == "json")
916+
f = MediaConchLib::format_Json;
911917
else if (format == "simple")
912918
f = MediaConchLib::format_Simple;
913919
else

Source/CLI/CommandLine_Parser.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ static bool wait_for_another_argument(std::string& argument)
134134
}
135135
else if (argument=="-oj")
136136
{
137-
Last_Argument = "--output-jstree=";
137+
Last_Argument = "--output-json=";
138138
return true;
139139
}
140140
else if (argument=="-oh")
@@ -204,7 +204,7 @@ static void change_short_options_to_long(std::string& argument)
204204
if (argument=="-fa")
205205
argument = "--format=MAXML";
206206
if (argument=="-fj")
207-
argument = "--format=JSTREE";
207+
argument = "--format=JSON";
208208
if (argument=="-fh")
209209
argument = "--format=HTML";
210210
if (argument=="-fc")
@@ -289,7 +289,7 @@ int Parse(MediaConch::CLI* cli, std::string& argument)
289289
OPTION("--output-text", Output)
290290
OPTION("--output-xml", Output)
291291
OPTION("--output-maxml", Output)
292-
OPTION("--output-jstree", Output)
292+
OPTION("--output-json", Output)
293293
OPTION("--output-html", Output)
294294
OPTION("--output-csv", Output)
295295
OPTION("--output-simple", Output)

Source/CLI/Help.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ int Help()
8181
TEXTOUT(" (changed to -fa if there are more than 1 tool or more than 1 file)");
8282
TEXTOUT(" --Format=html, -fh");
8383
TEXTOUT(" Output MediaConch reports in HTML format");
84+
TEXTOUT(" --Format=json, -fj");
85+
TEXTOUT(" Output MediaConch reports in JSON format");
8486
TEXTOUT(" --Format=simple, -fs");
8587
TEXTOUT(" Output MediaConch reports in a shorten form");
8688
TEXTOUT(" (>1 line only if there are errors), default format");
@@ -102,6 +104,8 @@ int Help()
102104
TEXTOUT(" Output MediaConch reports in file in XML format");
103105
TEXTOUT(" Output-Html=file, -oh file");
104106
TEXTOUT(" Output MediaConch reports in file in HTML format");
107+
TEXTOUT(" Output-Json=file, -oj file");
108+
TEXTOUT(" Output MediaConch reports in file in JSON format");
105109
TEXTOUT(" Output-Simple=file, -os file");
106110
TEXTOUT(" Output MediaConch reports in file in a shorten form");
107111
TEXTOUT(" (>1 line only if there are errors), default format");

Source/Common/DaemonClient.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,8 @@ int DaemonClient::checker_get_report(CheckerReport& cr, MediaConchLib::Checker_R
677677
req.display_name = MediaConchLib::display_text_name;
678678
else if (cr.format == MediaConchLib::format_Html)
679679
req.display_name = MediaConchLib::display_html_name;
680+
else if (cr.format == MediaConchLib::format_Json)
681+
req.display_name = MediaConchLib::display_json_name;
680682
else if (cr.format == MediaConchLib::format_JsTree)
681683
req.display_name = MediaConchLib::display_jstree_name;
682684
else if (cr.format == MediaConchLib::format_Simple)

Source/Common/MediaConchLib.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const std::string MediaConchLib::display_xml_name = std::string("XML");
3838
const std::string MediaConchLib::display_maxml_name = std::string("MAXML");
3939
const std::string MediaConchLib::display_text_name = std::string("TEXT");
4040
const std::string MediaConchLib::display_html_name = std::string("HTML");
41+
const std::string MediaConchLib::display_json_name = std::string("JSON");
4142
const std::string MediaConchLib::display_jstree_name = std::string("JSTREE");
4243
const std::string MediaConchLib::display_simple_name = std::string("SIMPLE");
4344
const std::string MediaConchLib::display_csv_name = std::string("CSV");

Source/Common/MediaConchLib.h

+2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class MediaConchLib
8282
format_OrigXml,
8383
format_Simple,
8484
format_CSV,
85+
format_Json,
8586
format_Max,
8687
};
8788

@@ -286,6 +287,7 @@ class MediaConchLib
286287
static const std::string display_maxml_name;
287288
static const std::string display_text_name;
288289
static const std::string display_html_name;
290+
static const std::string display_json_name;
289291
static const std::string display_jstree_name;
290292
static const std::string display_simple_name;
291293
static const std::string display_csv_name;

Source/Common/Reports.cpp

+22-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "Common/generated/ImplementationReportVeraPDFXsl.h"
2424
#include "Common/generated/ImplementationReportDPFManagerXsl.h"
2525
#include "Common/generated/ImplementationReportDisplayHtmlXsl.h"
26+
#include "Common/generated/ImplementationReportDisplayJsonXsl.h"
2627
#include "Common/generated/ImplementationReportDisplayCSVXsl.h"
2728
#include "Common/generated/ImplementationReportDisplaySimpleXsl.h"
2829
#if defined(_WIN32) || defined(WIN32)
@@ -69,6 +70,8 @@ int Reports::checker_get_report(CheckerReport& cr, MediaConchLib::Checker_Report
6970
transform_with_xslt_text_memory(result->report, result->report);
7071
else if (cr.format == MediaConchLib::format_Html)
7172
transform_with_xslt_html_memory(result->report, result->report);
73+
else if (cr.format == MediaConchLib::format_Json)
74+
transform_with_xslt_json_memory(result->report, result->report);
7275
else if (cr.format == MediaConchLib::format_Simple)
7376
transform_with_xslt_simple_memory(result->report, result->report);
7477
else if (cr.format == MediaConchLib::format_CSV)
@@ -93,6 +96,7 @@ int Reports::checker_get_report(CheckerReport& cr, MediaConchLib::Checker_Report
9396
case MediaConchLib::format_Xml:
9497
case MediaConchLib::format_MaXml:
9598
case MediaConchLib::format_Html:
99+
case MediaConchLib::format_Json:
96100
case MediaConchLib::format_OrigXml:
97101
case MediaConchLib::format_Simple:
98102
case MediaConchLib::format_CSV:
@@ -280,6 +284,8 @@ int Reports::get_reports_output(int user, const std::vector<long>& files,
280284
{
281285
// No transformation for XML
282286
}
287+
else if (f == MediaConchLib::format_Json)
288+
transform_with_xslt_json_memory(tmp, tmp);
283289
else if (f == MediaConchLib::format_Simple)
284290
transform_with_xslt_simple_memory(tmp, tmp);
285291
else if (f == MediaConchLib::format_CSV)
@@ -335,6 +341,8 @@ int Reports::get_reports_output(int user, const std::vector<long>& files,
335341
{
336342
if (f == MediaConchLib::format_Html)
337343
transform_with_xslt_html_memory(transformed, transformed);
344+
else if (f == MediaConchLib::format_Json)
345+
transform_with_xslt_json_memory(transformed, transformed);
338346
else if (f == MediaConchLib::format_Simple)
339347
transform_with_xslt_simple_memory(transformed, transformed);
340348
else if (f == MediaConchLib::format_CSV)
@@ -380,7 +388,9 @@ int Reports::get_reports_output(int user, const std::vector<long>& files,
380388
{
381389
if (f == MediaConchLib::format_Html)
382390
transform_with_xslt_html_memory(transformed, transformed);
383-
if (f == MediaConchLib::format_Simple)
391+
else if (f == MediaConchLib::format_Json)
392+
transform_with_xslt_json_memory(transformed, transformed);
393+
else if (f == MediaConchLib::format_Simple)
384394
transform_with_xslt_simple_memory(transformed, transformed);
385395
else if (f == MediaConchLib::format_CSV)
386396
transform_with_xslt_csv_memory(transformed, transformed);
@@ -416,7 +426,9 @@ int Reports::get_reports_output(int user, const std::vector<long>& files,
416426
{
417427
if (f == MediaConchLib::format_Html)
418428
transform_with_xslt_html_memory(report, report);
419-
if (f == MediaConchLib::format_Simple)
429+
else if (f == MediaConchLib::format_Json)
430+
transform_with_xslt_json_memory(report, report);
431+
else if (f == MediaConchLib::format_Simple)
420432
transform_with_xslt_simple_memory(report, report);
421433
else if (f == MediaConchLib::format_CSV)
422434
transform_with_xslt_csv_memory(report, report);
@@ -1315,6 +1327,14 @@ int Reports::transform_with_xslt_html_memory(const std::string& report, std::str
13151327
return transform_with_xslt_memory(report, memory, opts, result);
13161328
}
13171329

1330+
//---------------------------------------------------------------------------
1331+
int Reports::transform_with_xslt_json_memory(const std::string& report, std::string& result)
1332+
{
1333+
std::map<std::string, std::string> opts;
1334+
std::string memory(implementation_report_display_json_xsl);
1335+
return transform_with_xslt_memory(report, memory, opts, result);
1336+
}
1337+
13181338
//---------------------------------------------------------------------------
13191339
int Reports::transform_with_xslt_simple_memory(const std::string& report, std::string& result)
13201340
{

Source/Common/Reports.h

+1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ class Reports
127127
const std::map<std::string, std::string>& opts, std::string& result);
128128
int transform_with_xslt_text_memory(const std::string& report, std::string& result);
129129
int transform_with_xslt_html_memory(const std::string& report, std::string& result);
130+
int transform_with_xslt_json_memory(const std::string& report, std::string& result);
130131
int transform_with_xslt_simple_memory(const std::string& report, std::string& result);
131132
int transform_with_xslt_csv_memory(const std::string& report, std::string& result);
132133

0 commit comments

Comments
 (0)