diff options
-rw-r--r-- | p2pvr/cron/importSchedume.xml | 8 | ||||
-rw-r--r-- | p2pvr/cron/sched.xml | 2 | ||||
-rw-r--r-- | p2pvr/scanner/Jamfile.jam | 11 | ||||
-rw-r--r-- | p2pvr/scanner/dvbSiReaderHelper.cpp | 2 | ||||
-rw-r--r-- | p2pvr/scanner/dvbSiReaderHelper.h | 3 | ||||
-rw-r--r-- | p2pvr/scanner/eitRows.cpp | 84 | ||||
-rw-r--r-- | 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 @@ <param name="startTime"><value source="parent" attribute="startTime" depth="1" /></param> <param name="stopTime"><value source="parent" attribute="stopTime" depth="1" /></param> <param name="eventID"><value source="parent" attribute="eventID" depth="1" /></param> + <param name="episode"><value source="parent" attribute="episode" depth="1" /></param> + <param name="episodes"><value source="parent" attribute="episodes" depth="1" /></param> + <param name="year"><value source="parent" attribute="year" depth="1" /></param> + <param name="flags"><value source="parent" attribute="flags" depth="1" /></param> </parameters> </p2:sqlmergeinsert> </p2:iterate> @@ -54,6 +58,10 @@ <column>contentSeriesID</column> <column>startTime</column> <column>stopTime</column> + <column>episode</column> + <column>episodes</column> + <column>year</column> + <column>flags</column> </columns> </p2:sqlmerge> </block> 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 @@ <column name="startTime" source="attribute">startTime</column> <column name="stopTime" source="attribute">stopTime</column> <column name="serviceID" source="attribute">serviceID</column> + <column name="episode" source="attribute">episode</column> + <column name="episodes" source="attribute">episodes</column> </columns> </p2:view> </block> 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 : : <name>boost_regex ; + project : requirements <variant>debug:<linkflags>-Wl,-z,defs <cflags>"-W -Wall -Werror -Wwrite-strings" @@ -7,7 +9,14 @@ project lib p2pvr-scan-ice : icescan.cpp scanner.ice : <library>p2pvr-scan-p2 ; # Scanner - t -lib p2pvr-scan-p2 : eitRows.cpp serviceRows.cpp dvbSiReaderHelper.cpp : <library>../../project2//p2common ; +lib p2pvr-scan-p2 : + eitRows.cpp + serviceRows.cpp + dvbSiReaderHelper.cpp + : + <library>../../project2//p2common + <library>boost_regex + ; # ScannerICE - the ICE test app #exe scanice : ice_scan.cpp : <library>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<Glib::ustring> 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 <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; + } } } 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 <stdint.h> + #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) |