From 08bc6f12bbd1db1381dd56b978d0b5638d254777 Mon Sep 17 00:00:00 2001 From: phunkyfish Date: Sun, 15 Oct 2023 18:05:43 -0400 Subject: [PATCH 1/2] Add support for Genres for Media --- src/iptvsimple/Epg.cpp | 4 ++- src/iptvsimple/Media.h | 5 ++++ src/iptvsimple/data/MediaEntry.cpp | 39 +++++++++++++++++++++++++++++- src/iptvsimple/data/MediaEntry.h | 4 ++- 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/iptvsimple/Epg.cpp b/src/iptvsimple/Epg.cpp index befa23fe7..9ac6286be 100644 --- a/src/iptvsimple/Epg.cpp +++ b/src/iptvsimple/Epg.cpp @@ -33,6 +33,8 @@ Epg::Epg(kodi::addon::CInstancePVRClient* client, Channels& channels, Media& med { MoveOldGenresXMLFileToNewLocation(); } + + m_media.SetGenreMappings(m_genreMappings); } bool Epg::Init(int epgMaxPastDays, int epgMaxFutureDays) @@ -617,6 +619,6 @@ void Epg::MergeEpgDataIntoMedia() // then return the first entry as matching. This is a common pattern // for channel that only contain a single media item. if (channelEpg && !channelEpg->GetEpgEntries().empty()) - mediaEntry.UpdateFrom(channelEpg->GetEpgEntries().begin()->second); + mediaEntry.UpdateFrom(channelEpg->GetEpgEntries().begin()->second, m_genreMappings); } } \ No newline at end of file diff --git a/src/iptvsimple/Media.h b/src/iptvsimple/Media.h index 355d72e50..81cc05daa 100644 --- a/src/iptvsimple/Media.h +++ b/src/iptvsimple/Media.h @@ -9,6 +9,7 @@ #pragma once #include "ChannelGroups.h" +#include "data/EpgGenre.h" #include "data/MediaEntry.h" #include @@ -31,6 +32,8 @@ namespace iptvsimple std::vector& GetMediaEntryList() { return m_media; } + void SetGenreMappings(std::vector& genreMappings) { m_genreMappings = genreMappings; } + private: data::MediaEntry GetMediaEntry(const std::string& mediaEntryId) const; bool IsInVirtualMediaEntryFolder(const data::MediaEntry& mediaEntry) const; @@ -38,6 +41,8 @@ namespace iptvsimple std::vector m_media; std::unordered_map m_mediaIdMap; + std::vector m_genreMappings; + bool m_haveMediaTypes = false; std::shared_ptr m_settings; diff --git a/src/iptvsimple/data/MediaEntry.cpp b/src/iptvsimple/data/MediaEntry.cpp index d75f83b82..75134b916 100644 --- a/src/iptvsimple/data/MediaEntry.cpp +++ b/src/iptvsimple/data/MediaEntry.cpp @@ -76,7 +76,7 @@ void MediaEntry::UpdateFrom(iptvsimple::data::Channel channel) m_inputStreamName = channel.GetInputStreamName(); } -void MediaEntry::UpdateFrom(iptvsimple::data::EpgEntry epgEntry) +void MediaEntry::UpdateFrom(iptvsimple::data::EpgEntry epgEntry, const std::vector& genreMappings) { // All from Base Entry m_startTime = epgEntry.GetStartTime(); @@ -95,6 +95,19 @@ void MediaEntry::UpdateFrom(iptvsimple::data::EpgEntry epgEntry) if (!epgEntry.GetIconPath().empty()) m_iconPath = epgEntry.GetIconPath(); m_genreString = epgEntry.GetGenreString(); + if (SetEpgGenre(genreMappings)) + { + if (m_settings->UseEpgGenreTextWhenMapping()) + { + //Setting this value in sub type allows custom text to be displayed + //while still sending the type used for EPG colour + m_genreSubType = EPG_GENRE_USE_STRING; + } + } + else + { + m_genreType = EPG_GENRE_USE_STRING; + } m_cast = epgEntry.GetCast(); m_director = epgEntry.GetDirector(); m_writer = epgEntry.GetWriter(); @@ -108,6 +121,30 @@ void MediaEntry::UpdateFrom(iptvsimple::data::EpgEntry epgEntry) m_premiere = epgEntry.IsPremiere(); } +bool MediaEntry::SetEpgGenre(const std::vector genreMappings) +{ + if (genreMappings.empty()) + return false; + + for (const auto& genre : StringUtils::Split(m_genreString, EPG_STRING_TOKEN_SEPARATOR)) + { + if (genre.empty()) + continue; + + for (const auto& genreMapping : genreMappings) + { + if (StringUtils::EqualsNoCase(genreMapping.GetGenreString(), genre)) + { + m_genreType = genreMapping.GetGenreType(); + m_genreSubType = genreMapping.GetGenreSubType(); + return true; + } + } + } + + return false; +} + namespace { diff --git a/src/iptvsimple/data/MediaEntry.h b/src/iptvsimple/data/MediaEntry.h index dd40197f7..f1c13eb57 100644 --- a/src/iptvsimple/data/MediaEntry.h +++ b/src/iptvsimple/data/MediaEntry.h @@ -86,10 +86,12 @@ namespace iptvsimple void Reset(); void UpdateFrom(iptvsimple::data::Channel channel); - void UpdateFrom(iptvsimple::data::EpgEntry epgEntry); + void UpdateFrom(iptvsimple::data::EpgEntry epgEntry, const std::vector& genres); void UpdateTo(kodi::addon::PVRRecording& left, bool isInVirtualMediaEntryFolder, bool haveMediaTypes); private: + bool SetEpgGenre(std::vector genreMappings); + std::string m_mediaEntryId; bool m_radio = false; time_t m_startTime = 0; From 67fcc45b184878cffe1402f7018fc3c616c79cf8 Mon Sep 17 00:00:00 2001 From: phunkyfish Date: Tue, 17 Oct 2023 15:52:35 +0100 Subject: [PATCH 2/2] changelog and version 20.11.2 --- pvr.iptvsimple/addon.xml.in | 2 +- pvr.iptvsimple/changelog.txt | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pvr.iptvsimple/addon.xml.in b/pvr.iptvsimple/addon.xml.in index 005134b08..e59b4bc5c 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 8bc3b0217..1eb7ee6a2 100644 --- a/pvr.iptvsimple/changelog.txt +++ b/pvr.iptvsimple/changelog.txt @@ -1,3 +1,6 @@ +v21.4.2 +- Add support for Genres for Media + v21.4.1 - EPG entry selection criteria for timezone shift calculation works for Media as well as channels - Fix being able to disable media from settings