diff --git a/src/Curl.h b/src/Curl.h index d7847f0..d064c4d 100644 --- a/src/Curl.h +++ b/src/Curl.h @@ -29,7 +29,7 @@ class Curl void ResetHeaders(); virtual std::string GetCookie(const std::string& name); void SetCookie(const std::string& host, const std::string& name, const std::string& value); - std::string GetLocation() { return m_location; } + const std::string& GetLocation() const { return m_location; } void SetRedirectLimit(int limit) { m_redirectLimit = limit; } private: diff --git a/src/JWT.h b/src/JWT.h index e811bdf..19e8ce0 100644 --- a/src/JWT.h +++ b/src/JWT.h @@ -27,14 +27,14 @@ class JWT { public: - JWT(std::string token); - JWT(){}; + explicit JWT(std::string token); + explicit JWT(){}; bool isExpired(int offset = 0) const; - std::string getToken() { return strToken; }; - int getExp() { return exp; }; - bool isInitialized() { return initialized; }; + const std::string& getToken() const { return strToken; }; + int getExp() const { return exp; }; + bool isInitialized() const { return initialized; }; rapidjson::Document parsedToken; // bad, I know.. private: diff --git a/src/WaipuData.cpp b/src/WaipuData.cpp index 51abde1..4846d60 100644 --- a/src/WaipuData.cpp +++ b/src/WaipuData.cpp @@ -543,8 +543,6 @@ bool WaipuData::RefreshDeviceCapabiltiesToken() kodi::Log(ADDON_LOG_DEBUG, "[X-Device-Token] response: %s", jsonDeviceToken.c_str()); - std::string deviceToken; - rapidjson::Document deviceTokenDoc; deviceTokenDoc.Parse(jsonDeviceToken.c_str()); if (deviceTokenDoc.HasParseError()) @@ -693,7 +691,7 @@ PVR_ERROR WaipuData::GetBackendVersion(std::string& version) return PVR_ERROR_NO_ERROR; } -std::string WaipuData::GetLicense() +const std::string& WaipuData::GetLicense() { return m_license; } @@ -951,16 +949,14 @@ PVR_ERROR WaipuData::GetChannelStreamProperties( { // use hls where possible, fallback to dash protocol = "dash"; - for (const auto& thisChannel : m_channels) + + const std::vector::iterator thisChannel = + std::find_if(m_channels.begin(), m_channels.end(), + [&](const WaipuChannel& v) { return v.iUniqueId == channel.GetUniqueId(); }); + + if (thisChannel != m_channels.end() && m_hls_allowlist.contains(thisChannel->waipuID)) { - if (thisChannel.iUniqueId == channel.GetUniqueId()) - { - if (m_hls_allowlist.contains(thisChannel.waipuID)) - { - protocol = "hls"; - } - break; - } + protocol = "hls"; } kodi::Log(ADDON_LOG_DEBUG, "protocol auto select: %s", protocol.c_str()); } @@ -1073,8 +1069,8 @@ PVR_ERROR WaipuData::GetChannelGroupMembers(const kodi::addon::PVRChannelGroup& { if (group.GetIsRadio()) { - kodi::Log(ADDON_LOG_ERROR, - "[%s] ERROR: Function was called with a group having 'radio: true'", __FUNCTION__); + kodi::Log(ADDON_LOG_ERROR, "[%s] ERROR: Function was called with a group having 'radio: true'", + __FUNCTION__); return PVR_ERROR_INVALID_PARAMETERS; } @@ -1295,7 +1291,6 @@ PVR_ERROR WaipuData::GetEPGForChannelNew(int channelUid, std::transform(channelid.begin(), channelid.end(), channelid.begin(), ::tolower); kodi::Log(ADDON_LOG_DEBUG, "[epg-new] channel: %s", channelid.c_str()); - std::string endTime = Utils::TimeToString(end); int limit = 32; @@ -1520,7 +1515,6 @@ std::string WaipuData::GetEPGTagURL(const kodi::addon::PVREPGTag& tag, const std // fallback to replay playback kodi::Log(ADDON_LOG_DEBUG, "[play epg tag] streamUrlProvider not found -> fallback to replay!"); - std::string startTime = std::to_string(tag.GetStartTime()); return GetChannelStreamURL(tag.GetUniqueChannelId(), protocol, startTime); } @@ -1836,7 +1830,7 @@ PVR_ERROR WaipuData::DeleteRecording(const kodi::addon::PVRRecording& recording) std::string request_data = "{\"ids\":[\"" + recording_id + "\"]}"; kodi::Log(ADDON_LOG_DEBUG, "[delete recording] req: %s;", request_data.c_str()); std::string deleted = - HttpDelete("https://recording.waipu.tv/api/recordings", request_data.c_str(), + HttpDelete("https://recording.waipu.tv/api/recordings", request_data, {{"Content-Type", "application/vnd.waipu.pvr-recording-ids-v2+json"}}); kodi::Log(ADDON_LOG_DEBUG, "[delete recording] response: %s;", deleted.c_str()); kodi::addon::CInstancePVRClient::TriggerRecordingUpdate(); @@ -2047,7 +2041,7 @@ PVR_ERROR WaipuData::DeleteTimer(const kodi::addon::PVRTimer& timer, bool forceD std::string request_data = "{\"ids\":[\"" + std::to_string(timer_id) + "\"]}"; kodi::Log(ADDON_LOG_DEBUG, "[delete single timer] req: %s;", request_data.c_str()); std::string deleted = - HttpDelete("https://recording.waipu.tv/api/recordings", request_data.c_str(), + HttpDelete("https://recording.waipu.tv/api/recordings", request_data, {{"Content-Type", "application/vnd.waipu.pvr-recording-ids-v2+json"}}); kodi::Log(ADDON_LOG_DEBUG, "[delete single timer] response: %s;", deleted.c_str()); kodi::QueueNotification(QUEUE_INFO, "Recording", "Recording Deleted"); @@ -2065,7 +2059,7 @@ PVR_ERROR WaipuData::DeleteTimer(const kodi::addon::PVRTimer& timer, bool forceD kodi::Log(ADDON_LOG_DEBUG, "[delete multi timer] req (group: %i): %s;", groupID, request_data.c_str()); std::string deleted = - HttpPost("https://recording-scheduler.waipu.tv/api/delete-requests", request_data.c_str(), + HttpPost("https://recording-scheduler.waipu.tv/api/delete-requests", request_data, {{"Content-Type", "application/vnd.waipu.recording-scheduler-delete-serial-recordings-v1+json"}}); kodi::Log(ADDON_LOG_DEBUG, "[delete multi timer] response: %s;", deleted.c_str()); @@ -2162,7 +2156,7 @@ PVR_ERROR WaipuData::GetDriveSpace(uint64_t& total, uint64_t& used) if (!IsConnected()) return PVR_ERROR_SERVER_ERROR; - total = m_account_hours_recording * 1024 * 1024; + total = m_account_hours_recording * 1024l * 1024l; used = m_finishedRecordingsSeconds > 0 ? m_finishedRecordingsSeconds * 1024 * 1024 / 3600 : 0; return PVR_ERROR_NO_ERROR; @@ -2224,8 +2218,7 @@ PVR_ERROR WaipuData::SetRecordingLastPlayedPosition(const kodi::addon::PVRRecord std::string request_data = "{\"position\":" + std::to_string(lastplayedposition) + "}"; std::string response = HttpRequest( "PUT", "https://stream-position.waipu.tv/api/stream-positions/" + recording.GetRecordingId(), - request_data.c_str(), - {{"Content-Type", "application/vnd.waipu.stream-position-request.v1+json"}}); + request_data, {{"Content-Type", "application/vnd.waipu.stream-position-request.v1+json"}}); kodi::Log(ADDON_LOG_DEBUG, "%s - Response: %s", __FUNCTION__, response.c_str()); return PVR_ERROR_NO_ERROR; diff --git a/src/WaipuData.h b/src/WaipuData.h index 9cf3610..dc0414b 100644 --- a/src/WaipuData.h +++ b/src/WaipuData.h @@ -160,7 +160,7 @@ class ATTR_DLL_LOCAL WaipuData : public kodi::addon::CAddonBase, std::string m_userhandle = ""; std::string m_protocol; std::string m_device_id; - WAIPU_PROVIDER m_provider; + WAIPU_PROVIDER m_provider = WAIPU_PROVIDER_WAIPU; std::vector m_channels; std::vector m_channelGroups; @@ -188,7 +188,7 @@ class ATTR_DLL_LOCAL WaipuData : public kodi::addon::CAddonBase, void ReadSettings(); bool ParseAccessToken(); - void AddTimerType(std::vector& types, int idx, int attributes); + void AddTimerType(std::vector& types, int id, int attributes); std::string GetChannelStreamURL(int uniqueId, const std::string& protocol, @@ -196,7 +196,7 @@ class ATTR_DLL_LOCAL WaipuData : public kodi::addon::CAddonBase, std::string GetRecordingURL(const kodi::addon::PVRRecording& recording, const std::string& protocol); std::string GetEPGTagURL(const kodi::addon::PVREPGTag& tag, const std::string& protocol); - std::string GetLicense(); + const std::string& GetLicense(); const std::map GetOAuthDeviceCode(const std::string& tenant); const std::map CheckOAuthState(const std::string& device_code); void SetStreamProperties(std::vector& properties,