Skip to content

Commit

Permalink
Merge pull request #48 from flubshi/matrix_channelgroups
Browse files Browse the repository at this point in the history
Matrix: Implement channel groups
  • Loading branch information
flubshi authored Nov 30, 2019
2 parents 619eff1 + 2316df9 commit 2e4868a
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 20 deletions.
3 changes: 2 additions & 1 deletion pvr.waipu/addon.xml.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<addon
id="pvr.waipu"
version="1.3.0"
version="1.3.1"
name="waipu.tv PVR Client"
provider-name="flubshi">
<requires>@ADDON_DEPENDS@
Expand Down Expand Up @@ -29,6 +29,7 @@
<screenshot>resources/screenshots/screenshot-02.jpg</screenshot>
</assets>
<news>
- 1.3.1 Add channel groups: display favorites
- 1.3.0 Implement O2 authentication
- 1.2.4 Fix Ubuntu packaging: adjust rapidjson dependency
- 1.2.3 Fix Ubuntu packaging: add rapidjson dependency
Expand Down
9 changes: 9 additions & 0 deletions src/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ int Utils::GetIDDirty(std::string str)
return rand() % 99999 + 1;
}

int Utils::GetChannelId(const char* strChannelName)
{
int iId = 0;
int c;
while ((c = *strChannelName++))
iId = ((iId << 5) + iId) + c; /* iId * 33 + c */
return abs(iId);
}

int Utils::stoiDefault(std::string str, int i)
{
try
Expand Down
5 changes: 4 additions & 1 deletion src/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ class Utils
static time_t StringToTime(std::string timeString);
static std::string ltrim(std::string str, const std::string chars = "\t\n\v\f\r _");
static int GetIDDirty(std::string str);
static int GetChannelId(const char* strChannelName);
static int stoiDefault(std::string str, int i);
static bool ends_with(std::string const& haystack, std::string const& end);
static std::string ReplaceAll(std::string str, const std::string& search, const std::string& replace);
static std::string ReplaceAll(std::string str,
const std::string& search,
const std::string& replace);
};
58 changes: 50 additions & 8 deletions src/WaipuData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ bool WaipuData::O2Login()
string input_name = match.str(1);
string input_value = match.str(2);
// we need to dirty HTML-decode &#x3d; to = for base64 padding:
input_value = Utils::ReplaceAll(input_value,"&#x3d;","=");
input_value = Utils::ReplaceAll(input_value, "&#x3d;", "=");

XBMC->Log(LOG_DEBUG, "[form input] %s -> %s;", input_name.c_str(), input_value.c_str());

Expand Down Expand Up @@ -368,6 +368,7 @@ WaipuData::WaipuData(const string& user, const string& pass, const WAIPU_PROVIDE
WaipuData::~WaipuData(void)
{
m_channels.clear();
m_channelGroups.clear();
m_apiToken = {};
}

Expand Down Expand Up @@ -404,6 +405,10 @@ bool WaipuData::LoadChannelData(void)
XBMC->Log(LOG_DEBUG, "[channels] iterate channels");
XBMC->Log(LOG_DEBUG, "[channels] size: %i;", channelsDoc["result"].Size());


WaipuChannelGroup favgroup;
favgroup.name = "Favoriten";

int i = 0;
for (const auto& channel : channelsDoc["result"].GetArray())
{
Expand Down Expand Up @@ -431,9 +436,9 @@ bool WaipuData::LoadChannelData(void)
waipu_channel.waipuID = waipuid; // waipu[id]
XBMC->Log(LOG_DEBUG, "[channel] waipuid: %s;", waipu_channel.waipuID.c_str());

int orderindex = channel["orderIndex"].GetUint() + 1;
waipu_channel.iUniqueId = orderindex; // waipu[orderIndex]
XBMC->Log(LOG_DEBUG, "[channel] id: %i;", orderindex);
int uniqueId = Utils::GetChannelId(waipuid.c_str());
waipu_channel.iUniqueId = uniqueId;
XBMC->Log(LOG_DEBUG, "[channel] id: %i;", uniqueId);

string displayName = channel["displayName"].GetString();
waipu_channel.strChannelName = displayName; // waipu[displayName]
Expand Down Expand Up @@ -483,9 +488,15 @@ bool WaipuData::LoadChannelData(void)
}
XBMC->Log(LOG_DEBUG, "[channel] selected channel logo: %s", waipu_channel.strIconPath.c_str());

bool isFav = channel["faved"].GetBool();
if(isFav)
favgroup.channels.push_back(waipu_channel);

m_channels.push_back(waipu_channel);
}

m_channelGroups.push_back(favgroup);

return true;
}

Expand Down Expand Up @@ -571,17 +582,48 @@ string WaipuData::GetChannelStreamUrl(int uniqueId, const string& protocol)

int WaipuData::GetChannelGroupsAmount(void)
{
return -1;
return static_cast<int>(m_channelGroups.size());
}

