Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[backport][PlaylistLoader] Fix KODIPROP parsing / revert-restored a wrong commit #890

Merged
merged 4 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pvr.iptvsimple/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.iptvsimple"
version="21.8.6"
version="21.8.7"
name="IPTV Simple Client"
provider-name="nightik and Ross Nicholson">
<requires>@ADDON_DEPENDS@
Expand Down
4 changes: 4 additions & 0 deletions pvr.iptvsimple/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v21.8.7
- Fix #KODIPROP parsing from playlists
- Fix wrong fix to manifest user-agent header for inputstream.adaptive

v21.8.6
- Always add mimetype for inputstream.adaptive
- Better handled user-agent header for inputstream.adaptive use cases
Expand Down
38 changes: 24 additions & 14 deletions src/iptvsimple/PlaylistLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ void PlaylistLoader::ParseAndAddChannelGroups(const std::string& groupNamesListS

void PlaylistLoader::ParseSinglePropertyIntoChannel(const std::string& line, Channel& channel, const std::string& markerName)
{
const std::string value = ReadMarkerValue(line, markerName);
const std::string value = ReadMarkerValue(line, markerName, markerName != KODIPROP_MARKER);
auto pos = value.find('=');
if (pos != std::string::npos)
{
Expand Down Expand Up @@ -604,7 +604,9 @@ void PlaylistLoader::ReloadPlayList()
}
}

std::string PlaylistLoader::ReadMarkerValue(const std::string& line, const std::string& markerName)
std::string PlaylistLoader::ReadMarkerValue(const std::string& line,
const std::string& markerName,
bool isCheckDelimiters /* = true */)
{
size_t markerStart = line.find(markerName);
if (markerStart != std::string::npos)
Expand All @@ -613,21 +615,29 @@ std::string PlaylistLoader::ReadMarkerValue(const std::string& line, const std::
markerStart += marker.length();
if (markerStart < line.length())
{
if (marker == M3U_GROUP_MARKER && line[markerStart] != '"')
size_t markerEnd;
if (isCheckDelimiters)
{
//For this case we just want to return the full string without splitting it
//This is because groups use semi-colons and not spaces as a delimiter
return line.substr(markerStart, line.length());
}
if (marker == M3U_GROUP_MARKER && line[markerStart] != '"')
{
//For this case we just want to return the full string without splitting it
//This is because groups use semi-colons and not spaces as a delimiter
return line.substr(markerStart, line.length());
}

char find = ' ';
if (line[markerStart] == '"')
{
find = '"';
markerStart++;
char find = ' ';
if (line[markerStart] == '"')
{
find = '"';
markerStart++;
}
markerEnd = line.find(find, markerStart);
if (markerEnd == std::string::npos)
{
markerEnd = line.length();
}
}
size_t markerEnd = line.find(find, markerStart);
if (markerEnd == std::string::npos)
else
{
markerEnd = line.length();
}
Expand Down
2 changes: 1 addition & 1 deletion src/iptvsimple/PlaylistLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace iptvsimple
void ReloadPlayList();

private:
static std::string ReadMarkerValue(const std::string& line, const std::string& markerName);
static std::string ReadMarkerValue(const std::string& line, const std::string& markerName, bool isCheckDelimiters = true);
static void ParseSinglePropertyIntoChannel(const std::string& line, iptvsimple::data::Channel& channel, const std::string& markerName);

std::string ParseIntoChannel(const std::string& line, iptvsimple::data::Channel& channel, data::MediaEntry& mediaEntry, int epgTimeShift, int catchupCorrectionSecs, bool xeevCatchup);
Expand Down
48 changes: 28 additions & 20 deletions src/iptvsimple/utilities/StreamUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,28 @@ 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)
{
// Check if the channel has explicitly set up the use of inputstream.adaptive,
// if so, the best behaviour for media services is:
// - Always add mimetype to prevent kodi core to make an HTTP HEADER requests
// this because in some cases services refuse this request and can also deny downloads
// - If requested by settings, always add the "user-agent" header to ISA properties
const bool isISAdaptiveSet =
channel.GetProperty(PVR_STREAM_PROPERTY_INPUTSTREAM) == INPUTSTREAM_ADAPTIVE;

if (!isISAdaptiveSet && ChannelSpecifiesInputstream(channel))
if (ChannelSpecifiesInputstream(channel))
{
// Channel has an inputstream class set so we only set the stream URL
properties.emplace_back(PVR_STREAM_PROPERTY_STREAMURL, streamURL);
Expand All @@ -48,7 +59,7 @@ void StreamUtils::SetAllStreamProperties(std::vector<kodi::addon::PVRStreamPrope
streamType = StreamUtils::InspectStreamType(streamURL, channel);

// Using kodi's built in inputstreams
if (!isISAdaptiveSet && StreamUtils::UseKodiInputstreams(streamType, settings))
if (StreamUtils::UseKodiInputstreams(streamType, settings))
{
std::string ffmpegStreamURL = StreamUtils::GetURLWithFFmpegReconnectOptions(streamURL, streamType, channel, settings);

Expand Down Expand Up @@ -91,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 All @@ -113,8 +122,7 @@ void StreamUtils::SetAllStreamProperties(std::vector<kodi::addon::PVRStreamPrope
if (!streamUrlSet)
properties.emplace_back(PVR_STREAM_PROPERTY_STREAMURL, streamURL);

if (!isISAdaptiveSet)
properties.emplace_back(PVR_STREAM_PROPERTY_INPUTSTREAM, INPUTSTREAM_ADAPTIVE);
properties.emplace_back(PVR_STREAM_PROPERTY_INPUTSTREAM, INPUTSTREAM_ADAPTIVE);

if (streamType == StreamType::HLS || streamType == StreamType::DASH ||
streamType == StreamType::SMOOTH_STREAMING)
Expand Down