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

Rework JSON output #1011

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
52 changes: 45 additions & 7 deletions Source/MediaInfo/MediaInfo_Inform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,14 @@ Ztring MediaInfo_Internal::Inform()
#if defined(MEDIAINFO_XML_YES) || defined(MEDIAINFO_JSON_YES)
Node* Node_Main=NULL;
Node* Node_MI=NULL;
Node* Node_Tracks=NULL;
#endif //MEDIAINFO_XML_YES || MEDIAINFO_JSON_YES
Ztring Retour;
bool HTML=false;
bool XML=false;
bool XML_0_7_78_MA=false;
bool XML_0_7_78_MI=false;
bool OLDJSON=false;
bool JSON=false;
bool CSV=false;
#if defined(MEDIAINFO_HTML_YES)
Expand All @@ -322,9 +324,14 @@ Ztring MediaInfo_Internal::Inform()
if (MediaInfoLib::Config.Inform_Get()==__T("MIXML") || MediaInfoLib::Config.Inform_Get()==__T("XML"))
XML_0_7_78_MI=true;
#endif //defined(MEDIAINFO_XML_YES)
#if defined(MEDIAINFO_JSON_YES)
#if defined(MEDIAINFO_JSON_YES)
if (MediaInfoLib::Config.Inform_Get()==__T("JSON"))
JSON=true;
if (MediaInfoLib::Config.Inform_Get()==__T("OLDJSON"))
{
JSON=true;
OLDJSON=true;
}
#endif //defined(MEDIAINFO_JSON_YES)
#if defined(MEDIAINFO_CSV_YES)
if (MediaInfoLib::Config.Inform_Get()==__T("CSV"))
Expand All @@ -334,7 +341,7 @@ Ztring MediaInfo_Internal::Inform()
if (HTML)
Retour+=__T("<html>\n\n<head>\n<META http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /></head>\n<body>\n");
#if defined(MEDIAINFO_XML_YES) || defined(MEDIAINFO_JSON_YES)
if (XML_0_7_78_MA || XML_0_7_78_MI || JSON)
if (XML_0_7_78_MA || XML_0_7_78_MI || OLDJSON)
{
Node_Main=new Node("media");
Ztring Options=Get(Stream_General, 0, General_CompleteName, Info_Options);
Expand All @@ -357,6 +364,17 @@ Ztring MediaInfo_Internal::Inform()
else
Node_Main=new Node("File");
}
if (JSON && !OLDJSON)
{
Node_Main=new Node("Media");
Ztring Options=Get(Stream_General, 0, General_CompleteName, Info_Options);
if (InfoOption_ShowInInform<Options.size() && Options[InfoOption_ShowInInform]==__T('Y'))
Node_Main->Add_Attribute("Ref", Get(Stream_General, 0, General_CompleteName));
if (Info && !Info->ParserName.empty())
Node_Main->Add_Attribute("Parser", Info->ParserName);

Node_Tracks=Node_Main->Add_Child("Tracks");
}
#endif //defined(MEDIAINFO_XML_YES) || defined(MEDIAINFO_JSON_YES)

