Skip to content

Commit

Permalink
Merge pull request #627 from phunkyfish/tvg-logo-unencoded
Browse files Browse the repository at this point in the history
Tvg logo unencoded
  • Loading branch information
phunkyfish authored Aug 7, 2022
2 parents b51fc74 + c80a611 commit 2b62cf2
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 3 deletions.
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="20.4.0"
version="20.5.0"
name="IPTV Simple Client"
provider-name="nightik and Ross Nicholson">
<requires>@ADDON_DEPENDS@
Expand Down
3 changes: 3 additions & 0 deletions pvr.iptvsimple/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
v20.5.0
- URL encode last part of tvg logo URL as they can be based on channel names and they can contain spaces and non standard characters not allowed in paths

v20.4.0
- Support ${duration} format specifier
- Fix azure image to use Windows 2019 and VS 2019
Expand Down
23 changes: 21 additions & 2 deletions src/iptvsimple/data/Channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,29 @@ void Channel::SetIconPathFromTvgLogo(const std::string& tvgLogo, std::string& ch

kodi::UnknownToUTF8(m_iconPath, m_iconPath);

// urlencode channel logo when set from channel name and source is Remote Path
// append extension as channel name wouldn't have it
// urlencode channel logo when set from channel name and source is Remote Path, append extension as channel wouldn't cover this
if (logoSetFromChannelName && Settings::GetInstance().GetLogoPathType() == PathType::REMOTE_PATH)
{
m_iconPath = utilities::WebUtils::UrlEncode(m_iconPath);
}
else if (m_iconPath.find("://") != std::string::npos)
{
// we also want to check the last part of a URL to ensure it's valid as quite often they are based on channel names
// the path should be fine

size_t pos = m_iconPath.find_last_of("/");
if (pos != std::string::npos)
{
const std::string urlPath = m_iconPath.substr(0, pos + 1);
std::string urlFile = m_iconPath.substr(pos + 1);
if (!utilities::WebUtils::IsEncoded(urlFile))
{
urlFile = utilities::WebUtils::UrlEncode(urlFile);

m_iconPath = urlPath + urlFile;
}
}
}

if (m_iconPath.find("://") == std::string::npos)
{
Expand Down
47 changes: 47 additions & 0 deletions src/iptvsimple/utilities/WebUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,53 @@ const std::string WebUtils::UrlEncode(const std::string& value)
return escaped.str();
}

namespace
{

char from_hex(char ch) {
return isdigit(ch) ? ch - '0' : tolower(ch) - 'a' + 10;
}

} // unamed namespace

const std::string WebUtils::UrlDecode(const std::string& value)
{
char h;
std::ostringstream escaped;
escaped.fill('0');

for (auto i = value.begin(), n = value.end(); i != n; ++i)
{
std::string::value_type c = (*i);

if (c == '%')
{
if (i[1] && i[2])
{
h = from_hex(i[1]) << 4 | from_hex(i[2]);
escaped << h;
i += 2;
}
}
else if (c == '+')
{
escaped << ' ';
}
else
{
escaped << c;
}
}

return escaped.str();
}

bool WebUtils::IsEncoded(const std::string& value)
{
// Note this is not perfect as '+' symbols will mess this up, they should in general be avoided in preference of '%20'
return UrlDecode(value) != value;
}

std::string WebUtils::ReadFileContentsStartOnly(const std::string& url, int* httpCode)
{
std::string strContent;
Expand Down
2 changes: 2 additions & 0 deletions src/iptvsimple/utilities/WebUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace iptvsimple
{
public:
static const std::string UrlEncode(const std::string& value);
static const std::string UrlDecode(const std::string& value);
static bool IsEncoded(const std::string& value);
static std::string ReadFileContentsStartOnly(const std::string& url, int* httpCode);
static bool IsHttpUrl(const std::string& url);
static std::string RedactUrl(const std::string& url);
Expand Down

0 comments on commit 2b62cf2

Please sign in to comment.