From a23e465b633b48136c2fbd16406e955902fc11a2 Mon Sep 17 00:00:00 2001 From: Julian Scheel Date: Tue, 2 Feb 2016 12:18:41 +0100 Subject: [PATCH] Add support for groups Parse the groups out of the json data. As of now all radio channels are stored in groups prefixed with "Radio" which is used to set the radio flag now. Signed-off-by: Julian Scheel --- src/OctonetData.cpp | 70 ++++++++++++++++++++++++++++++++++++++++++++- src/OctonetData.h | 13 +++++++++ src/client.cpp | 18 ++++++++++-- 3 files changed, 97 insertions(+), 4 deletions(-) diff --git a/src/OctonetData.cpp b/src/OctonetData.cpp index 36b873e..805f558 100644 --- a/src/OctonetData.cpp +++ b/src/OctonetData.cpp @@ -34,6 +34,7 @@ OctonetData::OctonetData() { serverAddress = octonetAddress; channels.clear(); + groups.clear(); if (loadChannelList()) kodi->QueueNotification(QUEUE_INFO, "%d channels loaded.", channels.size()); @@ -42,6 +43,7 @@ OctonetData::OctonetData() OctonetData::~OctonetData(void) { channels.clear(); + groups.clear(); } bool OctonetData::loadChannelList() @@ -66,13 +68,18 @@ bool OctonetData::loadChannelList() const Json::Value groupList = root["GroupList"]; for (unsigned int i = 0; i < groupList.size(); i++) { const Json::Value channelList = groupList[i]["ChannelList"]; + OctonetGroup group; + + group.name = groupList[i]["Title"].asString(); + group.radio = group.name.compare(0, 5, "Radio") ? false : true; + for (unsigned int j = 0; j < channelList.size(); j++) { const Json::Value channel = channelList[j]; OctonetChannel chan; chan.name = channel["Title"].asString(); chan.url = "rtsp://" + serverAddress + "/" + channel["Request"].asString(); - chan.radio = false; + chan.radio = group.radio; #if 0 /* Would require a 64 bit identifier */ std::string id = channel["ID"].asString(); @@ -85,8 +92,10 @@ bool OctonetData::loadChannelList() ids >> chan.id; #endif chan.id = 1000 + channels.size(); + group.members.push_back(channels.size()); channels.push_back(chan); } + groups.push_back(group); } return true; @@ -125,3 +134,62 @@ PVR_ERROR OctonetData::getChannels(ADDON_HANDLE handle, bool bRadio) } return PVR_ERROR_NO_ERROR; } + +int OctonetData::getGroupCount(void) +{ + return groups.size(); +} + +PVR_ERROR OctonetData::getGroups(ADDON_HANDLE handle, bool bRadio) +{ + for (unsigned int i = 0; i < groups.size(); i++) + { + OctonetGroup &group = groups.at(i); + if (group.radio == bRadio) + { + PVR_CHANNEL_GROUP g; + memset(&g, 0, sizeof(PVR_CHANNEL_GROUP)); + + g.iPosition = 0; + g.bIsRadio = group.radio; + strncpy(g.strGroupName, group.name.c_str(), strlen(group.name.c_str())); + + pvr->TransferChannelGroup(handle, &g); + } + } + + return PVR_ERROR_NO_ERROR; +} + +PVR_ERROR OctonetData::getGroupMembers(ADDON_HANDLE handle, const PVR_CHANNEL_GROUP &group) +{ + OctonetGroup *g = findGroup(group.strGroupName); + if (g == NULL) + return PVR_ERROR_UNKNOWN; + + for (unsigned int i = 0; i < g->members.size(); i++) + { + OctonetChannel &channel = channels.at(g->members[i]); + PVR_CHANNEL_GROUP_MEMBER m; + memset(&m, 0, sizeof(PVR_CHANNEL_GROUP_MEMBER)); + + strncpy(m.strGroupName, group.strGroupName, strlen(group.strGroupName)); + m.iChannelUniqueId = channel.id; + m.iChannelNumber = channel.id; + + pvr->TransferChannelGroupMember(handle, &m); + } + + return PVR_ERROR_NO_ERROR; +} + +OctonetGroup* OctonetData::findGroup(const std::string &name) +{ + for (unsigned int i = 0; i < groups.size(); i++) + { + if (groups.at(i).name == name) + return &groups.at(i); + } + + return NULL; +} diff --git a/src/OctonetData.h b/src/OctonetData.h index f2a5277..8bafc4a 100644 --- a/src/OctonetData.h +++ b/src/OctonetData.h @@ -36,6 +36,13 @@ struct OctonetChannel int id; }; +struct OctonetGroup +{ + std::string name; + bool radio; + std::vector members; +}; + class OctonetData : public PLATFORM::CThread { public: @@ -45,12 +52,18 @@ class OctonetData : public PLATFORM::CThread virtual int getChannelCount(void); virtual PVR_ERROR getChannels(ADDON_HANDLE handle, bool bRadio); + virtual int getGroupCount(void); + virtual PVR_ERROR getGroups(ADDON_HANDLE handle, bool bRadio); + virtual PVR_ERROR getGroupMembers(ADDON_HANDLE handle, const PVR_CHANNEL_GROUP &group); + protected: virtual bool loadChannelList(void); + virtual OctonetGroup* findGroup(const std::string &name); virtual void *Process(void); private: std::string serverAddress; std::vector channels; + std::vector groups; }; diff --git a/src/client.cpp b/src/client.cpp index 7252f35..c8dd99c 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -148,6 +148,7 @@ PVR_ERROR GetAddonCapabilities(PVR_ADDON_CAPABILITIES *pCapabilities) { pCapabilities->bSupportsTV = true; pCapabilities->bSupportsRadio = true; + pCapabilities->bSupportsChannelGroups = true; return PVR_ERROR_NO_ERROR; } @@ -174,9 +175,20 @@ PVR_ERROR CallMenuHook(const PVR_MENUHOOK& menuhook, const PVR_MENUHOOK_DATA &it PVR_ERROR GetEPGForChannel(ADDON_HANDLE handle, const PVR_CHANNEL& channel, time_t iStart, time_t iEnd) { return PVR_ERROR_NOT_IMPLEMENTED; } /* Channel groups */ -int GetChannelGroupsAmount(void) { return -1; } -PVR_ERROR GetChannelGroups(ADDON_HANDLE handle, bool bRadio) { return PVR_ERROR_NOT_IMPLEMENTED; } -PVR_ERROR GetChannelGroupMembers(ADDON_HANDLE handle, const PVR_CHANNEL_GROUP& group) { return PVR_ERROR_NOT_IMPLEMENTED; } +int GetChannelGroupsAmount(void) +{ + return data->getGroupCount(); +} + +PVR_ERROR GetChannelGroups(ADDON_HANDLE handle, bool bRadio) +{ + return data->getGroups(handle, bRadio); +} + +PVR_ERROR GetChannelGroupMembers(ADDON_HANDLE handle, const PVR_CHANNEL_GROUP& group) +{ + return data->getGroupMembers(handle, group); +} /* Channels */ PVR_ERROR OpenDialogChannelScan(void) { return PVR_ERROR_NOT_IMPLEMENTED; }