diff --git a/pvr.iptvsimple/addon.xml.in b/pvr.iptvsimple/addon.xml.in index 005134b0..e59b4bc5 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 8bc3b021..1eb7ee6a 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 diff --git a/src/iptvsimple/Epg.cpp b/src/iptvsimple/Epg.cpp index befa23fe..9ac6286b 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 355d72e5..81cc05da 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 d75f83b8..75134b91 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 dd40197f..f1c13eb5 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;