Skip to content

Commit

Permalink
[HLSTree] Check for already add uri variant/rendition
Browse files Browse the repository at this point in the history
  • Loading branch information
CastagnaIT committed Aug 26, 2023
1 parent 99402f7 commit 03c58f1
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/parser/HLSTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "../utils/log.h"
#include "kodi/tools/StringUtils.h"

#include <algorithm>
#include <optional>
#include <sstream>

Expand Down Expand Up @@ -959,6 +960,20 @@ bool adaptive::CHLSTree::ParseMultivariantPlaylist(const std::string& data)
else
continue; // Skip, other types are not supported

std::string uri = attribs["URI"];

if (!uri.empty())
{
// Check if this uri has been already added
if (std::any_of(pl.m_audioRenditions.cbegin(), pl.m_audioRenditions.cend(),
[&uri](const Rendition& v) { return v.m_uri == uri; }) ||
std::any_of(pl.m_subtitleRenditions.cbegin(), pl.m_subtitleRenditions.cend(),
[&uri](const Rendition& v) { return v.m_uri == uri; }))
{
continue;
}
}

Rendition rend;
rend.m_type = attribs["TYPE"];
rend.m_groupId = attribs["GROUP-ID"];
Expand All @@ -973,7 +988,7 @@ bool adaptive::CHLSTree::ParseMultivariantPlaylist(const std::string& data)
rend.m_isDefault = attribs["DEFAULT"] == "YES";
rend.m_isForced = attribs["FORCED"] == "YES";
rend.m_characteristics = attribs["CHARACTERISTICS"];
rend.m_uri = attribs["URI"];
rend.m_uri = uri;

if (streamType == StreamType::AUDIO)
pl.m_audioRenditions.emplace_back(rend);
Expand Down Expand Up @@ -1003,6 +1018,13 @@ bool adaptive::CHLSTree::ParseMultivariantPlaylist(const std::string& data)
continue;
}

// Check if this uri has been already added
if (std::any_of(pl.m_variants.cbegin(), pl.m_variants.cend(),
[&uri](const Variant& v) { return v.m_uri == uri; }))
{
continue;
}

Variant var;
var.m_bandwidth = STRING::ToUint32(attribs["BANDWIDTH"]);
var.m_codecs = attribs["CODECS"];
Expand Down

0 comments on commit 03c58f1

Please sign in to comment.