From c3e26a6257530fbdc61f63031e3ebff619520f6c Mon Sep 17 00:00:00 2001 From: randomdan Date: Tue, 12 Apr 2011 06:47:21 +0000 Subject: Extract episode details, year and flags from subtitle --- p2pvr/cron/importSchedume.xml | 8 ++++ p2pvr/cron/sched.xml | 2 + p2pvr/scanner/Jamfile.jam | 11 ++++- p2pvr/scanner/dvbSiReaderHelper.cpp | 2 +- p2pvr/scanner/dvbSiReaderHelper.h | 3 +- p2pvr/scanner/eitRows.cpp | 84 ++++++++++++++++++++++++++++++++++++- p2pvr/scanner/si_tables.h | 2 + 7 files changed, 107 insertions(+), 5 deletions(-) diff --git a/p2pvr/cron/importSchedume.xml b/p2pvr/cron/importSchedume.xml index 767b8d2..e59403a 100644 --- a/p2pvr/cron/importSchedume.xml +++ b/p2pvr/cron/importSchedume.xml @@ -28,6 +28,10 @@ + + + + @@ -54,6 +58,10 @@ contentSeriesID startTime stopTime + episode + episodes + year + flags diff --git a/p2pvr/cron/sched.xml b/p2pvr/cron/sched.xml index 25e37d2..c2f9230 100644 --- a/p2pvr/cron/sched.xml +++ b/p2pvr/cron/sched.xml @@ -26,6 +26,8 @@ startTime stopTime serviceID + episode + episodes diff --git a/p2pvr/scanner/Jamfile.jam b/p2pvr/scanner/Jamfile.jam index fca4615..81fdb9d 100644 --- a/p2pvr/scanner/Jamfile.jam +++ b/p2pvr/scanner/Jamfile.jam @@ -1,3 +1,5 @@ +lib boost_regex : : boost_regex ; + project : requirements debug:-Wl,-z,defs "-W -Wall -Werror -Wwrite-strings" @@ -7,7 +9,14 @@ project lib p2pvr-scan-ice : icescan.cpp scanner.ice : p2pvr-scan-p2 ; # Scanner - t -lib p2pvr-scan-p2 : eitRows.cpp serviceRows.cpp dvbSiReaderHelper.cpp : ../../project2//p2common ; +lib p2pvr-scan-p2 : + eitRows.cpp + serviceRows.cpp + dvbSiReaderHelper.cpp + : + ../../project2//p2common + boost_regex + ; # ScannerICE - the ICE test app #exe scanice : ice_scan.cpp : p2pvr-scan ; diff --git a/p2pvr/scanner/dvbSiReaderHelper.cpp b/p2pvr/scanner/dvbSiReaderHelper.cpp index a464520..330b1eb 100644 --- a/p2pvr/scanner/dvbSiReaderHelper.cpp +++ b/p2pvr/scanner/dvbSiReaderHelper.cpp @@ -46,7 +46,7 @@ DvbSiReaderHelper::closeInput() const } } -VariableType +DvbSiReaderHelper::StrPtr DvbSiReaderHelper::convert(const char * txt, size_t len) { if (len == 0) { diff --git a/p2pvr/scanner/dvbSiReaderHelper.h b/p2pvr/scanner/dvbSiReaderHelper.h index 1efb461..d82ab29 100644 --- a/p2pvr/scanner/dvbSiReaderHelper.h +++ b/p2pvr/scanner/dvbSiReaderHelper.h @@ -21,7 +21,8 @@ class DvbSiReaderHelper { virtual bool parseInfoTable(const u_char *data, size_t len, const RowProcessor *) const = 0; void closeInput() const; - static VariableType convert(const char * txt, size_t len); + typedef boost::shared_ptr StrPtr; + static StrPtr convert(const char * txt, size_t len); static const std::string ISO10646; static const std::string EitEncoding; static const std::string UTF8; 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 #include #include +#include +#include #include #include +#include +#include +#include +#include #include #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 episodeRegex = Glib::Regex::create("[ (]+(?:\\w+ )?([0-9]+)(?: of |/)([0-9]+)[.)]+"); +static Glib::RefPtr yearRegex = Glib::Regex::create("\\(([0-9]{4})[ )]+"); +static Glib::RefPtr 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(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(matches.fetch(1)); + current->episodes = boost::lexical_cast(matches.fetch(2)); + *subtitle = episodeRegex->replace_literal(*subtitle, 0, "", Glib::REGEX_MATCH_NOTEMPTY); + } + if (yearRegex->match(*subtitle, matches)) { + current->year = boost::lexical_cast(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; + } } } diff --git a/p2pvr/scanner/si_tables.h b/p2pvr/scanner/si_tables.h index 3721db4..c48fdae 100644 --- a/p2pvr/scanner/si_tables.h +++ b/p2pvr/scanner/si_tables.h @@ -28,6 +28,8 @@ // Free Software Foundation, Inc., 59 Temple Place - Suite 330, // Boston, MA 02111-1307, USA. +#include + #define HILO(x) (x##_hi << 8 | x##_lo) #define HILO2(x) (x##1 << 8 | x##2) #define HILO3(x) (x##1 << 16 | x##2 << 8 | x##3) -- cgit v1.2.3