summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/rating.cc73
-rw-r--r--src/rating.h27
-rw-r--r--src/util.cc18
3 files changed, 111 insertions, 7 deletions
diff --git a/src/rating.cc b/src/rating.cc
index 2064c644..0ba9f2b8 100644
--- a/src/rating.cc
+++ b/src/rating.cc
@@ -32,13 +32,23 @@
*/
+#include "exceptions.h"
#include "rating.h"
+#include "util.h"
#include <libcxml/cxml.h>
+#include <boost/algorithm/string.hpp>
+using std::string;
+using std::vector;
+using boost::algorithm::trim;
+using boost::optional;
using namespace dcp;
+static vector<RatingSystem> rating_systems_list;
+
+
Rating::Rating (cxml::ConstNodePtr node)
: agency(node->string_child("Agency"))
, label(node->string_child("Label"))
@@ -62,3 +72,66 @@ dcp::operator== (Rating const & a, Rating const & b)
}
+vector<RatingSystem>
+dcp::rating_systems()
+{
+ return rating_systems_list;
+}
+
+
+void
+dcp::load_rating_list(boost::filesystem::path ratings_file)
+{
+ auto f = fopen_boost (ratings_file, "r");
+ if (!f) {
+ throw FileError ("Could not open ratings file", ratings_file, errno);
+ }
+
+ auto get_line_no_throw = [f, ratings_file]() -> optional<string> {
+ char buffer[512];
+ char* r = fgets(buffer, sizeof(buffer), f);
+ if (r == 0) {
+ return {};
+ }
+ string a = buffer;
+ trim(a);
+ return a;
+ };
+
+ auto get_line = [f, ratings_file, &get_line_no_throw]() {
+ auto line = get_line_no_throw();
+ if (!line) {
+ throw FileError("Bad ratings file", ratings_file, -1);
+ }
+ return *line;
+ };
+
+ optional<string> agency;
+
+ while (!feof(f)) {
+ if (!agency) {
+ agency = get_line();
+ }
+ auto name = get_line();
+ auto country_and_region_names = get_line();
+ auto country_code = get_line();
+
+ RatingSystem system(*agency, name, country_and_region_names, country_code);
+ while (!feof(f)) {
+ auto rating = get_line_no_throw();
+ if (!rating) {
+ /* End of the file */
+ break;
+ }
+ if (rating->substr(0, 4) == "http") {
+ /* End of the system */
+ agency = rating;
+ break;
+ }
+ system.ratings.push_back(dcp::Rating(*agency, *rating));
+ }
+
+ rating_systems_list.push_back(system);
+ }
+}
+
diff --git a/src/rating.h b/src/rating.h
index 0fb912b3..cd6ce520 100644
--- a/src/rating.h
+++ b/src/rating.h
@@ -69,6 +69,33 @@ public:
extern bool operator== (Rating const & a, Rating const & b);
+class RatingSystem
+{
+public:
+ RatingSystem (std::string agency_, std::string name_, std::string country_and_region_names_, std::string country_code_)
+ : agency(agency_)
+ , name(name_)
+ , country_and_region_names(country_and_region_names_)
+ , country_code(country_code_)
+ {}
+
+ /** URI of the agency issuing the rating */
+ std::string agency;
+ /** Name of the rating system */
+ std::string name;
+ /** Country name, possibly followed by a slash and a region name */
+ std::string country_and_region_names;
+ /** Country code */
+ std::string country_code;
+
+ std::vector<Rating> ratings;
+};
+
+
+std::vector<RatingSystem> rating_systems();
+
+void load_rating_list(boost::filesystem::path ratings_file);
+
}
diff --git a/src/util.cc b/src/util.cc
index 7a5733c2..ed3fb772 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -37,14 +37,15 @@
*/
-#include "util.h"
-#include "language_tag.h"
-#include "exceptions.h"
-#include "types.h"
#include "certificate.h"
-#include "openjpeg_image.h"
-#include "dcp_assert.h"
#include "compose.hpp"
+#include "dcp_assert.h"
+#include "exceptions.h"
+#include "language_tag.h"
+#include "openjpeg_image.h"
+#include "rating.h"
+#include "types.h"
+#include "util.h"
#include <openjpeg.h>
#include <asdcp/KM_util.h>
#include <asdcp/KM_fileio.h>
@@ -194,7 +195,10 @@ dcp::init (optional<boost::filesystem::path> given_resources_directory)
asdcp_smpte_dict = &ASDCP::DefaultSMPTEDict();
- load_language_tag_lists (given_resources_directory.get_value_or(resources_directory()) / "tags");
+ auto res = given_resources_directory.get_value_or(resources_directory());
+
+ load_language_tag_lists (res / "tags");
+ load_rating_list (res / "ratings");
}