summaryrefslogtreecommitdiff
path: root/p2pvr/scanner/eitRows.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'p2pvr/scanner/eitRows.cpp')
-rw-r--r--p2pvr/scanner/eitRows.cpp84
1 files changed, 82 insertions, 2 deletions
diff --git a/p2pvr/scanner/eitRows.cpp b/p2pvr/scanner/eitRows.cpp
index f5bcf51..23e8cfe 100644
--- a/p2pvr/scanner/eitRows.cpp
+++ b/p2pvr/scanner/eitRows.cpp
@@ -31,8 +31,14 @@
#include <errno.h>
#include <stdint.h>
#include <time.h>
+#include <glibmm/regex.h>
+#include <boost/regex.hpp>
#include <boost/bind.hpp>
#include <boost/date_time/gregorian_calendar.hpp>
+#include <boost/algorithm/string/predicate.hpp>
+#include <boost/algorithm/string/trim.hpp>
+#include <boost/foreach.hpp>
+#include <boost/lexical_cast.hpp>
#include <linux/dvb/dmx.h>
#include "si_tables.h"
@@ -63,6 +69,10 @@ struct EitProgram {
VariableType contentRecommendation;
VariableType startTime;
VariableType stopTime;
+ VariableType episode;
+ VariableType episodes;
+ VariableType year;
+ VariableType flags;
};
static Glib::ustring title("title");
@@ -139,6 +149,10 @@ EitRows::resolveAttr(const Glib::ustring & attrName) const {
returnAttr(contentRecommendation);
returnAttr(startTime);
returnAttr(stopTime);
+ returnAttr(episode);
+ returnAttr(episodes);
+ returnAttr(year);
+ returnAttr(flags);
throw NoSuchAttribute(attrName);
}
@@ -158,6 +172,9 @@ EitRows::~EitRows()
static int time_offset = 0;
static int chan_filter = 0;
static int chan_filter_mask = 0;
+static Glib::RefPtr<Glib::Regex> episodeRegex = Glib::Regex::create("[ (]+(?:\\w+ )?([0-9]+)(?: of |/)([0-9]+)[.)]+");
+static Glib::RefPtr<Glib::Regex> yearRegex = Glib::Regex::create("\\(([0-9]{4})[ )]+");
+static Glib::RefPtr<Glib::Regex> flagsRegex = Glib::Regex::create("[ []+([A-Z,]+)\\]");
void
EitRows::parseEventDescription(const u_char *data) const {
@@ -165,14 +182,77 @@ EitRows::parseEventDescription(const u_char *data) const {
const struct descr_short_event *evtdesc = reinterpret_cast<const struct descr_short_event *>(data);
size_t evtlen = evtdesc->event_name_length;
+ StrPtr title, subtitle, desc;
if (evtlen) {
current->titleLang = Glib::ustring((const char *)&evtdesc->lang_code1, 3);
- current->title = convert((const char *)evtdesc->data, evtlen);
+ title = convert((const char *)evtdesc->data, evtlen);
}
size_t dsclen = evtdesc->data[evtlen];
if (dsclen) {
- current->subtitle = convert((const char *)evtdesc->data + evtlen + 1, dsclen);
+ subtitle = convert((const char *)evtdesc->data + evtlen + 1, dsclen);
+ }
+ if (subtitle) {
+ Glib::MatchInfo matches;
+ if (episodeRegex->match(*subtitle, matches)) {
+ current->episode = boost::lexical_cast<int>(matches.fetch(1));
+ current->episodes = boost::lexical_cast<int>(matches.fetch(2));
+ *subtitle = episodeRegex->replace_literal(*subtitle, 0, "", Glib::REGEX_MATCH_NOTEMPTY);
+ }
+ if (yearRegex->match(*subtitle, matches)) {
+ current->year = boost::lexical_cast<int>(matches.fetch(1));
+ *subtitle = yearRegex->replace_literal(*subtitle, 0, "", Glib::REGEX_MATCH_NOTEMPTY);
+ }
+ if (flagsRegex->match(*subtitle, matches)) {
+ current->flags = matches.fetch(1);
+ *subtitle = yearRegex->replace_literal(*subtitle, 0, "", Glib::REGEX_MATCH_NOTEMPTY);
+ }
+ }
+ if (title && subtitle) {
+ if (boost::algorithm::ends_with(*title, "...") && boost::algorithm::starts_with(*subtitle, "...")) {
+ title->resize(title->length() - 3);
+ *title += " ";
+ size_t dot = subtitle->find('.', 4);
+ if (dot == Glib::ustring::npos) {
+ title->append(*subtitle, 3, subtitle->length() - 3);
+ }
+ else {
+ title->append(*subtitle, 3, dot - 3);
+ subtitle->erase(0, dot + 2);
+ }
+ }
+ size_t colon = subtitle->find(':');
+ if (colon != Glib::ustring::npos) {
+ desc = StrPtr(new Glib::ustring(*subtitle, colon + 1, subtitle->length() - colon));
+ subtitle->resize(colon);
+ }
+ else {
+ colon = title->find(':');
+ desc = subtitle;
+ if (colon != Glib::ustring::npos) {
+ subtitle = StrPtr(new Glib::ustring(*title, colon + 1, title->length() - colon));
+ title->resize(colon);
+ }
+ else {
+ subtitle.reset();
+ }
+ }
+ }
+ if (title) {
+ boost::algorithm::trim_if(*title, isspace);
+ current->title = title;
+ }
+ if (subtitle) {
+ boost::algorithm::trim_if(*subtitle, isspace);
+ if (!subtitle->empty()) {
+ current->subtitle = subtitle;
+ }
+ }
+ if (desc) {
+ boost::algorithm::trim_if(*desc, isspace);
+ if (!desc->empty()) {
+ current->desc1 = desc;
+ }
}
}