Skip to content

Commit

Permalink
Merge pull request #83 from ksooo/fix-ia-user-agent
Browse files Browse the repository at this point in the history
Fix playback: Add custom user agent to inputstream.adaptive properties.
  • Loading branch information
ksooo authored Aug 21, 2024
2 parents 0c7439e + 4d09cad commit 15d4909
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pvr.plutotv/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.plutotv"
version="22.1.0"
version="22.1.1"
name="Pluto.tv PVR Client"
provider-name="Team Kodi, flubshi">
<requires>@ADDON_DEPENDS@
Expand Down
3 changes: 3 additions & 0 deletions pvr.plutotv/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
v22.1.1
- Add custom user agent to inputstream.adaptive properties.

v22.1.0
- PVR Add-on API v9.0.0

Expand Down
37 changes: 37 additions & 0 deletions src/PlutotvData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
#include "Utils.h"
#include "kodi/tools/StringUtils.h"

#include <cctype>
#include <ctime>
#include <iomanip>
#include <ios>
#include <sstream>

namespace
{
Expand Down Expand Up @@ -66,6 +70,32 @@ PVR_ERROR PlutotvData::GetBackendVersion(std::string& version)
return PVR_ERROR_NO_ERROR;
}

namespace
{
// http://stackoverflow.com/a/17708801
const std::string UrlEncode(const std::string& value)
{
std::ostringstream escaped;
escaped.fill('0');
escaped << std::hex;

for (auto c : value)
{
// Keep alphanumeric and other accepted characters intact
if (std::isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~')
{
escaped << c;
continue;
}

// Any other characters are percent-encoded
escaped << '%' << std::setw(2) << int(static_cast<unsigned char>(c));
}

return escaped.str();
}
} // unnamed namespace

void PlutotvData::SetStreamProperties(std::vector<kodi::addon::PVRStreamProperty>& properties,
const std::string& url,
bool realtime)
Expand All @@ -77,6 +107,13 @@ void PlutotvData::SetStreamProperties(std::vector<kodi::addon::PVRStreamProperty
properties.emplace_back(PVR_STREAM_PROPERTY_ISREALTIMESTREAM, realtime ? "true" : "false");
// HLS
properties.emplace_back(PVR_STREAM_PROPERTY_MIMETYPE, "application/x-mpegURL");

const std::string encodedUserAgent{UrlEncode(PLUTOTV_USER_AGENT)};
properties.emplace_back("inputstream.adaptive.manifest_headers",
"User-Agent=" + encodedUserAgent);
properties.emplace_back("inputstream.adaptive.stream_headers",
"User-Agent=" + encodedUserAgent);

if (GetSettingsWorkaroundBrokenStreams())
properties.emplace_back("inputstream.adaptive.manifest_config",
"{\"hls_ignore_endlist\":true,\"hls_fix_mediasequence\":true,\"hls_fix_discsequence\":true}");
Expand Down

0 comments on commit 15d4909

Please sign in to comment.