Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JSON output for MediaConch reports #796

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Source/CLI/CLI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ void __stdcall Event_CallBackFunction(unsigned char* Data_Content, size_t Data_S
format = MediaConchLib::format_Html;
else if (filename.size() >= 4 && filename.rfind(".csv") == filename.size() - 4)
format = MediaConchLib::format_CSV;
else if (filename.size() >= 5 && filename.rfind(".json") == filename.size() - 5)
format = MediaConchLib::format_Json;
else
format = MediaConchLib::format_Simple;

Expand Down Expand Up @@ -659,6 +661,8 @@ void __stdcall Event_CallBackFunction(unsigned char* Data_Content, size_t Data_S
return set_format(MediaConchLib::format_Simple);
else if (f == "CSV" || f == "csv")
return set_format(MediaConchLib::format_CSV);
else if (f == "JSON" || f == "json")
return set_format(MediaConchLib::format_Json);
else
mi_inform = f;

Expand Down Expand Up @@ -908,6 +912,8 @@ void __stdcall Event_CallBackFunction(unsigned char* Data_Content, size_t Data_S
f = MediaConchLib::format_Html;
else if (format == "csv")
f = MediaConchLib::format_CSV;
else if (format == "json")
f = MediaConchLib::format_Json;
else if (format == "simple")
f = MediaConchLib::format_Simple;
else
Expand Down
6 changes: 3 additions & 3 deletions Source/CLI/CommandLine_Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ static bool wait_for_another_argument(std::string& argument)
}
else if (argument=="-oj")
{
Last_Argument = "--output-jstree=";
Last_Argument = "--output-json=";
return true;
}
else if (argument=="-oh")
Expand Down Expand Up @@ -204,7 +204,7 @@ static void change_short_options_to_long(std::string& argument)
if (argument=="-fa")
argument = "--format=MAXML";
if (argument=="-fj")
argument = "--format=JSTREE";
argument = "--format=JSON";
if (argument=="-fh")
argument = "--format=HTML";
if (argument=="-fc")
Expand Down Expand Up @@ -289,7 +289,7 @@ int Parse(MediaConch::CLI* cli, std::string& argument)
OPTION("--output-text", Output)
OPTION("--output-xml", Output)
OPTION("--output-maxml", Output)
OPTION("--output-jstree", Output)
OPTION("--output-json", Output)
OPTION("--output-html", Output)
OPTION("--output-csv", Output)
OPTION("--output-simple", Output)
Expand Down
4 changes: 4 additions & 0 deletions Source/CLI/Help.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ int Help()
TEXTOUT(" (changed to -fa if there are more than 1 tool or more than 1 file)");
TEXTOUT(" --Format=html, -fh");
TEXTOUT(" Output MediaConch reports in HTML format");
TEXTOUT(" --Format=json, -fj");
TEXTOUT(" Output MediaConch reports in JSON format");
TEXTOUT(" --Format=simple, -fs");
TEXTOUT(" Output MediaConch reports in a shorten form");
TEXTOUT(" (>1 line only if there are errors), default format");
Expand All @@ -102,6 +104,8 @@ int Help()
TEXTOUT(" Output MediaConch reports in file in XML format");
TEXTOUT(" Output-Html=file, -oh file");
TEXTOUT(" Output MediaConch reports in file in HTML format");
TEXTOUT(" Output-Json=file, -oj file");
TEXTOUT(" Output MediaConch reports in file in JSON format");
TEXTOUT(" Output-Simple=file, -os file");
TEXTOUT(" Output MediaConch reports in file in a shorten form");
TEXTOUT(" (>1 line only if there are errors), default format");
Expand Down
2 changes: 2 additions & 0 deletions Source/Common/DaemonClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,8 @@ int DaemonClient::checker_get_report(CheckerReport& cr, MediaConchLib::Checker_R
req.display_name = MediaConchLib::display_text_name;
else if (cr.format == MediaConchLib::format_Html)
req.display_name = MediaConchLib::display_html_name;
else if (cr.format == MediaConchLib::format_Json)
req.display_name = MediaConchLib::display_json_name;
else if (cr.format == MediaConchLib::format_JsTree)
req.display_name = MediaConchLib::display_jstree_name;
else if (cr.format == MediaConchLib::format_Simple)
Expand Down
1 change: 1 addition & 0 deletions Source/Common/MediaConchLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const std::string MediaConchLib::display_xml_name = std::string("XML");
const std::string MediaConchLib::display_maxml_name = std::string("MAXML");
const std::string MediaConchLib::display_text_name = std::string("TEXT");
const std::string MediaConchLib::display_html_name = std::string("HTML");
const std::string MediaConchLib::display_json_name = std::string("JSON");
const std::string MediaConchLib::display_jstree_name = std::string("JSTREE");
const std::string MediaConchLib::display_simple_name = std::string("SIMPLE");
const std::string MediaConchLib::display_csv_name = std::string("CSV");
Expand Down
2 changes: 2 additions & 0 deletions Source/Common/MediaConchLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class MediaConchLib
format_OrigXml,
format_Simple,
format_CSV,
format_Json,
format_Max,
};

Expand Down Expand Up @@ -286,6 +287,7 @@ class MediaConchLib
static const std::string display_maxml_name;
static const std::string display_text_name;
static const std::string display_html_name;
static const std::string display_json_name;
static const std::string display_jstree_name;
static const std::string display_simple_name;
static const std::string display_csv_name;
Expand Down
24 changes: 22 additions & 2 deletions Source/Common/Reports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "Common/generated/ImplementationReportVeraPDFXsl.h"
#include "Common/generated/ImplementationReportDPFManagerXsl.h"
#include "Common/generated/ImplementationReportDisplayHtmlXsl.h"
#include "Common/generated/ImplementationReportDisplayJsonXsl.h"
#include "Common/generated/ImplementationReportDisplayCSVXsl.h"
#include "Common/generated/ImplementationReportDisplaySimpleXsl.h"
#if defined(_WIN32) || defined(WIN32)
Expand Down Expand Up @@ -69,6 +70,8 @@ int Reports::checker_get_report(CheckerReport& cr, MediaConchLib::Checker_Report
transform_with_xslt_text_memory(result->report, result->report);
else if (cr.format == MediaConchLib::format_Html)
transform_with_xslt_html_memory(result->report, result->report);
else if (cr.format == MediaConchLib::format_Json)
transform_with_xslt_json_memory(result->report, result->report);
else if (cr.format == MediaConchLib::format_Simple)
transform_with_xslt_simple_memory(result->report, result->report);
else if (cr.format == MediaConchLib::format_CSV)
Expand All @@ -93,6 +96,7 @@ int Reports::checker_get_report(CheckerReport& cr, MediaConchLib::Checker_Report
case MediaConchLib::format_Xml:
case MediaConchLib::format_MaXml:
case MediaConchLib::format_Html:
case MediaConchLib::format_Json:
case MediaConchLib::format_OrigXml:
case MediaConchLib::format_Simple:
case MediaConchLib::format_CSV:
Expand Down Expand Up @@ -280,6 +284,8 @@ int Reports::get_reports_output(int user, const std::vector<long>& files,
{
// No transformation for XML
}
else if (f == MediaConchLib::format_Json)
transform_with_xslt_json_memory(tmp, tmp);
else if (f == MediaConchLib::format_Simple)
transform_with_xslt_simple_memory(tmp, tmp);
else if (f == MediaConchLib::format_CSV)
Expand Down Expand Up @@ -335,6 +341,8 @@ int Reports::get_reports_output(int user, const std::vector<long>& files,
{
if (f == MediaConchLib::format_Html)
transform_with_xslt_html_memory(transformed, transformed);
else if (f == MediaConchLib::format_Json)
transform_with_xslt_json_memory(transformed, transformed);
else if (f == MediaConchLib::format_Simple)
transform_with_xslt_simple_memory(transformed, transformed);
else if (f == MediaConchLib::format_CSV)
Expand Down Expand Up @@ -380,7 +388,9 @@ int Reports::get_reports_output(int user, const std::vector<long>& files,
{
if (f == MediaConchLib::format_Html)
transform_with_xslt_html_memory(transformed, transformed);
if (f == MediaConchLib::format_Simple)
else if (f == MediaConchLib::format_Json)
transform_with_xslt_json_memory(transformed, transformed);
else if (f == MediaConchLib::format_Simple)
transform_with_xslt_simple_memory(transformed, transformed);
else if (f == MediaConchLib::format_CSV)
transform_with_xslt_csv_memory(transformed, transformed);
Expand Down Expand Up @@ -416,7 +426,9 @@ int Reports::get_reports_output(int user, const std::vector<long>& files,
{
if (f == MediaConchLib::format_Html)
transform_with_xslt_html_memory(report, report);
if (f == MediaConchLib::format_Simple)
else if (f == MediaConchLib::format_Json)
transform_with_xslt_json_memory(report, report);
else if (f == MediaConchLib::format_Simple)
transform_with_xslt_simple_memory(report, report);
else if (f == MediaConchLib::format_CSV)
transform_with_xslt_csv_memory(report, report);
Expand Down Expand Up @@ -1315,6 +1327,14 @@ int Reports::transform_with_xslt_html_memory(const std::string& report, std::str
return transform_with_xslt_memory(report, memory, opts, result);
}

//---------------------------------------------------------------------------
int Reports::transform_with_xslt_json_memory(const std::string& report, std::string& result)
{
std::map<std::string, std::string> opts;
std::string memory(implementation_report_display_json_xsl);
return transform_with_xslt_memory(report, memory, opts, result);
}

//---------------------------------------------------------------------------
int Reports::transform_with_xslt_simple_memory(const std::string& report, std::string& result)
{
Expand Down
1 change: 1 addition & 0 deletions Source/Common/Reports.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class Reports
const std::map<std::string, std::string>& opts, std::string& result);
int transform_with_xslt_text_memory(const std::string& report, std::string& result);
int transform_with_xslt_html_memory(const std::string& report, std::string& result);
int transform_with_xslt_json_memory(const std::string& report, std::string& result);
int transform_with_xslt_simple_memory(const std::string& report, std::string& result);
int transform_with_xslt_csv_memory(const std::string& report, std::string& result);

Expand Down
Loading
Loading