Skip to content

Commit

Permalink
Support custom groups for Media
Browse files Browse the repository at this point in the history
  • Loading branch information
phunkyfish committed Apr 26, 2023
1 parent 2b8e5fa commit abd83b9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
21 changes: 20 additions & 1 deletion src/iptvsimple/Media.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,35 @@ int GenerateMediaEntryId(const char* providerName, const char* streamUrl)

} // unamed namespace

bool Media::AddMediaEntry(MediaEntry& mediaEntry)
bool Media::AddMediaEntry(MediaEntry& mediaEntry, std::vector<int>& groupIdList, ChannelGroups& channelGroups, bool channelHadGroups)
{
// If we have no groups set for this media check it that's ok before adding it.
// Note that TV is a proxy for Media. There is no concept of radio for media
if (m_settings->AllowTVChannelGroupsOnly() && groupIdList.empty())
return false;

std::string mediaEntryId = std::to_string(GenerateMediaEntryId(mediaEntry.GetProviderName().c_str(),
mediaEntry.GetStreamURL().c_str()));
mediaEntryId.append("-" + mediaEntry.GetDirectory() + mediaEntry.GetTitle());
mediaEntry.SetMediaEntryId(mediaEntryId);

// Media Ids must be unique
if (m_mediaIdMap.find(mediaEntryId) != m_mediaIdMap.end())
return false;

bool belongsToGroup = false;
for (int myGroupId : groupIdList)
{
if (channelGroups.GetChannelGroup(myGroupId) != nullptr)
belongsToGroup = true;
}


// We only care if a media entry belongs to a group if it had groups to begin with
// Note that a channel can have had groups but no have no groups valid currently.
if (!belongsToGroup && channelHadGroups)
return false;

m_media.emplace_back(mediaEntry);
m_mediaIdMap.insert({mediaEntryId, mediaEntry});

Expand Down
3 changes: 2 additions & 1 deletion src/iptvsimple/Media.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#pragma once

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

#include <string>
Expand All @@ -26,7 +27,7 @@ namespace iptvsimple
const std::string GetMediaEntryURL(const kodi::addon::PVRRecording& mediaEntry);
const iptvsimple::data::MediaEntry* FindMediaEntry(const std::string& id, const std::string& displayName) const;

bool AddMediaEntry(iptvsimple::data::MediaEntry& entry);
bool AddMediaEntry(iptvsimple::data::MediaEntry& entry, std::vector<int>& groupIdList, iptvsimple::ChannelGroups& channelGroups, bool channelHadGroups);

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

Expand Down
2 changes: 1 addition & 1 deletion src/iptvsimple/PlaylistLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ bool PlaylistLoader::LoadPlayList()
entry.UpdateFrom(tmpChannel);
entry.SetStreamURL(line);

if (!m_media.AddMediaEntry(entry))
if (!m_media.AddMediaEntry(entry, currentChannelGroupIdList, m_channelGroups, channelHadGroups))
Logger::Log(LEVEL_DEBUG, "%s - Counld not add media entry as an entry with the same gnenerated unique ID already exists", __func__);

}
Expand Down

0 comments on commit abd83b9

Please sign in to comment.