for (size_t StreamKind=(size_t)Stream_General; StreamKind<Stream_Max; StreamKind++)
Expand All @@ -368,7 +386,7 @@ Ztring MediaInfo_Internal::Inform()
if (HTML) Retour+=__T("<table width=\"100%\" border=\"0\" cellpadding=\"1\" cellspacing=\"2\" style=\"border:1px solid Navy\">\n<tr>\n <td width=\"150\"><h2>");
#if defined(MEDIAINFO_XML_YES) || defined(MEDIAINFO_JSON_YES)
Node* Node_Current=NULL;
if (XML || XML_0_7_78_MA || XML_0_7_78_MI || JSON) Node_Current=Node_MI?Node_MI->Add_Child("track", true):Node_Main->Add_Child("track", true);
if (XML || XML_0_7_78_MA || XML_0_7_78_MI || OLDJSON) Node_Current=Node_MI?Node_MI->Add_Child("track", true):Node_Main->Add_Child("track", true);
#endif //defined(MEDIAINFO_XML_YES) || defined(MEDIAINFO_JSON_YES)
Ztring A=Get((stream_t)StreamKind, StreamPos, __T("StreamKind/String"));
Ztring B=Get((stream_t)StreamKind, StreamPos, __T("StreamKindPos"));
Expand All @@ -386,14 +404,27 @@ Ztring MediaInfo_Internal::Inform()
}
if (HTML) Retour+=__T("</h2></td>\n </tr>");
#if defined(MEDIAINFO_XML_YES) || defined(MEDIAINFO_JSON_YES)
if (XML || XML_0_7_78_MA || XML_0_7_78_MI || JSON)
if (XML || XML_0_7_78_MA || XML_0_7_78_MI || OLDJSON)
{
Node_Current->Add_Attribute("type", A);
if (!B.empty()) Node_Current->Add_Attribute("typeorder", B);
Node* Track=new Node();
Track->RawContent=Inform((stream_t)StreamKind, StreamPos, false).To_UTF8();
Node_Current->Childs.push_back(Track);
}
else if (JSON && !OLDJSON)
{
Node_Current=Node_Tracks->Add_Child(A.To_UTF8(), true);

Node* Track=new Node();
Ztring TrackContent=Inform((stream_t)StreamKind, StreamPos, false);
if (!TrackContent.empty())
{
if (!B.empty()) Track->RawContent="\"Typeorder\": \"" + B.To_UTF8() + "\",\n";
Track->RawContent+=TrackContent.To_UTF8();
Node_Current->Childs.push_back(Track);
}
}
else
#endif //defined(MEDIAINFO_XML_YES) || defined(MEDIAINFO_JSON_YES)
{
Expand Down Expand Up @@ -476,6 +507,7 @@ Ztring MediaInfo_Internal::Inform (stream_t StreamKind, size_t StreamPos, bool I
#if defined(MEDIAINFO_XML_YES) || defined(MEDIAINFO_JSON_YES)
bool XML=false;
bool XML_0_7_78=false;
bool OLDJSON=false;
bool JSON=false;
std::vector<Node*> Nodes;
#endif //MEDIAINFO_XML_YES || MEDIAINFO_JSON_YES
Expand All @@ -490,7 +522,13 @@ Ztring MediaInfo_Internal::Inform (stream_t StreamKind, size_t StreamPos, bool I
XML=true;
#endif //defined(MEDIAINFO_XML_YES)
#if defined(MEDIAINFO_JSON_YES)
JSON=MediaInfoLib::Config.Inform_Get()==__T("JSON")?true:false;
if (MediaInfoLib::Config.Inform_Get()==__T("JSON"))
JSON=true;
if (MediaInfoLib::Config.Inform_Get()==__T("OLDJSON"))
{
JSON=true;
OLDJSON=true;
}
#endif //defined(MEDIAINFO_JSON_YES)
#if defined(MEDIAINFO_CSV_YES)
bool CSV=MediaInfoLib::Config.Inform_Get()==__T("CSV")?true:false;
Expand Down Expand Up @@ -553,7 +591,7 @@ Ztring MediaInfo_Internal::Inform (stream_t StreamKind, size_t StreamPos, bool I
if ((XML_0_7_78 || JSON) && !IsExtra && Champ_Pos>=Stream[StreamKind][StreamPos].size())
{
IsExtra=true;
Node* Node_Extra=new Node("extra");
Node* Node_Extra=new Node((XML_0_7_78 || OLDJSON)?"extra":"Extra");
Fields.push_back(Node_Extra);
}
#endif //defined(MEDIAINFO_XML_YES || MEDIAINFO_JSON_YES
Expand Down Expand Up @@ -700,7 +738,7 @@ Ztring MediaInfo_Internal::Inform (stream_t StreamKind, size_t StreamPos, bool I
#if defined(MEDIAINFO_XML_YES) || defined(MEDIAINFO_JSON_YES)
for (size_t Field=0; Field < Fields.size(); Field++)
{
if (Fields[Field]->Name == "extra")
if (Fields[Field]->Name == "extra" || Fields[Field]->Name == "Extra")
{ std::string TmpRetour;
for (size_t Field2=0; Field2 < Fields[Field]->Childs.size(); Field2++)
if (XML)
Expand Down
2 changes: 1 addition & 1 deletion Source/MediaInfo/MediaInfo_Internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2279,7 +2279,7 @@ Ztring MediaInfo_Internal::Inform(std::vector<MediaInfo_Internal*>& Info)
else
#endif //defined(MEDIAINFO_XML_YES)
#if defined(MEDIAINFO_JSON_YES)
if (MediaInfoLib::Config.Inform_Get()==__T("JSON"))
if (MediaInfoLib::Config.Inform_Get()==__T("JSON") || MediaInfoLib::Config.Inform_Get()==__T("OLDJSON"))
{
if (Info.size() > 1)
Result+=__T("[")+MediaInfoLib::Config.LineSeparator_Get();
Expand Down