PVR_ERROR WaipuData::GetChannelGroups(ADDON_HANDLE handle, bool bRadio)
PVR_ERROR WaipuData::GetChannelGroups(ADDON_HANDLE handle)
{
return PVR_ERROR_NOT_IMPLEMENTED;
std::vector<WaipuChannelGroup>::iterator it;
for (it = m_channelGroups.begin(); it != m_channelGroups.end(); ++it)
{
PVR_CHANNEL_GROUP xbmcGroup;
memset(&xbmcGroup, 0, sizeof(PVR_CHANNEL_GROUP));
xbmcGroup.iPosition = 0; /* not supported */
xbmcGroup.bIsRadio = false; /* is radio group */
strncpy(xbmcGroup.strGroupName, it->name.c_str(), sizeof(xbmcGroup.strGroupName) - 1);

PVR->TransferChannelGroup(handle, &xbmcGroup);
}
return PVR_ERROR_NO_ERROR;
}

PVR_ERROR WaipuData::GetChannelGroupMembers(ADDON_HANDLE handle, const PVR_CHANNEL_GROUP& group)
{
return PVR_ERROR_NOT_IMPLEMENTED;
for (const auto& cgroup : m_channelGroups)
{
if (cgroup.name != group.strGroupName)
continue;

for (const auto& channel : cgroup.channels)
{
PVR_CHANNEL_GROUP_MEMBER xbmcGroupMember;
memset(&xbmcGroupMember, 0, sizeof(PVR_CHANNEL_GROUP_MEMBER));

strncpy(xbmcGroupMember.strGroupName, group.strGroupName,
sizeof(xbmcGroupMember.strGroupName) - 1);
xbmcGroupMember.iChannelUniqueId = static_cast<unsigned int>(channel.iUniqueId);
xbmcGroupMember.iChannelNumber = static_cast<unsigned int>(channel.iChannelNumber);

PVR->TransferChannelGroupMember(handle, &xbmcGroupMember);
}
return PVR_ERROR_NO_ERROR;
}

return PVR_ERROR_NO_ERROR;
}

PVR_ERROR WaipuData::GetEPGForChannel(ADDON_HANDLE handle,
Expand Down
11 changes: 9 additions & 2 deletions src/WaipuData.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,20 @@ struct WaipuApiToken

struct WaipuChannel
{
int iUniqueId; //waipu[orderIndex]
int iUniqueId;
string waipuID; // waipu[id]
int iChannelNumber; //position
string strChannelName; //waipu[displayName]
string strIconPath; // waipu[links][rel=iconlargehd]
string strStreamURL; // waipu[links][rel=livePlayout]
};

struct WaipuChannelGroup
{
std::string name;
std::vector<WaipuChannel> channels;
};

struct WaipuEPGMappingEntry
{
int iBroadcastId;
Expand All @@ -76,7 +82,7 @@ class WaipuData
PVR_ERROR GetChannels(ADDON_HANDLE handle, bool bRadio);

int GetChannelGroupsAmount(void);
PVR_ERROR GetChannelGroups(ADDON_HANDLE handle, bool bRadio);
PVR_ERROR GetChannelGroups(ADDON_HANDLE handle);
PVR_ERROR GetChannelGroupMembers(ADDON_HANDLE handle, const PVR_CHANNEL_GROUP& group);

virtual string GetChannelStreamUrl(int uniqueId, const string& protocol);
Expand Down Expand Up @@ -111,6 +117,7 @@ class WaipuData
private:
bool ParseAccessToken(void);
std::vector<WaipuChannel> m_channels;
std::vector<WaipuChannelGroup> m_channelGroups;
std::string username;
std::string password;
WaipuApiToken m_apiToken;
Expand Down
32 changes: 24 additions & 8 deletions src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,14 @@ extern "C"
}
if (XBMC->GetSetting("provider_select", &intBuffer))
{
if(intBuffer == 0){
provider = WAIPU_PROVIDER_WAIPU;
}else{
provider = WAIPU_PROVIDER_O2;
}
if (intBuffer == 0)
{
provider = WAIPU_PROVIDER_WAIPU;
}
else
{
provider = WAIPU_PROVIDER_O2;
}
}
XBMC->Log(LOG_DEBUG, "End Readsettings");
}
Expand Down Expand Up @@ -224,6 +227,7 @@ extern "C"
pCapabilities->bSupportsTV = true;
pCapabilities->bSupportsRecordings = true;
pCapabilities->bSupportsTimers = true;
pCapabilities->bSupportsChannelGroups = true;

return PVR_ERROR_NO_ERROR;
}
Expand Down Expand Up @@ -360,13 +364,25 @@ extern "C"
return ret;
}

int GetChannelGroupsAmount(void) { return -1; }
int GetChannelGroupsAmount(void) { return m_data->GetChannelGroupsAmount(); }

PVR_ERROR GetChannelGroups(ADDON_HANDLE handle, bool bRadio)
{
if (bRadio)
return PVR_ERROR_NO_ERROR;

PVR_ERROR GetChannelGroups(ADDON_HANDLE handle, bool bRadio) { return PVR_ERROR_NOT_IMPLEMENTED; }
if (m_data)
return m_data->GetChannelGroups(handle);

return PVR_ERROR_SERVER_ERROR;
}

PVR_ERROR GetChannelGroupMembers(ADDON_HANDLE handle, const PVR_CHANNEL_GROUP& group)
{
return PVR_ERROR_NOT_IMPLEMENTED;
if (m_data)
return m_data->GetChannelGroupMembers(handle, group);

return PVR_ERROR_SERVER_ERROR;
}

PVR_ERROR SignalStatus(PVR_SIGNAL_STATUS& signalStatus) { return PVR_ERROR_NOT_IMPLEMENTED; }
Expand Down

0 comments on commit 2e4868a

Please sign in to comment.