Skip to content

Commit 15d4909

Browse files
authored
Merge pull request #83 from ksooo/fix-ia-user-agent
Fix playback: Add custom user agent to inputstream.adaptive properties.
2 parents 0c7439e + 4d09cad commit 15d4909

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

pvr.plutotv/addon.xml.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<addon
33
id="pvr.plutotv"
4-
version="22.1.0"
4+
version="22.1.1"
55
name="Pluto.tv PVR Client"
66
provider-name="Team Kodi, flubshi">
77
<requires>@ADDON_DEPENDS@

pvr.plutotv/changelog.txt

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
v22.1.1
2+
- Add custom user agent to inputstream.adaptive properties.
3+
14
v22.1.0
25
- PVR Add-on API v9.0.0
36

src/PlutotvData.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
#include "Utils.h"
1313
#include "kodi/tools/StringUtils.h"
1414

15+
#include <cctype>
1516
#include <ctime>
17+
#include <iomanip>
18+
#include <ios>
19+
#include <sstream>
1620

1721
namespace
1822
{
@@ -66,6 +70,32 @@ PVR_ERROR PlutotvData::GetBackendVersion(std::string& version)
6670
return PVR_ERROR_NO_ERROR;
6771
}
6872

73+
namespace
74+
{
75+
// http://stackoverflow.com/a/17708801
76+
const std::string UrlEncode(const std::string& value)
77+
{
78+
std::ostringstream escaped;
79+
escaped.fill('0');
80+
escaped << std::hex;
81+
82+
for (auto c : value)
83+
{
84+
// Keep alphanumeric and other accepted characters intact
85+
if (std::isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~')
86+
{
87+
escaped << c;
88+
continue;
89+
}
90+
91+
// Any other characters are percent-encoded
92+
escaped << '%' << std::setw(2) << int(static_cast<unsigned char>(c));
93+
}
94+
95+
return escaped.str();
96+
}
97+
} // unnamed namespace
98+
6999
void PlutotvData::SetStreamProperties(std::vector<kodi::addon::PVRStreamProperty>& properties,
70100
const std::string& url,
71101
bool realtime)
@@ -77,6 +107,13 @@ void PlutotvData::SetStreamProperties(std::vector<kodi::addon::PVRStreamProperty
77107
properties.emplace_back(PVR_STREAM_PROPERTY_ISREALTIMESTREAM, realtime ? "true" : "false");
78108
// HLS
79109
properties.emplace_back(PVR_STREAM_PROPERTY_MIMETYPE, "application/x-mpegURL");
110+
111+
const std::string encodedUserAgent{UrlEncode(PLUTOTV_USER_AGENT)};
112+
properties.emplace_back("inputstream.adaptive.manifest_headers",
113+
"User-Agent=" + encodedUserAgent);
114+
properties.emplace_back("inputstream.adaptive.stream_headers",
115+
"User-Agent=" + encodedUserAgent);
116+
80117
if (GetSettingsWorkaroundBrokenStreams())
81118
properties.emplace_back("inputstream.adaptive.manifest_config",
82119
"{\"hls_ignore_endlist\":true,\"hls_fix_mediasequence\":true,\"hls_fix_discsequence\":true}");

0 commit comments

Comments
 (0)