2014-03-24 15:54:22 +01:00
|
|
|
// Copyright (c) 2014, Thomas Goyne <plorkyeran@aegisub.org>
|
2006-03-01 05:32:00 +01:00
|
|
|
//
|
2014-03-24 15:54:22 +01:00
|
|
|
// 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.
|
2006-03-01 05:32:00 +01:00
|
|
|
//
|
2014-03-24 15:54:22 +01:00
|
|
|
// 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.
|
2006-03-01 05:32:00 +01:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
|
|
|
|
2014-03-24 15:54:22 +01:00
|
|
|
#include "include/aegisub/subtitles_provider.h"
|
|
|
|
|
2014-05-02 19:39:38 +02:00
|
|
|
#include "ass_dialogue.h"
|
|
|
|
#include "ass_file.h"
|
|
|
|
#include "ass_info.h"
|
|
|
|
#include "ass_style.h"
|
2014-03-24 15:54:22 +01:00
|
|
|
#include "factory_manager.h"
|
2013-01-07 02:50:09 +01:00
|
|
|
#include "options.h"
|
2008-03-05 03:58:11 +01:00
|
|
|
#include "subtitles_provider_csri.h"
|
|
|
|
#include "subtitles_provider_libass.h"
|
2014-03-24 15:54:22 +01:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
struct factory {
|
|
|
|
std::string name;
|
|
|
|
std::string subtype;
|
2014-03-25 17:51:38 +01:00
|
|
|
std::unique_ptr<SubtitlesProvider> (*create)(std::string const& subtype, agi::BackgroundRunner *br);
|
2014-03-24 15:54:22 +01:00
|
|
|
bool hidden;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<factory> const& factories() {
|
|
|
|
static std::vector<factory> factories;
|
|
|
|
if (factories.size()) return factories;
|
|
|
|
#ifdef WITH_CSRI
|
|
|
|
for (auto const& subtype : csri::List())
|
|
|
|
factories.push_back(factory{"CSRI/" + subtype, subtype, csri::Create, false});
|
|
|
|
#endif
|
|
|
|
factories.push_back(factory{"libass", "", libass::Create, false});
|
|
|
|
return factories;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> SubtitlesProviderFactory::GetClasses() {
|
|
|
|
return ::GetClasses(factories());
|
|
|
|
}
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2014-03-25 17:51:38 +01:00
|
|
|
std::unique_ptr<SubtitlesProvider> SubtitlesProviderFactory::GetProvider(agi::BackgroundRunner *br) {
|
2014-03-24 15:54:22 +01:00
|
|
|
auto preferred = OPT_GET("Subtitle/Provider")->GetString();
|
|
|
|
auto sorted = GetSorted(factories(), preferred);
|
2007-01-21 07:30:19 +01:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
std::string error;
|
2014-03-24 15:54:22 +01:00
|
|
|
for (auto factory : sorted) {
|
2007-01-21 07:30:19 +01:00
|
|
|
try {
|
2014-03-25 17:51:38 +01:00
|
|
|
auto provider = factory->create(factory->subtype, br);
|
2007-01-21 07:30:19 +01:00
|
|
|
if (provider) return provider;
|
|
|
|
}
|
2010-09-01 08:50:35 +02:00
|
|
|
catch (agi::UserCancelException const&) { throw; }
|
2014-06-11 00:28:45 +02:00
|
|
|
catch (agi::Exception const& err) { error += factory->name + ": " + err.GetMessage() + "\n"; }
|
2014-03-24 15:54:22 +01:00
|
|
|
catch (...) { error += factory->name + ": Unknown error\n"; }
|
2007-01-21 07:30:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
throw error;
|
2006-05-06 03:05:46 +02:00
|
|
|
}
|
2014-05-02 19:39:38 +02:00
|
|
|
|
|
|
|
void SubtitlesProvider::LoadSubtitles(AssFile *subs, int time) {
|
|
|
|
buffer.clear();
|
|
|
|
|
|
|
|
auto push_header = [&](const char *str) {
|
|
|
|
buffer.insert(buffer.end(), str, str + strlen(str));
|
|
|
|
};
|
|
|
|
auto push_line = [&](std::string const& str) {
|
|
|
|
buffer.insert(buffer.end(), &str[0], &str[0] + str.size());
|
|
|
|
buffer.push_back('\n');
|
|
|
|
};
|
|
|
|
|
|
|
|
push_header("[Script Info]\n");
|
|
|
|
for (auto const& line : subs->Info)
|
|
|
|
push_line(line.GetEntryData());
|
|
|
|
|
|
|
|
push_header("[V4+ Styles]\n");
|
2014-05-04 20:16:57 +02:00
|
|
|
for (auto const& line : subs->Styles)
|
2014-05-02 19:39:38 +02:00
|
|
|
push_line(line.GetEntryData());
|
|
|
|
|
|
|
|
push_header("[Events]\n");
|
|
|
|
for (auto const& line : subs->Events) {
|
2014-05-20 16:05:07 +02:00
|
|
|
if (!line.Comment && (time < 0 || !(line.Start > time || line.End <= time)))
|
2014-05-02 19:39:38 +02:00
|
|
|
push_line(line.GetEntryData());
|
|
|
|
}
|
|
|
|
|
|
|
|
LoadSubtitles(&buffer[0], buffer.size());
|
|
|
|
}
|