Skip to content

Commit

Permalink
add ext EPG info responder
Browse files Browse the repository at this point in the history
  • Loading branch information
hannemann committed Apr 19, 2015
1 parent 4eb0f20 commit a9d2053
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 3 deletions.
11 changes: 10 additions & 1 deletion API.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

<div class="center">
<h1>RESTFULAPI-Plugin for VDR</h1><br />
<b>Version 0.2.3.0</b><br />
<b>Version 0.2.3.1</b><br />
Copyright &copy; 2015 yavdr-Team, Michael Eiler<br /><br />
Organization/Community: <a href="mailto:[email protected]">[email protected]</a><br />
Developer: <a href="mailto:[email protected]">[email protected]</a> or <a href="mailto:[email protected]">[email protected]</a><br />
Expand Down Expand Up @@ -82,6 +82,7 @@ <h1>Table Of Contents</h1>
<li><a href="#SearchTimersRecordingdirs">Get recording dirs</a>
<li><a href="#SearchTimersChannelgroups">Get channel groups</a>
<li><a href="#SearchTimersConflicts">Check timer conflicts</a>
<li><a href="#SearchTimersExtEPGInfo">Fetch ext EPG info (epgsearchcats.conf)</a>
</ul>
<li><a href="#ScraperImages">ScraperImages</a></li>
<li><a href="#Wirbelscan">Control the Wirbelscan plugin</a>
Expand Down Expand Up @@ -1080,6 +1081,14 @@ <h2><a name="SearchTimersConflicts">Check timer conflicts</a></h2>
</code></div>
<br />
<br />

<h2><a name="SearchTimersExtEPGInfo">Fetch searchtimer ext EPG info defined in epgsearchcats.conf</a></h2>
<br />
<div class="code"><code>
GET http://&lt;ip&gt;:&lt;port&gt;/searchtimers/extepginfo.json|xml|html&lt;id&gt;
</code></div>
<br />
<br />
<hr/>
<h1 class="center"><a name="ScraperImages">ScraperImage</a></h1>
<hr />
Expand Down
8 changes: 7 additions & 1 deletion debian/changelog
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
vdr-plugin-restfulapi (0.2.3.1-0yavdr0~precise) precise; urgency=medium

* add searchtimer ext EPG info responder

-- Henning Künne <[email protected]> Sun, 19 Apr 2015 21:28:20 +0200

vdr-plugin-restfulapi (0.2.3.0-0yavdr0~precise) precise; urgency=medium

* add searchtimer channelgroups responder
* add searchtimer blacklists responder
* add searchtimer timer conflicts responder
* add searchtimer recording dirs responder

-- Henning Künne <[email protected]> Sun, 22 Mar 2015 21:09:20 +0200
-- Henning Künne <[email protected]> Sun, 19 Apr 2015 20:09:20 +0200

vdr-plugin-restfulapi (0.2.2.1-0yavdr0~precise) precise; urgency=medium

