1
0
mirror of https://github.com/DigitalDevices/pvr.octonet.git synced 2023-10-10 13:36:57 +02:00

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 <julian@jusst.de>
This commit is contained in:
Julian Scheel 2016-02-02 12:18:41 +01:00
parent f724c5934c
commit a23e465b63
3 changed files with 97 additions and 4 deletions

View File

@ -34,6 +34,7 @@ OctonetData::OctonetData()
{ {
serverAddress = octonetAddress; serverAddress = octonetAddress;
channels.clear(); channels.clear();
groups.clear();
if (loadChannelList()) if (loadChannelList())
kodi->QueueNotification(QUEUE_INFO, "%d channels loaded.", channels.size()); kodi->QueueNotification(QUEUE_INFO, "%d channels loaded.", channels.size());
@ -42,6 +43,7 @@ OctonetData::OctonetData()
OctonetData::~OctonetData(void) OctonetData::~OctonetData(void)
{ {
channels.clear(); channels.clear();
groups.clear();
} }
bool OctonetData::loadChannelList() bool OctonetData::loadChannelList()
@ -66,13 +68,18 @@ bool OctonetData::loadChannelList()
const Json::Value groupList = root["GroupList"]; const Json::Value groupList = root["GroupList"];
for (unsigned int i = 0; i < groupList.size(); i++) { for (unsigned int i = 0; i < groupList.size(); i++) {
const Json::Value channelList = groupList[i]["ChannelList"]; 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++) { for (unsigned int j = 0; j < channelList.size(); j++) {
const Json::Value channel = channelList[j]; const Json::Value channel = channelList[j];
OctonetChannel chan; OctonetChannel chan;
chan.name = channel["Title"].asString(); chan.name = channel["Title"].asString();
chan.url = "rtsp://" + serverAddress + "/" + channel["Request"].asString(); chan.url = "rtsp://" + serverAddress + "/" + channel["Request"].asString();
chan.radio = false; chan.radio = group.radio;
#if 0 /* Would require a 64 bit identifier */ #if 0 /* Would require a 64 bit identifier */
std::string id = channel["ID"].asString(); std::string id = channel["ID"].asString();
@ -85,8 +92,10 @@ bool OctonetData::loadChannelList()
ids >> chan.id; ids >> chan.id;
#endif #endif
chan.id = 1000 + channels.size(); chan.id = 1000 + channels.size();
group.members.push_back(channels.size());
channels.push_back(chan); channels.push_back(chan);
} }
groups.push_back(group);
} }
return true; return true;
@ -125,3 +134,62 @@ PVR_ERROR OctonetData::getChannels(ADDON_HANDLE handle, bool bRadio)
} }
return PVR_ERROR_NO_ERROR; 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;
}

View File

@ -36,6 +36,13 @@ struct OctonetChannel
int id; int id;
}; };
struct OctonetGroup
{
std::string name;
bool radio;
std::vector<int> members;
};
class OctonetData : public PLATFORM::CThread class OctonetData : public PLATFORM::CThread
{ {
public: public:
@ -45,12 +52,18 @@ class OctonetData : public PLATFORM::CThread
virtual int getChannelCount(void); virtual int getChannelCount(void);
virtual PVR_ERROR getChannels(ADDON_HANDLE handle, bool bRadio); 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: protected:
virtual bool loadChannelList(void); virtual bool loadChannelList(void);
virtual OctonetGroup* findGroup(const std::string &name);
virtual void *Process(void); virtual void *Process(void);
private: private:
std::string serverAddress; std::string serverAddress;
std::vector<OctonetChannel> channels; std::vector<OctonetChannel> channels;
std::vector<OctonetGroup> groups;
}; };

View File

@ -148,6 +148,7 @@ PVR_ERROR GetAddonCapabilities(PVR_ADDON_CAPABILITIES *pCapabilities)
{ {
pCapabilities->bSupportsTV = true; pCapabilities->bSupportsTV = true;
pCapabilities->bSupportsRadio = true; pCapabilities->bSupportsRadio = true;
pCapabilities->bSupportsChannelGroups = true;
return PVR_ERROR_NO_ERROR; 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; } PVR_ERROR GetEPGForChannel(ADDON_HANDLE handle, const PVR_CHANNEL& channel, time_t iStart, time_t iEnd) { return PVR_ERROR_NOT_IMPLEMENTED; }
/* Channel groups */ /* Channel groups */
int GetChannelGroupsAmount(void) { return -1; } int GetChannelGroupsAmount(void)
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; } 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 */ /* Channels */
PVR_ERROR OpenDialogChannelScan(void) { return PVR_ERROR_NOT_IMPLEMENTED; } PVR_ERROR OpenDialogChannelScan(void) { return PVR_ERROR_NOT_IMPLEMENTED; }