diff --git a/shared/channel.interface.ts b/shared/channel.interface.ts new file mode 100644 index 000000000..f907e59c6 --- /dev/null +++ b/shared/channel.interface.ts @@ -0,0 +1,32 @@ +/** + * Represents channel object + * TODO: define channel interface in iptv-parser library + */ +export interface Channel { + id: string; + url: string; + name: string; + group: { + title: string; + }; + tvg: { + id: string; + name: string; + language: string; + country: string; + url: string; + logo: string; + rec: string; + }; + epgParams?: string; + timeshift?: string; + catchup?: { + type?: string; + source?: string; + days?: string; + }; + http: { + referrer: string; + 'user-agent': string; + }; +} diff --git a/shared/constants.ts b/shared/constants.ts new file mode 100644 index 000000000..781bb1861 --- /dev/null +++ b/shared/constants.ts @@ -0,0 +1,4 @@ +/** + * Id of the channel with favorite channels aggregated from all added playlists + */ +export const GLOBAL_FAVORITES_PLAYLIST_ID = 'GLOBAL_FAVORITES'; diff --git a/shared/playlist.utils.ts b/shared/playlist.utils.ts new file mode 100644 index 000000000..f486725d9 --- /dev/null +++ b/shared/playlist.utils.ts @@ -0,0 +1,40 @@ +import { Channel } from './channel.interface'; +import { GLOBAL_FAVORITES_PLAYLIST_ID } from './constants'; +import { Playlist } from './playlist.interface'; + +/** + * Aggregates favorite channels as objects from all available playlists + * @param playlists all available playlists + * @returns an array with favorite channels from all playlists + */ +export function aggregateFavoriteChannels(playlists: Playlist[]): Channel[] { + const favorites = []; + playlists.forEach((playlist) => { + if (playlist.favorites?.length > 0) { + playlist.playlist.items.forEach((channel) => { + if (playlist.favorites.includes(channel.id)) { + favorites.push(channel); + } + }); + } + }); + return favorites; +} + +/** + * Creates a simplified playlist object which is used for global favorites + * @param channels channels list + * @returns simplified playlist object + */ +export function createFavoritesPlaylist( + channels: Channel[] +): Partial { + return { + id: GLOBAL_FAVORITES_PLAYLIST_ID, + _id: GLOBAL_FAVORITES_PLAYLIST_ID, + count: channels.length, + playlist: { + items: channels, + }, + }; +}