forked from mia/Aegisub
Rewrite the Clean Script Info export filter in lua
This makes it easy to make it a macro in addition to an export filter, and simplifies the implementation. Originally committed to SVN as r6586.
This commit is contained in:
parent
2fa054b48b
commit
9f43f9f041
7 changed files with 51 additions and 141 deletions
51
aegisub/automation/autoload/clean-info.lua
Normal file
51
aegisub/automation/autoload/clean-info.lua
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
-- Copyright (c) 2012, Thomas Goyne <plorkyeran@aegisub.org>
|
||||||
|
--
|
||||||
|
-- Permission to use, copy, modify, and distribute this software for any
|
||||||
|
-- purpose with or without fee is hereby granted, provided that the above
|
||||||
|
-- copyright notice and this permission notice appear in all copies.
|
||||||
|
--
|
||||||
|
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
--
|
||||||
|
-- $Id$
|
||||||
|
|
||||||
|
local tr = aegisub.gettext
|
||||||
|
|
||||||
|
script_name = tr"Clean Script Info"
|
||||||
|
script_description = tr"Removes all but the absolutely required fields from the Script Info section. You might want to run this on files that you plan to distribute in original form."
|
||||||
|
script_author = "Thomas Goyne"
|
||||||
|
script_version = "1"
|
||||||
|
|
||||||
|
function clean_script_info(subs)
|
||||||
|
local keep_keys = {
|
||||||
|
["collisions"] = true,
|
||||||
|
["playresx"] = true,
|
||||||
|
["playresy"] = true,
|
||||||
|
["scaledborderandshadow"] = true,
|
||||||
|
["scripttype"] = true,
|
||||||
|
["video colorspace"] = true,
|
||||||
|
["wrapstyle"] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
for i = 1, #subs do
|
||||||
|
if subs[i].class == "info" and not keep_keys[strlower(subs[i].key)] then
|
||||||
|
subs[i] = nil
|
||||||
|
i = i - 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function clean_script_info_macro(subs)
|
||||||
|
clean_script_info(sub)
|
||||||
|
aegisub.set_undo_point(script_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
aegisub.register_macro(script_name, script_description, clean_script_info_macro)
|
||||||
|
aegisub.register_filter(script_name, script_description, 0, clean_script_info)
|
||||||
|
|
||||||
|
|
|
@ -130,7 +130,6 @@
|
||||||
<ClInclude Include="$(SrcDir)dialog_translation.h" />
|
<ClInclude Include="$(SrcDir)dialog_translation.h" />
|
||||||
<ClInclude Include="$(SrcDir)dialog_version_check.h" />
|
<ClInclude Include="$(SrcDir)dialog_version_check.h" />
|
||||||
<ClInclude Include="$(SrcDir)dialog_video_details.h" />
|
<ClInclude Include="$(SrcDir)dialog_video_details.h" />
|
||||||
<ClInclude Include="$(SrcDir)export_clean_info.h" />
|
|
||||||
<ClInclude Include="$(SrcDir)export_fixstyle.h" />
|
<ClInclude Include="$(SrcDir)export_fixstyle.h" />
|
||||||
<ClInclude Include="$(SrcDir)export_framerate.h" />
|
<ClInclude Include="$(SrcDir)export_framerate.h" />
|
||||||
<ClInclude Include="$(SrcDir)factory_manager.h" />
|
<ClInclude Include="$(SrcDir)factory_manager.h" />
|
||||||
|
@ -315,7 +314,6 @@
|
||||||
<ClCompile Include="$(SrcDir)dialog_translation.cpp" />
|
<ClCompile Include="$(SrcDir)dialog_translation.cpp" />
|
||||||
<ClCompile Include="$(SrcDir)dialog_version_check.cpp" />
|
<ClCompile Include="$(SrcDir)dialog_version_check.cpp" />
|
||||||
<ClCompile Include="$(SrcDir)dialog_video_details.cpp" />
|
<ClCompile Include="$(SrcDir)dialog_video_details.cpp" />
|
||||||
<ClCompile Include="$(SrcDir)export_clean_info.cpp" />
|
|
||||||
<ClCompile Include="$(SrcDir)export_fixstyle.cpp" />
|
<ClCompile Include="$(SrcDir)export_fixstyle.cpp" />
|
||||||
<ClCompile Include="$(SrcDir)export_framerate.cpp" />
|
<ClCompile Include="$(SrcDir)export_framerate.cpp" />
|
||||||
<ClCompile Include="$(SrcDir)ffmpegsource_common.cpp" />
|
<ClCompile Include="$(SrcDir)ffmpegsource_common.cpp" />
|
||||||
|
|
|
@ -300,9 +300,6 @@
|
||||||
<ClInclude Include="$(SrcDir)export_framerate.h">
|
<ClInclude Include="$(SrcDir)export_framerate.h">
|
||||||
<Filter>Features\Export</Filter>
|
<Filter>Features\Export</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="$(SrcDir)export_clean_info.h">
|
|
||||||
<Filter>Features\Export</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="$(SrcDir)export_fixstyle.h">
|
<ClInclude Include="$(SrcDir)export_fixstyle.h">
|
||||||
<Filter>Features\Export</Filter>
|
<Filter>Features\Export</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
@ -884,9 +881,6 @@
|
||||||
<ClCompile Include="$(SrcDir)dialog_export.cpp">
|
<ClCompile Include="$(SrcDir)dialog_export.cpp">
|
||||||
<Filter>Features\Export</Filter>
|
<Filter>Features\Export</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="$(SrcDir)export_clean_info.cpp">
|
|
||||||
<Filter>Features\Export</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="$(SrcDir)export_fixstyle.cpp">
|
<ClCompile Include="$(SrcDir)export_fixstyle.cpp">
|
||||||
<Filter>Features\Export</Filter>
|
<Filter>Features\Export</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|
|
@ -188,7 +188,6 @@ SRC += \
|
||||||
dialog_version_check.cpp \
|
dialog_version_check.cpp \
|
||||||
dialog_video_details.cpp \
|
dialog_video_details.cpp \
|
||||||
audio_provider_dummy.cpp \
|
audio_provider_dummy.cpp \
|
||||||
export_clean_info.cpp \
|
|
||||||
export_fixstyle.cpp \
|
export_fixstyle.cpp \
|
||||||
export_framerate.cpp \
|
export_framerate.cpp \
|
||||||
fft.cpp \
|
fft.cpp \
|
||||||
|
|
|
@ -1,81 +0,0 @@
|
||||||
// Copyright (c) 2005, Niels Martin Hansen
|
|
||||||
// All rights reserved.
|
|
||||||
//
|
|
||||||
// Redistribution and use in source and binary forms, with or without
|
|
||||||
// modification, are permitted provided that the following conditions are met:
|
|
||||||
//
|
|
||||||
// * Redistributions of source code must retain the above copyright notice,
|
|
||||||
// this list of conditions and the following disclaimer.
|
|
||||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
// this list of conditions and the following disclaimer in the documentation
|
|
||||||
// and/or other materials provided with the distribution.
|
|
||||||
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
||||||
// may be used to endorse or promote products derived from this software
|
|
||||||
// without specific prior written permission.
|
|
||||||
//
|
|
||||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
||||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
// POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
//
|
|
||||||
// Aegisub Project http://www.aegisub.org/
|
|
||||||
//
|
|
||||||
// $Id$
|
|
||||||
|
|
||||||
/// @file export_clean_info.cpp
|
|
||||||
/// @brief Clean Script Info export filter
|
|
||||||
/// @ingroup export
|
|
||||||
///
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#include "ass_dialogue.h"
|
|
||||||
#include "ass_file.h"
|
|
||||||
#include "ass_override.h"
|
|
||||||
#include "export_clean_info.h"
|
|
||||||
|
|
||||||
AssTransformCleanInfoFilter::AssTransformCleanInfoFilter()
|
|
||||||
: AssExportFilter(_("Clean Script Info"), _("Removes all but the absolutely required fields from the Script Info section. You might want to run this on files that you plan to distribute in original form."))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void AssTransformCleanInfoFilter::ProcessSubs(AssFile *subs, wxWindow *) {
|
|
||||||
using std::list;
|
|
||||||
AssEntry *curEntry;
|
|
||||||
entryIter cur, next = subs->Line.begin();
|
|
||||||
while (next != subs->Line.end()) {
|
|
||||||
cur = next++;
|
|
||||||
|
|
||||||
curEntry = *cur;
|
|
||||||
if (curEntry->group != "[Script Info]") {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (curEntry->GetEntryData().empty()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (curEntry->GetEntryData() == "[Script Info]") {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (curEntry->GetEntryData().Left(1) == ";") {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
wxString field = curEntry->GetEntryData().Left(curEntry->GetEntryData().Find(':')).Lower();
|
|
||||||
if (field != "scripttype" &&
|
|
||||||
field != "collisions" &&
|
|
||||||
field != "playresx" &&
|
|
||||||
field != "playresy" &&
|
|
||||||
field != "wrapstyle" &&
|
|
||||||
field != "scaledborderandshadow") {
|
|
||||||
delete curEntry;
|
|
||||||
subs->Line.erase(cur);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,49 +0,0 @@
|
||||||
// Copyright (c) 2005, Niels Martin Hansen
|
|
||||||
// All rights reserved.
|
|
||||||
//
|
|
||||||
// Redistribution and use in source and binary forms, with or without
|
|
||||||
// modification, are permitted provided that the following conditions are met:
|
|
||||||
//
|
|
||||||
// * Redistributions of source code must retain the above copyright notice,
|
|
||||||
// this list of conditions and the following disclaimer.
|
|
||||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
// this list of conditions and the following disclaimer in the documentation
|
|
||||||
// and/or other materials provided with the distribution.
|
|
||||||
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
||||||
// may be used to endorse or promote products derived from this software
|
|
||||||
// without specific prior written permission.
|
|
||||||
//
|
|
||||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
||||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
// POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
//
|
|
||||||
// Aegisub Project http://www.aegisub.org/
|
|
||||||
//
|
|
||||||
// $Id$
|
|
||||||
|
|
||||||
/// @file export_clean_info.h
|
|
||||||
/// @see export_clean_info.cpp
|
|
||||||
/// @ingroup export
|
|
||||||
///
|
|
||||||
|
|
||||||
#include "ass_export_filter.h"
|
|
||||||
|
|
||||||
|
|
||||||
/// DOCME
|
|
||||||
/// @class AssTransformCleanInfoFilter
|
|
||||||
/// @brief Removes all but the absolutely required fields from the Script Info section
|
|
||||||
///
|
|
||||||
/// DOCME
|
|
||||||
class AssTransformCleanInfoFilter : public AssExportFilter {
|
|
||||||
public:
|
|
||||||
void ProcessSubs(AssFile *subs, wxWindow *);
|
|
||||||
AssTransformCleanInfoFilter();
|
|
||||||
};
|
|
|
@ -60,7 +60,6 @@
|
||||||
#include "auto4_base.h"
|
#include "auto4_base.h"
|
||||||
#include "charset_conv.h"
|
#include "charset_conv.h"
|
||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
#include "export_clean_info.h"
|
|
||||||
#include "export_fixstyle.h"
|
#include "export_fixstyle.h"
|
||||||
#include "export_framerate.h"
|
#include "export_framerate.h"
|
||||||
#include "frame_main.h"
|
#include "frame_main.h"
|
||||||
|
@ -246,7 +245,6 @@ bool AegisubApp::OnInit() {
|
||||||
// Load export filters
|
// Load export filters
|
||||||
StartupLog("Register export filters");
|
StartupLog("Register export filters");
|
||||||
AssExportFilterChain::Register(new AssFixStylesFilter);
|
AssExportFilterChain::Register(new AssFixStylesFilter);
|
||||||
AssExportFilterChain::Register(new AssTransformCleanInfoFilter);
|
|
||||||
AssExportFilterChain::Register(new AssTransformFramerateFilter);
|
AssExportFilterChain::Register(new AssTransformFramerateFilter);
|
||||||
|
|
||||||
// Get parameter subs
|
// Get parameter subs
|
||||||
|
|
Loading…
Reference in a new issue