Skip to content

Commit

Permalink
Fix refresh token on update, obey channel age rating
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvana-7777 committed May 13, 2024
1 parent 0212764 commit 45deaef
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 26 deletions.
2 changes: 1 addition & 1 deletion pvr.eon/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.eon"
version="21.7.6"
version="21.7.8"
name="EON PVR Client"
provider-name="Nirvana">
<requires>
Expand Down
6 changes: 5 additions & 1 deletion pvr.eon/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@ v21.7.4
- Exploit some more EPG data (live, age, seasons, episodes)
v21.7.5
- Fix startup with empty credentials and web
v20.7.6
v21.7.6
- Try to fix armv7a
v21.7.7
- Fix refresh token when updating
v21.7.8
- New Setting filter for channel age rating
4 changes: 4 additions & 0 deletions pvr.eon/resources/language/resource.language.de_de/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ msgctxt "#30055"
msgid "Please enter or correct username and password in the settings"
msgstr "Bitte Usernamen und Passwort in den Einstellungen ändern"

msgctxt "#30056"
msgid "Age Rating"
msgstr "Altersfreigabe"

msgctxt "#30500"
msgid "Inputstream error"
msgstr "Inputstream Fehler"
Expand Down
5 changes: 5 additions & 0 deletions pvr.eon/resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ msgctxt "#30055"
msgid "Please enter or correct username and password in the settings"
msgstr ""

msgctxt "#30056"
msgid "Age Rating"
msgstr ""


msgctxt "#30500"
msgid "Inputstream error"
msgstr ""
Expand Down
4 changes: 4 additions & 0 deletions pvr.eon/resources/language/resource.language.en_us/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ msgctxt "#30055"
msgid "Please enter or correct username and password in the settings"
msgstr ""

msgctxt "#30056"
msgid "Age Rating"
msgstr ""

