diff --git a/src/parser/HLSTree.cpp b/src/parser/HLSTree.cpp index a6d1facc1..b8ab73b68 100644 --- a/src/parser/HLSTree.cpp +++ b/src/parser/HLSTree.cpp @@ -16,6 +16,7 @@ #include "../utils/log.h" #include "kodi/tools/StringUtils.h" +#include #include #include @@ -974,6 +975,19 @@ bool adaptive::CHLSTree::ParseMultivariantPlaylist(const std::string& data) rend.m_isForced = attribs["FORCED"] == "YES"; rend.m_characteristics = attribs["CHARACTERISTICS"]; rend.m_uri = attribs["URI"]; + 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; })) + { + rend.m_isUriDuplicate = true; + } + } if (streamType == StreamType::AUDIO) pl.m_audioRenditions.emplace_back(rend); @@ -1017,6 +1031,13 @@ bool adaptive::CHLSTree::ParseMultivariantPlaylist(const std::string& data) var.m_groupIdSubtitles = attribs["SUBTITLES"]; var.m_uri = uri; + // 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; })) + { + var.m_isUriDuplicate = true; + } + pl.m_variants.emplace_back(var); } else if (tagName == "#EXT-X-SESSION-KEY") @@ -1050,6 +1071,9 @@ bool adaptive::CHLSTree::ParseMultivariantPlaylist(const std::string& data) // Add audio renditions (do not take in account variants references) for (const Rendition& r : pl.m_audioRenditions) { + if (r.m_isUriDuplicate) + continue; + auto newAdpSet = CAdaptationSet::MakeUniquePtr(period.get()); auto newRepr = CRepresentation::MakeUniquePtr(newAdpSet.get()); @@ -1096,6 +1120,9 @@ bool adaptive::CHLSTree::ParseMultivariantPlaylist(const std::string& data) // Add subtitles renditions (do not take in account variants references) for (const Rendition& r : pl.m_subtitleRenditions) { + if (r.m_isUriDuplicate) + continue; + auto newAdpSet = CAdaptationSet::MakeUniquePtr(period.get()); auto newRepr = CRepresentation::MakeUniquePtr(newAdpSet.get()); @@ -1112,6 +1139,9 @@ bool adaptive::CHLSTree::ParseMultivariantPlaylist(const std::string& data) // Add variants for (const Variant& var : pl.m_variants) { + if (var.m_isUriDuplicate) + continue; + if (var.m_bandwidth == 0) LOG::LogF(LOGWARNING, "Variant with malformed bandwidth attribute"); diff --git a/src/parser/HLSTree.h b/src/parser/HLSTree.h index 121c72c52..f686397aa 100644 --- a/src/parser/HLSTree.h +++ b/src/parser/HLSTree.h @@ -79,6 +79,8 @@ class ATTR_DLL_LOCAL CHLSTree : public AdaptiveTree std::string m_characteristics; std::string m_uri; int m_features{REND_FEATURE_NONE}; + // Means that another rendition have same uri + bool m_isUriDuplicate{false}; }; // \brief Usually refer to an EXT-X-STREAM-INF tag @@ -91,6 +93,8 @@ class ATTR_DLL_LOCAL CHLSTree : public AdaptiveTree std::string m_groupIdAudio; std::string m_groupIdSubtitles; std::string m_uri; + // Means that another variant have same uri + bool m_isUriDuplicate{false}; }; struct MultivariantPlaylist