Skip to content

Commit

Permalink
Merge pull request #797 from phunkyfish/media-entry-one-only
Browse files Browse the repository at this point in the history
Add support for Genres for Media
  • Loading branch information
phunkyfish authored Oct 17, 2023
2 parents 9573291 + 67fcc45 commit 97d4be3
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 4 deletions.
2 changes: 1 addition & 1 deletion 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="21.4.1"
version="21.4.2"
name="IPTV Simple Client"
provider-name="nightik and Ross Nicholson">
<requires>@ADDON_DEPENDS@
Expand Down
3 changes: 3 additions & 0 deletions pvr.iptvsimple/changelog.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/iptvsimple/Epg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
}
5 changes: 5 additions & 0 deletions src/iptvsimple/Media.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#pragma once

#include "ChannelGroups.h"
#include "data/EpgGenre.h"
#include "data/MediaEntry.h"

#include <string>
Expand All @@ -31,13 +32,17 @@ namespace iptvsimple

std::vector<iptvsimple::data::MediaEntry>& GetMediaEntryList() { return m_media; }

void SetGenreMappings(std::vector<iptvsimple::data::EpgGenre>& genreMappings) { m_genreMappings = genreMappings; }

private:
data::MediaEntry GetMediaEntry(const std::string& mediaEntryId) const;
bool IsInVirtualMediaEntryFolder(const data::MediaEntry& mediaEntry) const;

std::vector<iptvsimple::data::MediaEntry> m_media;
std::unordered_map<std::string, iptvsimple::data::MediaEntry> m_mediaIdMap;

std::vector<iptvsimple::data::EpgGenre> m_genreMappings;

bool m_haveMediaTypes = false;

std::shared_ptr<iptvsimple::InstanceSettings> m_settings;
Expand Down
39 changes: 38 additions & 1 deletion src/iptvsimple/data/MediaEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<EpgGenre>& genreMappings)
{
// All from Base Entry
m_startTime = epgEntry.GetStartTime();
Expand All @@ -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();
Expand All @@ -108,6 +121,30 @@ void MediaEntry::UpdateFrom(iptvsimple::data::EpgEntry epgEntry)
m_premiere = epgEntry.IsPremiere();
}

bool MediaEntry::SetEpgGenre(const std::vector<EpgGenre> 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
{

Expand Down
4 changes: 3 additions & 1 deletion src/iptvsimple/data/MediaEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<EpgGenre>& genres);
void UpdateTo(kodi::addon::PVRRecording& left, bool isInVirtualMediaEntryFolder, bool haveMediaTypes);

private:
bool SetEpgGenre(std::vector<EpgGenre> genreMappings);

std::string m_mediaEntryId;
bool m_radio = false;
time_t m_startTime = 0;
Expand Down

0 comments on commit 97d4be3

Please sign in to comment.