Skip to content

Commit

Permalink
Merge pull request #626 from phunkyfish/tvg-logo-urlencode-matrix
Browse files Browse the repository at this point in the history
Tvg logo unencoded matrix
  • Loading branch information
phunkyfish authored Aug 7, 2022
2 parents 7644bad + 054861c commit 6447c58
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 3 deletions.
5 changes: 4 additions & 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="19.1.1"
version="19.2.0"
name="PVR IPTV Simple Client"
provider-name="nightik and Ross Nicholson">
<requires>@ADDON_DEPENDS@
Expand All @@ -21,6 +21,9 @@
<icon>icon.png</icon>
</assets>
<news>
v19.2.0
- URL encode last part of tvg logo URL as they can be based on channel names

v19.1.1
- Fix ch-number tag being ignored

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 @@
v19.2.0
- URL encode last part of tvg logo URL as they can be based on channel names

v19.1.1
- Fix ch-number tag being ignored

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 @@ -126,10 +126,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 6447c58

Please sign in to comment.