Skip to content

Commit

Permalink
Improve web stream URL extraction handling
Browse files Browse the repository at this point in the history
  • Loading branch information
alpgul committed Feb 10, 2025
1 parent a0627e9 commit 40d3de1
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions src/iptvsimple/utilities/StreamUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,19 +504,24 @@ std::string StreamUtils::WebStreamExtractor(const std::string& webUrl,
{
std::string webPattern = currentChannel.GetProperty("web-regex");
std::string webHeaders = currentChannel.GetProperty("web-headers");
std::string extractedUrl =
WebStreamExtractor::ExtractStreamUrl(webUrl, webPattern, webHeaders, false);
Logger::Log(
LEVEL_DEBUG, "%s - Extracted URL: '%s', webPattern: '%s', webHeaders: '%s', webUrl: '%s'",
__FUNCTION__, extractedUrl.c_str(), webPattern.c_str(), webHeaders.c_str(), webUrl.c_str());
std::string mediaHeaders;
std::string tempUrl = webUrl;
size_t pos = tempUrl.find('|');

if (!extractedUrl.empty())
if (pos != std::string::npos)
{
size_t pos = webUrl.find('|');
if (pos != std::string::npos)
{
extractedUrl += webUrl.substr(pos);
}
mediaHeaders = tempUrl.substr(pos);
tempUrl = tempUrl.substr(0, pos);
}
std::string extractedUrl =
WebStreamExtractor::ExtractStreamUrl(tempUrl, webPattern, webHeaders, false);
Logger::Log(LEVEL_DEBUG,
"%s - Extracted URL: '%s', webPattern: '%s', webHeaders: '%s', webUrl: '%s'",
__FUNCTION__, extractedUrl.c_str(), webPattern.c_str(), webHeaders.c_str(),
tempUrl.c_str());
if (!extractedUrl.empty() && !mediaHeaders.empty())
{
extractedUrl += mediaHeaders;
}
return extractedUrl;
}
Expand All @@ -531,19 +536,23 @@ std::string StreamUtils::WebStreamExtractor(const std::string& webUrl,
{
std::string webPattern = currentMediaEntry.GetProperty("web-regex");
std::string webHeaders = currentMediaEntry.GetProperty("web-headers");
std::string mediaHeaders;
std::string tempUrl = webUrl;
size_t pos = tempUrl.find('|');

if (pos != std::string::npos)
{
mediaHeaders = tempUrl.substr(pos);
tempUrl = tempUrl.substr(0, pos);
}
std::string extractedUrl =
WebStreamExtractor::ExtractStreamUrl(webUrl, webPattern, webHeaders, true);
Logger::Log(
LEVEL_DEBUG, "%s - Extracted URL: '%s', webPattern: '%s', webHeaders: '%s', webUrl: '%s'",
__FUNCTION__, extractedUrl.c_str(), webPattern.c_str(), webHeaders.c_str(), webUrl.c_str());

if (!extractedUrl.empty())
if (!extractedUrl.empty() && !mediaHeaders.empty())
{
size_t pos = webUrl.find('|');
if (pos != std::string::npos)
{
extractedUrl += webUrl.substr(pos);
}
extractedUrl += mediaHeaders;
}
return extractedUrl;
}
Expand Down

0 comments on commit 40d3de1

Please sign in to comment.