Expand Down
5 changes: 5 additions & 0 deletions epgsearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ ExtEPGInfo::ExtEPGInfo( string const& data )
{
m_id = -1;
m_searchmode = 0;
m_data = data;

vector< string > parts = StringExtension::split( data, "|" );
try {
Expand All @@ -682,6 +683,10 @@ ExtEPGInfo::ExtEPGInfo( string const& data )
void ExtEPGInfo::ParseValues( string const& data )
{
m_values = StringExtension::split( data, "," );

for(std::vector<int>::size_type i = 0; i != m_values.size(); i++) {
m_values[i] = StringExtension::trim(m_values[i]);
}
}

bool ExtEPGInfo::Selected(unsigned int index, string const& values)
Expand Down
2 changes: 2 additions & 0 deletions epgsearch.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,14 @@ class ExtEPGInfo
std::string Name() const { return m_menuname; }
std::vector< std::string > Values() const { return m_values; }
bool Selected(unsigned int index, std::string const& values);
std::string Get() { return m_data; };
private:
int m_id;
std::string m_name;
std::string m_menuname;
std::vector< std::string > m_values;
int m_searchmode;
std::string m_data;

void ParseValues( std::string const& data );
};
Expand Down
2 changes: 1 addition & 1 deletion restfulapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "serverthread.h"
#include "statusmonitor.h"

static const char *VERSION = "0.2.3.0";
static const char *VERSION = "0.2.3.1";
static const char *DESCRIPTION = "Offers a RESTful-API to retrieve data from VDR";
static const char *MAINMENUENTRY = NULL;//"Restfulapi";

Expand Down
117 changes: 117 additions & 0 deletions searchtimers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ void SearchTimersResponder::reply(ostream& out, cxxtools::http::Request& request
replyBlacklists(out, request, reply);
} else if (request.method() == "GET" && (int)request.url().find("/searchtimers/conflicts") == 0 ) {
replyTimerConflicts(out, request, reply);
} else if (request.method() == "GET" && (int)request.url().find("/searchtimers/extepginfo") == 0 ) {
replyExtEpgInfo(out, request, reply);
} else {
if (request.method() == "GET") {
replyShow(out, request, reply);
Expand Down Expand Up @@ -573,4 +575,119 @@ void XmlTimerConflicts::finish()
s->write("</conflicts>");
}

// Timerconflicts responder

void SearchTimersResponder::replyExtEpgInfo(std::ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply) {

QueryHandler q("/searchtimers/extepginfo", request);
ExtEpgInfos* list;
vdrlive::ExtEPGInfos extepginfos;

if ( q.isFormat(".json") ) {
reply.addHeader("Content-Type", "application/json; charset=utf-8");
list = (ExtEpgInfos*)new JsonExtEpgInfos(&out);
} else if ( q.isFormat(".html") ) {
reply.addHeader("Content-Type", "text/html; charset=utf-8");
list = (ExtEpgInfos*)new HtmlExtEpgInfos(&out);
} else if ( q.isFormat(".xml") ) {
reply.addHeader("Content-Type", "text/xml; charset=utf-8");
list = (ExtEpgInfos*)new XmlExtEpgInfos(&out);
} else {
reply.httpReturn(403, "Resources are not available for the selected format. (Use: .json, .xml or .html)");
return;
}

list->init();
int total = 0;

for (vdrlive::ExtEPGInfos::iterator item = extepginfos.begin(); item != extepginfos.end(); ++item) {

ExtEpgInfo info;
info.name = item->Name();
info.id = item->Id();
info.values = item->Values();
info.config = item->Get();

list->addInfo(info);
total++;
}

list->setTotal(total);
list->finish();
delete list;

}

ExtEpgInfos::ExtEpgInfos(std::ostream* _out)
{
s = new StreamExtension(_out);
total = 0;
}

ExtEpgInfos::~ExtEpgInfos()
{
delete s;
}

void HtmlExtEpgInfos::init()
{
s->writeHtmlHeader( "Ext EPG Info" );
s->write("<ul>");
}

void HtmlExtEpgInfos::addInfo(ExtEpgInfo info)
{
if ( filtered() ) return;

//s->write(cString::sprintf("<li>%s</li>", info.c_str()));
}

void HtmlExtEpgInfos::finish()
{
s->write("</ul>");
s->write("</body></html>");
}


void JsonExtEpgInfos::addInfo(ExtEpgInfo info)
{
if ( filtered() ) return;
infos.push_back(info);
}

void JsonExtEpgInfos::finish()
{
cxxtools::JsonSerializer serializer(*s->getBasicStream());
serializer.serialize(infos, "ext_epg_info");
serializer.serialize(Count(), "count");
serializer.serialize(total, "total");
serializer.finish();
}

void XmlExtEpgInfos::init()
{
s->writeXmlHeader();
s->write("<ext_epg_infos xmlns=\"http://www.domain.org/restfulapi/2011/groups-xml\">\n");
}

void XmlExtEpgInfos::addInfo(ExtEpgInfo info)
{
if ( filtered() ) return;
//s->write(cString::sprintf(" <ext_epg_info>%s</ext_epg_info>\n", StringExtension::encodeToXml( info ).c_str()));
}

void XmlExtEpgInfos::finish()
{
s->write(cString::sprintf(" <count>%i</count><total>%i</total>", Count(), total));
s->write("</ext_epg_infos>");
}

void operator<<= (cxxtools::SerializationInfo& si, const ExtEpgInfo& t)
{
si.addMember("id") <<= t.id;
si.addMember("name") <<= t.name;
si.addMember("values") <<= t.values;
si.addMember("config") <<= t.config;
}


56 changes: 56 additions & 0 deletions searchtimers.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class SearchTimersResponder : public cxxtools::http::Responder
virtual void replyRecordingDirs(std::ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply);
virtual void replyBlacklists(std::ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply);
virtual void replyTimerConflicts(std::ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply);
virtual void replyExtEpgInfo(std::ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply);
};

typedef cxxtools::http::CachedService<SearchTimersResponder> SearchTimersService;
Expand Down Expand Up @@ -221,4 +222,59 @@ class XmlTimerConflicts : TimerConflicts
virtual void finish();
};

struct ExtEpgInfo {
std::string name;
int id;
std::vector< std::string > values;
std::string config;
};

void operator<<= (cxxtools::SerializationInfo& si, const ExtEpgInfo& t);

class ExtEpgInfos : public BaseList
{
protected:
StreamExtension *s;
int total;
public:
explicit ExtEpgInfos(std::ostream* _out);
virtual ~ExtEpgInfos();
virtual void init() { };
virtual void addInfo(ExtEpgInfo info) { };
virtual void finish() { };
virtual void setTotal(int _total) { total = _total; }
};

class HtmlExtEpgInfos : ExtEpgInfos
{
public:
explicit HtmlExtEpgInfos(std::ostream* _out) : ExtEpgInfos(_out) { };
~HtmlExtEpgInfos() { };
virtual void init();
virtual void addInfo(ExtEpgInfo info);
virtual void finish();
};

class JsonExtEpgInfos : ExtEpgInfos
{
private:
std::vector< ExtEpgInfo > infos;
public:
explicit JsonExtEpgInfos(std::ostream* _out) : ExtEpgInfos(_out) { };
~JsonExtEpgInfos() { };
virtual void init() { };
virtual void addInfo(ExtEpgInfo info);
virtual void finish();
};

class XmlExtEpgInfos : ExtEpgInfos
{
public:
explicit XmlExtEpgInfos(std::ostream* _out) : ExtEpgInfos(_out) { };
~XmlExtEpgInfos() { };
virtual void init();
virtual void addInfo(ExtEpgInfo info);
virtual void finish();
};

#endif

0 comments on commit a9d2053

Please sign in to comment.