Skip to content

Commit

Permalink
M3U format specifier to override realtime processing in Kodi PVR wher…
Browse files Browse the repository at this point in the history
…e the stream should not be treated like VOD/Media in the UI
  • Loading branch information
phunkyfish committed Jul 25, 2023
1 parent 4b68d9c commit db27506
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ http://path-to-stream/live/channel-z.ts
- `media`: Specifies that this entry is a media entry by setting the values true `true`. Same as setting `#EXT-X-PLAYLIST-TYPE` to VOD.
- `media-dir`: An optional directory path which should specifiy where in the hierarchy this media entry should be represented. The path separator is `/`.
- `media-size`: An optional size of the media entry in bytes. Note: this is not usually available for VOD libraries.
- `realtime`: Live streams in PVR disable features such as passthrough by default. Set this item to "false" to bypass this behaviour if the stream should not be treated like VOD/Media in the UI.
- `#EXTGRP`: A semi-colon separted list of channel groups that this channel belongs to.
- `#KODIPROP`: A single property in the format `key=value` that can be passed to Kodi. Multiple can be passed each on a separate line.
- `#EXTVLCOPT`: A single property in the format `key=value` that can be passed to Kodi. Multiple can be passed each on a separate line. Note that if either a `http-user-agent` or a `http-referrer` property is found it will added to the URL as a HTTP header as `user-agent` or `referrer` respectively if not already provided in the URL. These two fields specifically will be dropped as properties whether or not they are added as header values. They will be added in the same format as the `URL` below.
Expand Down
39 changes: 36 additions & 3 deletions src/iptvsimple/PlaylistLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,33 @@ bool PlaylistLoader::Init()
return true;
}

namespace {

bool GetOverrideRealTime(std::string& line)
{
size_t realtimeIndex = line.find(REALTIME_OVERRIDE);
if (realtimeIndex != std::string::npos)
{
size_t startValueIndex = realtimeIndex + REALTIME_OVERRIDE.length();
size_t endQuoteIndex = line.find('"', startValueIndex);
if (endQuoteIndex != std::string::npos)
{
size_t valueLength = endQuoteIndex - startValueIndex;
std::string value = line.substr(startValueIndex, valueLength);
StringUtils::ToLower(value);
// The only value that matters is if the 'realtime' specifier is 'false'
// that means we want to override the realtime value but not treat the stream
// like media/VOD in the UI
// It's a bit confusing, but hey, that's Kodi for you ;)
return value == "false";
}
}

return false;
}

}

bool PlaylistLoader::LoadPlayList()
{
auto started = std::chrono::high_resolution_clock::now();
Expand All @@ -64,6 +91,7 @@ bool PlaylistLoader::LoadPlayList()
/* load channels */
bool isFirstLine = true;
bool isRealTime = true;
bool overrideRealTime = false;
bool isMediaEntry = false;
int epgTimeShift = 0;
int catchupCorrectionSecs = m_settings->GetCatchupCorrectionSecs();
Expand Down Expand Up @@ -149,6 +177,8 @@ bool PlaylistLoader::LoadPlayList()
line.find(MEDIA_SIZE) != std::string::npos ||
m_settings->MediaForcePlaylist();

overrideRealTime = GetOverrideRealTime(line);

const std::string groupNamesListString = ParseIntoChannel(line, tmpChannel, tmpMediaEntry, currentChannelGroupIdList, epgTimeShift, catchupCorrectionSecs, xeevCatchup);

if (!groupNamesListString.empty())
Expand Down Expand Up @@ -187,9 +217,12 @@ bool PlaylistLoader::LoadPlayList()
{
Logger::Log(LEVEL_DEBUG, "%s - Adding channel '%s' with URL: '%s'", __FUNCTION__, tmpChannel.GetChannelName().c_str(), line.c_str());

if ((isRealTime || !m_settings->IsMediaEnabled() || !m_settings->ShowVodAsRecordings()) && !isMediaEntry)
if ((isRealTime || overrideRealTime || !m_settings->IsMediaEnabled() || !m_settings->ShowVodAsRecordings()) && !isMediaEntry)
{
tmpChannel.AddProperty(PVR_STREAM_PROPERTY_ISREALTIMESTREAM, "true");
// There are cases where we want the stream to be represetned as a channel with live streaming disabled
// to allow features such as passthrough to work. We don't want this to be VOD as then it would be treated like media.
if (!overrideRealTime)
tmpChannel.AddProperty(PVR_STREAM_PROPERTY_ISREALTIMESTREAM, "true");

Channel channel = tmpChannel;
channel.SetStreamURL(line);
Expand All @@ -206,12 +239,12 @@ bool PlaylistLoader::LoadPlayList()

if (!m_media.AddMediaEntry(entry, currentChannelGroupIdList, m_channelGroups, channelHadGroups))
Logger::Log(LEVEL_DEBUG, "%s - Counld not add media entry as an entry with the same gnenerated unique ID already exists", __func__);

}

tmpChannel.Reset();
tmpMediaEntry.Reset();
isRealTime = true;
overrideRealTime = false;
isMediaEntry = false;
channelHadGroups = false;
}
Expand Down
1 change: 1 addition & 0 deletions src/iptvsimple/PlaylistLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace iptvsimple
static const std::string MEDIA = "media=";
static const std::string MEDIA_DIR = "media-dir=";
static const std::string MEDIA_SIZE = "media-size=";
static const std::string REALTIME_OVERRIDE = "realtime=\"";
static const std::string KODIPROP_MARKER = "#KODIPROP:";
static const std::string EXTVLCOPT_MARKER = "#EXTVLCOPT:";
static const std::string EXTVLCOPT_DASH_MARKER = "#EXTVLCOPT--";
Expand Down

0 comments on commit db27506

Please sign in to comment.