Skip to content

Commit 2b62cf2

Browse files
authored
Merge pull request #627 from phunkyfish/tvg-logo-unencoded
Tvg logo unencoded
2 parents b51fc74 + c80a611 commit 2b62cf2

File tree

5 files changed

+74
-3
lines changed

5 files changed

+74
-3
lines changed

pvr.iptvsimple/addon.xml.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<addon
33
id="pvr.iptvsimple"
4-
version="20.4.0"
4+
version="20.5.0"
55
name="IPTV Simple Client"
66
provider-name="nightik and Ross Nicholson">
77
<requires>@ADDON_DEPENDS@

pvr.iptvsimple/changelog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
v20.5.0
2+
- 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
3+
14
v20.4.0
25
- Support ${duration} format specifier
36
- Fix azure image to use Windows 2019 and VS 2019

src/iptvsimple/data/Channel.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,29 @@ void Channel::SetIconPathFromTvgLogo(const std::string& tvgLogo, std::string& ch
129129

130130
kodi::UnknownToUTF8(m_iconPath, m_iconPath);
131131

132-
// urlencode channel logo when set from channel name and source is Remote Path
133-
// append extension as channel name wouldn't have it
132+
// urlencode channel logo when set from channel name and source is Remote Path, append extension as channel wouldn't cover this
134133
if (logoSetFromChannelName && Settings::GetInstance().GetLogoPathType() == PathType::REMOTE_PATH)
134+
{
135135
m_iconPath = utilities::WebUtils::UrlEncode(m_iconPath);
136+
}
137+
else if (m_iconPath.find("://") != std::string::npos)
138+
{
139+
// 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
140+
// the path should be fine
141+
142+
size_t pos = m_iconPath.find_last_of("/");
143+
if (pos != std::string::npos)
144+
{
145+
const std::string urlPath = m_iconPath.substr(0, pos + 1);
146+
std::string urlFile = m_iconPath.substr(pos + 1);
147+
if (!utilities::WebUtils::IsEncoded(urlFile))
148+
{
149+
urlFile = utilities::WebUtils::UrlEncode(urlFile);
150+
151+
m_iconPath = urlPath + urlFile;
152+
}
153+
}
154+
}
136155

137156
if (m_iconPath.find("://") == std::string::npos)
138157
{

src/iptvsimple/utilities/WebUtils.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,53 @@ const std::string WebUtils::UrlEncode(const std::string& value)
4242
return escaped.str();
4343
}
4444

45+
namespace
46+
{
47+
48+
char from_hex(char ch) {
49+
return isdigit(ch) ? ch - '0' : tolower(ch) - 'a' + 10;
50+
}
51+
52+
} // unamed namespace
53+
54+
const std::string WebUtils::UrlDecode(const std::string& value)
55+
{
56+
char h;
57+
std::ostringstream escaped;
58+
escaped.fill('0');
59+
60+
for (auto i = value.begin(), n = value.end(); i != n; ++i)
61+
{
62+
std::string::value_type c = (*i);
63+
64+
if (c == '%')
65+
{
66+
if (i[1] && i[2])
67+
{
68+
h = from_hex(i[1]) << 4 | from_hex(i[2]);
69+
escaped << h;
70+
i += 2;
71+
}
72+
}
73+
else if (c == '+')
74+
{
75+
escaped << ' ';
76+
}
77+
else
78+
{
79+
escaped << c;
80+
}
81+
}
82+
83+
return escaped.str();
84+
}
85+
86+
bool WebUtils::IsEncoded(const std::string& value)
87+
{
88+
// Note this is not perfect as '+' symbols will mess this up, they should in general be avoided in preference of '%20'
89+
return UrlDecode(value) != value;
90+
}
91+
4592
std::string WebUtils::ReadFileContentsStartOnly(const std::string& url, int* httpCode)
4693
{
4794
std::string strContent;

src/iptvsimple/utilities/WebUtils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ namespace iptvsimple
2222
{
2323
public:
2424
static const std::string UrlEncode(const std::string& value);
25+
static const std::string UrlDecode(const std::string& value);
26+
static bool IsEncoded(const std::string& value);
2527
static std::string ReadFileContentsStartOnly(const std::string& url, int* httpCode);
2628
static bool IsHttpUrl(const std::string& url);
2729
static std::string RedactUrl(const std::string& url);

0 commit comments

Comments
 (0)