Skip to content

Commit

Permalink
Merge pull request #545 from phunkyfish/fix-episode-num
Browse files Browse the repository at this point in the history
Fix episode num
  • Loading branch information
phunkyfish authored Aug 28, 2021
2 parents c277bf8 + 2253c09 commit 7692a85
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 12 deletions.
10 changes: 8 additions & 2 deletions 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="7.6.9"
version="7.6.10"
name="PVR IPTV Simple Client"
provider-name="nightik and Ross Nicholson">
<requires>@ADDON_DEPENDS@
Expand All @@ -21,6 +21,12 @@
<icon>icon.png</icon>
</assets>
<news>
v7.6.10
- Fixed: Fix episode number when there is no season
- Fixed: Return server error if channels or groups could not be loaded due to missing file so they are not cleared in Kodi
- Translations updates from Weblate
- id_id, ko_kr, pl_pl

v7.6.9
- Translations updates from Weblate
- pl_pl
Expand All @@ -30,7 +36,7 @@ v7.6.8
- zh_cn

v7.6.7
Translations updates from Weblate
- Translations updates from Weblate
- id_id, lt_lt

v7.6.6
Expand Down
6 changes: 6 additions & 0 deletions pvr.iptvsimple/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
v7.6.10
- Fixed: Fix episode number when there is no season
- Fixed: Return server error if channels or groups could not be loaded due to missing file so they are not cleared in Kodi
- Translations updates from Weblate
- id_id, ko_kr, pl_pl

v7.6.9
- Translations updates from Weblate
- pl_pl
Expand Down
7 changes: 6 additions & 1 deletion src/PVRIptvData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,13 @@ ADDON_STATUS PVRIptvData::Create()
Settings::GetInstance().ReadFromAddon(kodi::GetBaseUserPath(), kodi::GetAddonPath());

m_channels.Init();
m_channelGroups.Init();
m_playlistLoader.Init();
m_playlistLoader.LoadPlayList();
if (!m_playlistLoader.LoadPlayList())
{
m_channels.ChannelsLoadFailed();
m_channelGroups.ChannelGroupsLoadFailed();
}
m_epg.Init(EpgMaxPastDays(), EpgMaxFutureDays());

kodi::Log(ADDON_LOG_INFO, "%s Starting separate client update thread...", __FUNCTION__);
Expand Down
10 changes: 10 additions & 0 deletions src/iptvsimple/ChannelGroups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,16 @@ using namespace iptvsimple::utilities;

ChannelGroups::ChannelGroups(const Channels& channels) : m_channels(channels) {}

bool ChannelGroups::Init()
{
Clear();
return true;
}

void ChannelGroups::Clear()
{
m_channelGroups.clear();
m_channelGroupsLoadFailed = false;
}

int ChannelGroups::GetChannelGroupsAmount() const
Expand All @@ -31,6 +38,9 @@ int ChannelGroups::GetChannelGroupsAmount() const

PVR_ERROR ChannelGroups::GetChannelGroups(kodi::addon::PVRChannelGroupsResultSet& results, bool radio) const
{
if (m_channelGroupsLoadFailed)
return PVR_ERROR_SERVER_ERROR;

Logger::Log(LEVEL_DEBUG, "%s - Starting to get ChannelGroups for PVR", __FUNCTION__);

for (const auto& channelGroup : m_channelGroups)
Expand Down
4 changes: 4 additions & 0 deletions src/iptvsimple/ChannelGroups.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@ namespace iptvsimple
iptvsimple::data::ChannelGroup* GetChannelGroup(int uniqueId);
iptvsimple::data::ChannelGroup* FindChannelGroup(const std::string& name);
const std::vector<data::ChannelGroup>& GetChannelGroupsList() const { return m_channelGroups; }
bool Init();
void Clear();
bool CheckChannelGroupAllowed(iptvsimple::data::ChannelGroup& newChannelGroup);
void ChannelGroupsLoadFailed() { m_channelGroupsLoadFailed = true; };

private:
const iptvsimple::Channels& m_channels;
std::vector<iptvsimple::data::ChannelGroup> m_channelGroups;

bool m_channelGroupsLoadFailed = false;
};
} //namespace iptvsimple
4 changes: 4 additions & 0 deletions src/iptvsimple/Channels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ bool Channels::Init()
void Channels::Clear()
{
m_channels.clear();
m_channelsLoadFailed = false;
m_currentChannelNumber = Settings::GetInstance().GetStartChannelNumber();
}

