Skip to content

Commit

Permalink
[StreamUtils] Set headers also on inputstream.adaptive.stream_headers
Browse files Browse the repository at this point in the history
Usually if a service require user-agent header must be set on both manifests and streams
  • Loading branch information
CastagnaIT committed Aug 21, 2024
1 parent 2ade200 commit 6bf0486
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions src/iptvsimple/utilities/StreamUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,25 @@ using namespace iptvsimple;
using namespace iptvsimple::data;
using namespace iptvsimple::utilities;

namespace
{
bool SplitUrlProtocolOpts(const std::string& streamURL,
std::string& url,
std::string& encodedProtocolOptions)
{
size_t found = streamURL.find_first_of('|');
if (found != std::string::npos)
{
// Headers found, split and url-encode them
url = streamURL.substr(0, found);
const std::string& protocolOptions = streamURL.substr(found + 1, streamURL.length());
encodedProtocolOptions = StreamUtils::GetUrlEncodedProtocolOptions(protocolOptions);
return true;
}
return false;
}
} // unnamed namespace

void StreamUtils::SetAllStreamProperties(std::vector<kodi::addon::PVRStreamProperty>& properties, const iptvsimple::data::Channel& channel, const std::string& streamURL, bool isChannelURL, std::map<std::string, std::string>& catchupProperties, std::shared_ptr<InstanceSettings>& settings)
{
if (ChannelSpecifiesInputstream(channel))
Expand Down Expand Up @@ -83,19 +102,17 @@ void StreamUtils::SetAllStreamProperties(std::vector<kodi::addon::PVRStreamPrope
// If no media headers are explicitly set for inputstream.adaptive,
// strip the headers from streamURL and put it to media headers property

if (channel.GetProperty("inputstream.adaptive.stream_headers").empty())
if (channel.GetProperty("inputstream.adaptive.manifest_headers").empty() &&
channel.GetProperty("inputstream.adaptive.stream_headers").empty())
{
// No stream headers declared by property, check if stream URL has any
size_t found = streamURL.find_first_of('|');
if (found != std::string::npos)
std::string url;
std::string encodedProtocolOptions;
if (SplitUrlProtocolOpts(streamURL, url, encodedProtocolOptions))
{
// Headers found, split and url-encode them
const std::string& url = streamURL.substr(0, found);
const std::string& protocolOptions = streamURL.substr(found + 1, streamURL.length());
const std::string& encodedProtocolOptions = StreamUtils::GetUrlEncodedProtocolOptions(protocolOptions);

// Set stream URL without headers and encoded headers as property
properties.emplace_back(PVR_STREAM_PROPERTY_STREAMURL, url);
properties.emplace_back("inputstream.adaptive.manifest_headers", encodedProtocolOptions);
properties.emplace_back("inputstream.adaptive.stream_headers", encodedProtocolOptions);
streamUrlSet = true;
}
Expand Down

0 comments on commit 6bf0486

Please sign in to comment.