Skip to content

Commit

Permalink
Series and episode clean up
Browse files Browse the repository at this point in the history
Remove duplicated series information from recordings, timer and EPG.  Parse episode display information from the description.
  • Loading branch information
emveepee committed Jul 7, 2024
1 parent ab047a0 commit 4959873
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 15 deletions.
2 changes: 2 additions & 0 deletions pvr.nextpvr/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
v21.1.1
- Start timeshift in realtime for radio playback
- Add support for episode and episode part parsing
- Clean up duplicated S/E information sent from NextPVR in the subtitle when no subtitle is present.

v21.1.0
- Allow control of recording and timers access
Expand Down
27 changes: 26 additions & 1 deletion src/EPG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ PVR_ERROR EPG::GetEPGForChannel(int channelUid, time_t start, time_t end, kodi::
const std::string oidLookup(endTime + ":" + std::to_string(channelUid));

broadcast.SetTitle(title);
broadcast.SetEpisodeName(subtitle);
broadcast.SetUniqueChannelId(channelUid);
broadcast.SetStartTime(stol(startTime));
broadcast.SetUniqueBroadcastId(stoi(endTime));
Expand Down Expand Up @@ -132,9 +131,35 @@ PVR_ERROR EPG::GetEPGForChannel(int channelUid, time_t start, time_t end, kodi::
}

}

broadcast.SetSeriesNumber(XMLUtils::GetIntValue(pListingNode, "season", EPG_TAG_INVALID_SERIES_EPISODE));
broadcast.SetEpisodeNumber(XMLUtils::GetIntValue(pListingNode, "episode", EPG_TAG_INVALID_SERIES_EPISODE));
broadcast.SetEpisodePartNumber(EPG_TAG_INVALID_SERIES_EPISODE);
if (broadcast.GetEpisodeNumber() == EPG_TAG_INVALID_SERIES_EPISODE)
{
std::regex base_regex("^.*\\([eE][pP](\\d+)(?:/?(\\d+))?\\)");
std::smatch base_match;
if (std::regex_search(description, base_match, base_regex))
{
broadcast.SetEpisodeNumber(std::atoi(base_match[1].str().c_str()));
if (base_match[2].matched)
broadcast.SetEpisodePartNumber(std::atoi(base_match[2].str().c_str()));
}
else if (std::regex_search(description, base_match, std::regex("(^\\d+)/(\\d+)\.")))
{
broadcast.SetEpisodeNumber(std::atoi(base_match[1].str().c_str()));
broadcast.SetEpisodePartNumber(std::atoi(base_match[2].str().c_str()));
}
}
else if (broadcast.GetSeriesNumber() != EPG_TAG_INVALID_SERIES_EPISODE)
{
// clear out NextPVR formatted data, Kodi supports S/E format
if (subtitle == kodi::tools::StringUtils::Format("S%02dE%02d", broadcast.GetSeriesNumber(), broadcast.GetEpisodeNumber()))
{
subtitle.clear();
}
}
broadcast.SetEpisodeName(subtitle);

std::string original;
XMLUtils::GetString(pListingNode, "original", original);
Expand Down
39 changes: 25 additions & 14 deletions src/Recordings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,20 +323,17 @@ bool Recordings::UpdatePvrRecording(const tinyxml2::XMLNode* pRecordingNode, kod

tag.SetSeriesNumber(PVR_RECORDING_INVALID_SERIES_EPISODE);
tag.SetEpisodeNumber(PVR_RECORDING_INVALID_SERIES_EPISODE);

if (XMLUtils::GetString(pRecordingNode, "subtitle", buffer))
if (ParseNextPVRSubtitle(pRecordingNode, tag))
{
if (ParseNextPVRSubtitle(pRecordingNode, tag))
if (m_settings->m_separateSeasons && multipleSeasons && tag.GetSeriesNumber() != PVR_RECORDING_INVALID_SERIES_EPISODE)
{
if (m_settings->m_separateSeasons && multipleSeasons && tag.GetSeriesNumber() != PVR_RECORDING_INVALID_SERIES_EPISODE)
{
if (status != "Failed")
tag.SetDirectory(kodi::tools::StringUtils::Format("/%s/%s %d", tag.GetTitle().c_str(), kodi::addon::GetLocalizedString(20373).c_str(), tag.GetSeriesNumber()));
else
tag.SetDirectory(kodi::tools::StringUtils::Format("/%s/%s/%s %d", kodi::addon::GetLocalizedString(30166).c_str(),tag.GetTitle().c_str(), kodi::addon::GetLocalizedString(20373).c_str(), tag.GetSeriesNumber()));
}
if (status != "Failed")
tag.SetDirectory(kodi::tools::StringUtils::Format("/%s/%s %d", tag.GetTitle().c_str(), kodi::addon::GetLocalizedString(20373).c_str(), tag.GetSeriesNumber()));
else
tag.SetDirectory(kodi::tools::StringUtils::Format("/%s/%s/%s %d", kodi::addon::GetLocalizedString(30166).c_str(),tag.GetTitle().c_str(), kodi::addon::GetLocalizedString(20373).c_str(), tag.GetSeriesNumber()));
}
}

tag.SetYear(XMLUtils::GetIntValue(pRecordingNode, "year"));

std::string original;
Expand Down Expand Up @@ -473,19 +470,18 @@ bool Recordings::ParseNextPVRSubtitle(const tinyxml2::XMLNode *pRecordingNode, k
bool hasSeasonEpisode = false;
if (XMLUtils::GetString(pRecordingNode, "subtitle", buffer))
{
std::regex base_regex("S(\\d{2,4})E(\\d+) - ?(.+)?");
std::regex base_regex("S(\\d{2,4})E(\\d+)(?: - ?(.+)$)?");
std::smatch base_match;
// note NextPVR does not support S0 for specials
if (std::regex_match(buffer, base_match, base_regex))
if (std::regex_search(buffer, base_match, base_regex))
{
if (base_match.size() == 3 || base_match.size() == 4)
{

std::ssub_match base_sub_match = base_match[1];
tag.SetSeriesNumber(std::stoi(base_sub_match.str()));
base_sub_match = base_match[2];
tag.SetEpisodeNumber(std::stoi(base_sub_match.str()));
if (base_match.size() == 4)
if (base_match[3].matched)
{
base_sub_match = base_match[3];
tag.SetEpisodeName(base_sub_match.str());
Expand Down Expand Up @@ -518,6 +514,21 @@ bool Recordings::ParseNextPVRSubtitle(const tinyxml2::XMLNode *pRecordingNode, k
}
}
}
const std::string plot = tag.GetPlot();
if (tag.GetEpisodeNumber() == PVR_RECORDING_INVALID_SERIES_EPISODE && !plot.empty());
{
// Kodi doesn't support episode parts on recordings
std::regex base_regex("^.*\\([eE][pP](\\d+)(?:/?(\\d+))?\\)");
std::smatch base_match;
if (std::regex_search(plot, base_match, base_regex))
{
tag.SetEpisodeNumber(std::atoi(base_match[1].str().c_str()));
}
else if (std::regex_search(plot, base_match, std::regex("^(\\d+)/(\\d+)\\.")))
{
tag.SetEpisodeNumber(std::atoi(base_match[1].str().c_str()));
}
}
}
return hasSeasonEpisode;
}
Expand Down

0 comments on commit 4959873

Please sign in to comment.