Skip to content

Commit

Permalink
feature: limit displayed channels depending on user subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
flubshi committed Apr 7, 2019
1 parent 9252401 commit 339c3dc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/WaipuData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "Base64.h"
#include "rapidjson/document.h"
#include <ctime>
#include <algorithm>


using namespace std;
using namespace ADDON;
Expand Down Expand Up @@ -150,10 +152,23 @@ bool WaipuData::ApiLogin()
jwt_doc.Parse(jwt_payload.c_str());
string userHandle = jwt_doc["userHandle"].GetString();
XBMC->Log(LOG_DEBUG, "[jwt] userHandle: %s", userHandle.c_str());
// generate the license
string license_plain = "{\"merchant\" : \"exaring\", \"sessionId\" : \"default\", \"userId\" : \""+userHandle+"\"}";
XBMC->Log(LOG_DEBUG, "[jwt] license_plain: %s", license_plain.c_str());
m_license = base64_encode(license_plain.c_str(),license_plain.length());
XBMC->Log(LOG_DEBUG, "[jwt] license: %s", m_license.c_str());
// get user channels
m_user_channels.clear();
for (const auto& user_channel : jwt_doc["userAssets"]["channels"]["SD"].GetArray()) {
string user_channel_s = user_channel.GetString();
XBMC->Log(LOG_DEBUG, "[jwt] SD channel: %s", user_channel_s.c_str());
m_user_channels.push_back(user_channel_s);
}
for (const auto& user_channel : jwt_doc["userAssets"]["channels"]["HD"].GetArray()) {
string user_channel_s = user_channel.GetString();
m_user_channels.push_back(user_channel_s);
XBMC->Log(LOG_DEBUG, "[jwt] HD channel: %s", user_channel_s.c_str());
}
}
return true;
}
Expand Down Expand Up @@ -213,12 +228,16 @@ bool WaipuData::LoadChannelData(void)

int i = 0;
for (const auto& channel : channelsDoc["result"].GetArray()) {
string waipuid = channel["id"].GetString();
// check if channel is part of user channels:
if (find(m_user_channels.begin(), m_user_channels.end(), waipuid.c_str()) == m_user_channels.end())
continue;

++i;
WaipuChannel waipu_channel;
waipu_channel.iUniqueId = i;
XBMC->Log(LOG_DEBUG, "[channel] id: %i;",waipu_channel.iUniqueId);

string waipuid = channel["id"].GetString();
waipu_channel.waipuID = waipuid; // waipu[id]
XBMC->Log(LOG_DEBUG, "[channel] waipuid: %s;",waipu_channel.waipuID.c_str());

Expand Down
1 change: 1 addition & 0 deletions src/WaipuData.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,5 @@ class WaipuData
std::string m_license;
int m_recordings_count;
bool m_active_recordings_update;
std::vector<string> m_user_channels;
};

0 comments on commit 339c3dc

Please sign in to comment.