mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-08 17:06:15 -08:00
refactor: extract shared functions and interfaces from angular app
This commit is contained in:
1 parent
9cbccfcfb2
commit
e59b3c451c
3 files changed
+76
No files matched your search
@@ -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;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* Id of the channel with favorite channels aggregated from all added playlists
|
||||
*/
|
||||
export const GLOBAL_FAVORITES_PLAYLIST_ID = 'GLOBAL_FAVORITES';
|
||||
@@ -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<Playlist> {
|
||||
return {
|
||||
id: GLOBAL_FAVORITES_PLAYLIST_ID,
|
||||
_id: GLOBAL_FAVORITES_PLAYLIST_ID,
|
||||
count: channels.length,
|
||||
playlist: {
|
||||
items: channels,
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user