12
12
#include " Utils.h"
13
13
#include " kodi/tools/StringUtils.h"
14
14
15
+ #include < cctype>
15
16
#include < ctime>
17
+ #include < iomanip>
18
+ #include < ios>
19
+ #include < sstream>
16
20
17
21
namespace
18
22
{
@@ -66,6 +70,32 @@ PVR_ERROR PlutotvData::GetBackendVersion(std::string& version)
66
70
return PVR_ERROR_NO_ERROR;
67
71
}
68
72
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
+
69
99
void PlutotvData::SetStreamProperties (std::vector<kodi::addon::PVRStreamProperty>& properties,
70
100
const std::string& url,
71
101
bool realtime)
@@ -77,6 +107,13 @@ void PlutotvData::SetStreamProperties(std::vector<kodi::addon::PVRStreamProperty
77
107
properties.emplace_back (PVR_STREAM_PROPERTY_ISREALTIMESTREAM, realtime ? " true" : " false" );
78
108
// HLS
79
109
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
+
80
117
if (GetSettingsWorkaroundBrokenStreams ())
81
118
properties.emplace_back (" inputstream.adaptive.manifest_config" ,
82
119
" {\" hls_ignore_endlist\" :true,\" hls_fix_mediasequence\" :true,\" hls_fix_discsequence\" :true}" );
0 commit comments