Expand All @@ -41,6 +42,9 @@ int Channels::GetChannelsAmount() const

PVR_ERROR Channels::GetChannels(kodi::addon::PVRChannelsResultSet& results, bool radio) const
{
if (m_channelsLoadFailed)
return PVR_ERROR_SERVER_ERROR;

// We set a channel order here that applies to the 'Any channels' group in kodi-pvr
// This allows the users to use the 'Backend Order' sort option in the left to
// have the same order as the backend (regardles of the channel numbering used)
Expand Down
2 changes: 2 additions & 0 deletions src/iptvsimple/Channels.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ namespace iptvsimple
void Clear();

int GetCurrentChannelNumber() const { return m_currentChannelNumber; }
void ChannelsLoadFailed() { m_channelsLoadFailed = true; };

private:
int GenerateChannelId(const char* channelName, const char* streamUrl);

int m_currentChannelNumber;
bool m_channelsLoadFailed = false;

std::vector<iptvsimple::data::Channel> m_channels;
};
Expand Down
8 changes: 7 additions & 1 deletion src/iptvsimple/PlaylistLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ bool PlaylistLoader::LoadPlayList()
if (m_channels.GetChannelsAmount() == 0)
{
Logger::Log(LEVEL_ERROR, "%s - Unable to load channels from file '%s'", __FUNCTION__, m_m3uLocation.c_str());
return false;
// We no longer return false as this is just an empty M3U and a missing file error.
//return false;
}

Logger::Log(LEVEL_INFO, "%s - Loaded %d channels.", __FUNCTION__, m_channels.GetChannelsAmount());
Expand Down Expand Up @@ -414,6 +415,11 @@ void PlaylistLoader::ReloadPlayList()
m_client->TriggerChannelUpdate();
m_client->TriggerChannelGroupsUpdate();
}
else
{
m_channels.ChannelsLoadFailed();
m_channelGroups.ChannelGroupsLoadFailed();
}
}

std::string PlaylistLoader::ReadMarkerValue(const std::string& line, const std::string& markerName)
Expand Down
33 changes: 25 additions & 8 deletions src/iptvsimple/data/EpgEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ std::string ParseAsW3CDateString(const std::string& strDate)

std::string ParseAsW3CDateString(time_t time)
{
std::tm tm = SafeLocaltime(time);
std::tm tm = SafeLocaltime(time);
char buffer[16];
std::strftime(buffer, 16, "%Y-%m-%d", &tm);

Expand Down Expand Up @@ -336,16 +336,33 @@ bool EpgEntry::ParseOnScreenEpisodeNumberInfo(const std::string& episodeNumberSt
static const std::regex unwantedCharsRegex("[ \\txX_\\.]");
const std::string text = std::regex_replace(episodeNumberString, unwantedCharsRegex, "");

std::smatch match;
static const std::regex seasonEpisodeRegex("^[sS]([0-9][0-9]*)[eE][pP]?([0-9][0-9]*)$");
if (std::regex_match(text, match, seasonEpisodeRegex))
if (StringUtils::StartsWithNoCase(text, "S"))
{
if (match.size() == 3)
std::smatch match;
static const std::regex seasonEpisodeRegex("^[sS]([0-9][0-9]*)[eE][pP]?([0-9][0-9]*)$");
if (std::regex_match(text, match, seasonEpisodeRegex))
{
m_seasonNumber = std::atoi(match[1].str().c_str());
m_episodeNumber = std::atoi(match[2].str().c_str());
if (match.size() == 3)
{
m_seasonNumber = std::atoi(match[1].str().c_str());
m_episodeNumber = std::atoi(match[2].str().c_str());

return true;
return true;
}
}
}
else if (StringUtils::StartsWithNoCase(text, "E"))
{
static const std::regex episodeOnlyRegex("^[eE][pP]?([0-9][0-9]*)$");
std::smatch matchEpOnly;
if (std::regex_match(text, matchEpOnly, episodeOnlyRegex))
{
if (matchEpOnly.size() == 2)
{
m_episodeNumber = std::atoi(matchEpOnly[1].str().c_str());

return true;
}
}
}

Expand Down

0 comments on commit 7692a85

Please sign in to comment.