From 507840f395c4ff7a40c273dee6ba4a2fedb85e36 Mon Sep 17 00:00:00 2001 From: phunkyfish Date: Fri, 27 Oct 2023 00:00:35 +0100 Subject: [PATCH 1/3] Extract season from medis title for path if not available --- src/iptvsimple/Media.cpp | 4 +-- src/iptvsimple/data/MediaEntry.cpp | 40 +++++++++++++++++++++++++++--- src/iptvsimple/data/MediaEntry.h | 22 ++++++++++++++++ 3 files changed, 60 insertions(+), 6 deletions(-) diff --git a/src/iptvsimple/Media.cpp b/src/iptvsimple/Media.cpp index f734cc18..43070696 100644 --- a/src/iptvsimple/Media.cpp +++ b/src/iptvsimple/Media.cpp @@ -116,12 +116,12 @@ MediaEntry Media::GetMediaEntry(const std::string& mediaEntryId) const bool Media::IsInVirtualMediaEntryFolder(const MediaEntry& mediaEntryToCheck) const { - const std::string& mediaEntryFolderToCheck = mediaEntryToCheck.GetTitle(); + const std::string& mediaEntryFolderToCheck = mediaEntryToCheck.GetFolderTitle(); int iMatches = 0; for (const auto& mediaEntry : m_media) { - if (mediaEntryFolderToCheck == mediaEntry.GetTitle()) + if (mediaEntryFolderToCheck == mediaEntry.GetFolderTitle()) { iMatches++; Logger::Log(LEVEL_DEBUG, "%s Found MediaEntry title '%s' in media vector!", __func__, mediaEntryFolderToCheck.c_str()); diff --git a/src/iptvsimple/data/MediaEntry.cpp b/src/iptvsimple/data/MediaEntry.cpp index 75134b91..71d975f2 100644 --- a/src/iptvsimple/data/MediaEntry.cpp +++ b/src/iptvsimple/data/MediaEntry.cpp @@ -59,6 +59,23 @@ void MediaEntry::Reset() m_tvgShift = 0; } +namespace { + +std::string ExtractFolderTitle(const std::string& title) +{ + std::regex pattern("[sS]\\.?[0-9]+ ?[eE][pP]?\\.?[0-9]+/?[0-9]* *"); + std::stringstream result; + std::regex_replace(std::ostream_iterator(result), title.begin(), title.end(), pattern, ""); + const std::string folderTitle = result.str(); + + if (title != folderTitle) + return folderTitle; + + return title; +} + +} + void MediaEntry::UpdateFrom(iptvsimple::data::Channel channel) { m_radio = channel.IsRadio(); @@ -74,6 +91,8 @@ void MediaEntry::UpdateFrom(iptvsimple::data::Channel channel) m_providerUniqueId = channel.GetProviderUniqueId(); m_properties = channel.GetProperties(); m_inputStreamName = channel.GetInputStreamName(); + + m_folderTitle = ExtractFolderTitle(m_title); } void MediaEntry::UpdateFrom(iptvsimple::data::EpgEntry epgEntry, const std::vector& genreMappings) @@ -119,6 +138,8 @@ void MediaEntry::UpdateFrom(iptvsimple::data::EpgEntry epgEntry, const std::vect m_new = epgEntry.IsNew(); m_premiere = epgEntry.IsPremiere(); + + m_folderTitle = ExtractFolderTitle(m_title); } bool MediaEntry::SetEpgGenre(const std::vector genreMappings) @@ -270,10 +291,21 @@ void MediaEntry::UpdateTo(kodi::addon::PVRRecording& left, bool isInVirtualMedia std::string newDirectory = FixPath(m_directory); if (m_settings->GroupMediaByTitle() && isInVirtualMediaEntryFolder) { - if (m_settings->GroupMediaBySeason() && m_seasonNumber != EPG_TAG_INVALID_SERIES_EPISODE) - newDirectory = StringUtils::Format("%s%s/%s/", newDirectory.c_str(), m_title.c_str(), GetSeasonPrefix(m_seasonNumber).c_str()); - else - newDirectory = StringUtils::Format("%s%s/", newDirectory.c_str(), m_title.c_str()); + if (m_settings->GroupMediaBySeason()) + { + if (m_seasonNumber != EPG_TAG_INVALID_SERIES_EPISODE) + { + newDirectory = StringUtils::Format("%s%s/%s/", newDirectory.c_str(), m_title.c_str(), GetSeasonPrefix(m_seasonNumber).c_str()); + } + else + { + static std::regex pattern("^.*([sS]\\.?[0-9]+) ?[^]*$"); + std::string seasonText = GetMatchTextFromString(m_title, pattern); + + if (!seasonText.empty()) + newDirectory = StringUtils::Format("%s%s/%s/", newDirectory.c_str(), m_folderTitle.c_str(), seasonText.c_str()); + } + } } left.SetDirectory(newDirectory); diff --git a/src/iptvsimple/data/MediaEntry.h b/src/iptvsimple/data/MediaEntry.h index f1c13eb5..30b4def1 100644 --- a/src/iptvsimple/data/MediaEntry.h +++ b/src/iptvsimple/data/MediaEntry.h @@ -12,6 +12,7 @@ #include "Channel.h" #include "EpgEntry.h" +#include #include #include @@ -67,6 +68,9 @@ namespace iptvsimple int64_t GetSizeInBytes() const { return m_sizeInBytes; } void SetSizeInBytes(int64_t value) { m_sizeInBytes = value; } + const std::string& GetFolderTitle() const { return m_folderTitle; } + void SetFolderTitle(const std::string& value); + const std::string& GetM3UName() const { return m_m3uName; } const std::string& GetTvgId() const { return m_tvgId; } const std::string& GetTvgName() const { return m_tvgName; } @@ -89,6 +93,23 @@ namespace iptvsimple void UpdateFrom(iptvsimple::data::EpgEntry epgEntry, const std::vector& genres); void UpdateTo(kodi::addon::PVRRecording& left, bool isInVirtualMediaEntryFolder, bool haveMediaTypes); + std::string GetMatchTextFromString(const std::string& text, const std::regex& pattern) + { + std::string matchText = ""; + std::smatch match; + + if (std::regex_match(text, match, pattern)) + { + if (match.size() == 2) + { + std::ssub_match base_sub_match = match[1]; + matchText = base_sub_match.str(); + } + } + + return matchText; + }; + private: bool SetEpgGenre(std::vector genreMappings); @@ -105,6 +126,7 @@ namespace iptvsimple int m_providerUniqueId = PVR_PROVIDER_INVALID_UID; std::string m_directory; int64_t m_sizeInBytes = 0; + std::string m_folderTitle; // EPG lookup std::string m_m3uName; From 3ccb85b27d59266854b1849f74c6ddd0aa0cbac1 Mon Sep 17 00:00:00 2001 From: phunkyfish Date: Fri, 27 Oct 2023 11:06:59 +0100 Subject: [PATCH 2/3] Set default to include media Group name in path if no dir present --- pvr.iptvsimple/resources/instance-settings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pvr.iptvsimple/resources/instance-settings.xml b/pvr.iptvsimple/resources/instance-settings.xml index 78a2ff4e..0a5d4ce7 100644 --- a/pvr.iptvsimple/resources/instance-settings.xml +++ b/pvr.iptvsimple/resources/instance-settings.xml @@ -600,7 +600,7 @@ 0 - 0 + 2 From 6bdf14185a4cb921dec9adb7201cbeef81d5c524 Mon Sep 17 00:00:00 2001 From: phunkyfish Date: Fri, 27 Oct 2023 00:16:10 +0100 Subject: [PATCH 3/3] changelog and version 20.12.0 --- pvr.iptvsimple/addon.xml.in | 2 +- pvr.iptvsimple/changelog.txt | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pvr.iptvsimple/addon.xml.in b/pvr.iptvsimple/addon.xml.in index efdc7ce4..00d48554 100644 --- a/pvr.iptvsimple/addon.xml.in +++ b/pvr.iptvsimple/addon.xml.in @@ -1,7 +1,7 @@ @ADDON_DEPENDS@ diff --git a/pvr.iptvsimple/changelog.txt b/pvr.iptvsimple/changelog.txt index cfdf7081..4a1a2fe8 100644 --- a/pvr.iptvsimple/changelog.txt +++ b/pvr.iptvsimple/changelog.txt @@ -1,3 +1,7 @@ +v20.12.0 +- Extract season from medis title for path if not available +- Set default to include media Group name in path if no dir present + v20.11.1 - EPG entry selection criteria for timezone shift calculation works for Media as well as channels - Fix being able to disable media from settings