msgctxt "#30500"
msgid "Inputstream error"
msgstr ""
Expand Down
8 changes: 8 additions & 0 deletions pvr.eon/resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,14 @@
</constraints>
<control type="edit" format="integer" />
</setting>
<setting id="agerating" type="integer" label="30056">
<level>0</level>
<default>18</default>
<constraints>
<allowempty>false</allowempty>
</constraints>
<control type="edit" format="integer" />
</setting>
</group>
</category>
<category id="streaming" label="30049">
Expand Down
2 changes: 1 addition & 1 deletion src/Globals.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright (C) 2011-2021 Team Kodi (https://kodi.tv)
* Copyright (C) 2011 Pulse-Eight (http://www.pulse-eight.com/)
*
Expand Down
43 changes: 22 additions & 21 deletions src/PVREon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,26 +311,19 @@ bool CPVREon::GetDeviceFromSerial()
{
std::string postData;

if (m_platform == PLATFORM_ANDROIDTV) {
postData = "{\"deviceName\":\"" + EonParameters[m_platform].device_name +
"\",\"deviceType\":\"" + EonParameters[m_platform].device_type +
"\",\"modelName\":\"" + EonParameters[m_platform].device_model +
"\",\"platform\":\"" + EonParameters[m_platform].device_platform +
"\",\"serial\":\"" + m_device_serial +
"\",\"clientSwVersion\":\"" + EonParameters[m_platform].client_sw_version +
"\",\"clientSwBuild\":\"" + EonParameters[m_platform].client_sw_build +
"\",\"systemSwVersion\":{\"name\":\"" + EonParameters[m_platform].system_sw +
"\",\"version\":\"" + EonParameters[m_platform].system_version +
"\"},\"fcmToken\":\"\"}";
//TODO: implement parameter fcmToken...
} else {
postData = "{\"deviceName\":\"\",\"deviceType\":\"" + EonParameters[m_platform].device_type +
"\",\"modelName\":\"" + EonParameters[m_platform].device_model +
"\",\"platform\":\"" + EonParameters[m_platform].device_platform +
"\",\"serial\":\"" + m_device_serial +
"\",\"clientSwVersion\":\"\",\"systemSwVersion\":{\"name\":\"" + EonParameters[m_platform].system_sw +
"\",\"version\":\"" + EonParameters[m_platform].system_version + "\"}}";
}
postData = "{\"deviceName\":\"" + EonParameters[m_platform].device_name +
"\",\"deviceType\":\"" + EonParameters[m_platform].device_type +
"\",\"modelName\":\"" + EonParameters[m_platform].device_model +
"\",\"platform\":\"" + EonParameters[m_platform].device_platform +
"\",\"serial\":\"" + m_device_serial +
"\",\"clientSwVersion\":\"" + EonParameters[m_platform].client_sw_version;
if (m_platform == PLATFORM_ANDROIDTV)
postData += "\",\"clientSwBuild\":\"" + EonParameters[m_platform].client_sw_build;
postData += "\",\"systemSwVersion\":{\"name\":\"" + EonParameters[m_platform].system_sw +
"\",\"version\":\"" + EonParameters[m_platform].system_version + "\"}";
if (m_platform == PLATFORM_ANDROIDTV)
postData += ",\"fcmToken\":\"\""; //TODO: implement parameter fcmToken...
postData += "}";

std::string url = m_api + "v1/devices";

Expand Down Expand Up @@ -660,6 +653,13 @@ bool CPVREon::LoadChannels(const bool isRadio)

eon_channel.aaEnabled = Utils::JsonBoolOrFalse(channelItem, "aaEnabled");
eon_channel.subscribed = Utils::JsonBoolOrFalse(channelItem, "subscribed");
int ageRating = 0;
try {
ageRating = std::stoi(Utils::JsonStringOrEmpty(channelItem,"ageRating"));
} catch (std::invalid_argument&e) {

}
eon_channel.ageRating = ageRating;
const rapidjson::Value& categories = channelItem["categories"];
for (rapidjson::Value::ConstValueIterator itr2 = categories.Begin();
itr2 != categories.End(); ++itr2)
Expand Down Expand Up @@ -1022,7 +1022,8 @@ PVR_ERROR CPVREon::GetChannels(bool bRadio, kodi::addon::PVRChannelsResultSet& r
for (const auto& channel : m_channels)
{

if (channel.bRadio == bRadio)
int ageRating = m_settings->GetAgeRating();
if (channel.bRadio == bRadio && ageRating >= channel.ageRating)
{
kodi::addon::PVRChannel kodiChannel;

Expand Down
3 changes: 1 addition & 2 deletions src/PVREon.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct EonChannel
std::string sig;
bool aaEnabled;
bool subscribed;
int ageRating;
// std::string strStreamURL;
};

Expand Down Expand Up @@ -158,8 +159,6 @@ class ATTR_DLL_LOCAL CPVREon : public kodi::addon::CAddonBase,
bool GetServer(bool isLive, EonServer& myServer);

private:
PVR_ERROR CallMenuHook(const kodi::addon::PVRMenuhook& menuhook);

void SetStreamProperties(std::vector<kodi::addon::PVRStreamProperty>& properties,
const std::string& url,
const bool& realtime, const bool& playTimeshiftBuffer, const bool& isLive /*,
Expand Down
7 changes: 7 additions & 0 deletions src/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ bool CSettings::Load()
return false;
}

if (!kodi::addon::CheckSettingInt("agerating", m_eonAgeRating))
{
/* If setting is unknown fallback to defaults */
kodi::Log(ADDON_LOG_ERROR, "Couldn't get 'agerating' setting");
return false;
}

return true;
}

Expand Down
2 changes: 2 additions & 0 deletions src/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ATTR_DLL_LOCAL CSettings
const int& GetEonServiceProvider() const { return m_eonServiceProvider; }
const int& GetPlatform() const { return m_eonPlatform; }
const int& GetInputstream() const { return m_eonInputstream; }
const int& GetAgeRating() const { return m_eonAgeRating; }
const std::string& GetEonUsername() const { return m_eonUsername; }
const std::string& GetEonPassword() const { return m_eonPassword; }
const std::string& GetEonAccessToken() const { return m_eonAccessToken; }
Expand All @@ -46,6 +47,7 @@ class ATTR_DLL_LOCAL CSettings
int m_eonServiceProvider;
int m_eonPlatform;
int m_eonInputstream;
int m_eonAgeRating;
std::string m_eonUsername;
std::string m_eonPassword;
std::string m_eonAccessToken;
Expand Down
12 changes: 12 additions & 0 deletions src/http/HttpClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,18 @@ std::string HttpClient::HttpRequest(const std::string& action, const std::string
}
if (refresh_successful) {
content = HttpRequestToCurl(curl_reauth, action, url, postData, statusCode);
} else {
std::string refresh_token = m_settings->GetEonRefreshToken();
if (!refresh_token.empty() && !(url.find(BROKER_URL) != std::string::npos || url.find("v1/devices") != std::string::npos)) {
// Try to get new token as last resort
m_settings->SetSetting("refreshtoken", "");
refresh_successful = RefreshToken();
access_token = m_settings->GetEonAccessToken();
curl_reauth.AddHeader("Authorization", "bearer " + access_token);
if (refresh_successful) {
content = HttpRequestToCurl(curl_reauth, action, url, postData, statusCode);
}
}
}
}

Expand Down

0 comments on commit 45deaef

Please sign in to comment.