mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-08 17:06:15 -08:00
feat: generate global playlist with all favorites
this commit closes #97
This commit is contained in:
1 parent
c7d5310ef7
commit
764201a0af
11 files changed
+78
-113
No files matched your search
@@ -3,6 +3,7 @@ import axios from 'axios';
|
||||
import { app, BrowserWindow, ipcMain, session } from 'electron';
|
||||
import { parse } from 'iptv-playlist-parser';
|
||||
import Nedb, { Cursor } from 'nedb-promises-ts';
|
||||
import { GLOBAL_FAVORITES_PLAYLIST_ID } from './shared/constants';
|
||||
import {
|
||||
CHANNEL_SET_USER_AGENT,
|
||||
EPG_ERROR,
|
||||
@@ -27,6 +28,10 @@ import {
|
||||
PLAYLIST_UPDATE_RESPONSE,
|
||||
} from './shared/ipc-commands';
|
||||
import { Playlist, PlaylistUpdateState } from './shared/playlist.interface';
|
||||
import {
|
||||
aggregateFavoriteChannels,
|
||||
createFavoritesPlaylist,
|
||||
} from './shared/playlist.utils';
|
||||
import { ParsedPlaylist } from './src/typings.d';
|
||||
|
||||
const fs = require('fs');
|
||||
@@ -97,12 +102,16 @@ export class Api {
|
||||
ipcMain.on(PLAYLIST_GET_ALL, (event) => this.sendAllPlaylists(event));
|
||||
|
||||
ipcMain.on(PLAYLIST_GET_BY_ID, (event, args) => {
|
||||
db.findOne({ _id: args.id }).then((playlist) => {
|
||||
this.setUserAgent(playlist.userAgent);
|
||||
event.sender.send(PLAYLIST_PARSE_RESPONSE, {
|
||||
payload: playlist,
|
||||
if (args.id === GLOBAL_FAVORITES_PLAYLIST_ID) {
|
||||
this.sendPlaylistWithGlobalFavorites(event);
|
||||
} else {
|
||||
db.findOne({ _id: args.id }).then((playlist) => {
|
||||
this.setUserAgent(playlist?.userAgent);
|
||||
event.sender.send(PLAYLIST_PARSE_RESPONSE, {
|
||||
payload: playlist,
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.on(PLAYLIST_REMOVE_BY_ID, (event, args) => {
|
||||
@@ -234,6 +243,22 @@ export class Api {
|
||||
this.refreshPlaylists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message with playlist that contains favorite channels from all available playlists
|
||||
* @param event ipc main event
|
||||
*/
|
||||
sendPlaylistWithGlobalFavorites(event: Electron.IpcMainEvent) {
|
||||
db.find({ type: { $exists: false } }).then((playlists: Playlist[]) => {
|
||||
const favoriteChannels = aggregateFavoriteChannels(playlists);
|
||||
const favPlaylist = createFavoritesPlaylist(favoriteChannels);
|
||||
|
||||
event.sender.send(PLAYLIST_PARSE_RESPONSE, {
|
||||
type: PLAYLIST_PARSE_RESPONSE,
|
||||
payload: favPlaylist,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default listeners for custom-titlebar
|
||||
*/
|
||||
|
||||
+2
-1
@@ -8,7 +8,8 @@ import {
|
||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||
import * as _ from 'lodash';
|
||||
import { Observable } from 'rxjs';
|
||||
import { Channel, ChannelQuery, ChannelStore } from '../../../state';
|
||||
import { Channel } from '../../../../../shared/channel.interface';
|
||||
import { ChannelQuery, ChannelStore } from '../../../state';
|
||||
|
||||
@Component({
|
||||
selector: 'app-channel-list-container',
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
import { MockComponent, MockProvider, MockModule, MockPipe } from 'ng-mocks';
|
||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
/* eslint-disable @typescript-eslint/unbound-method */
|
||||
import { MatDialog, MatDialogModule } from '@angular/material/dialog';
|
||||
import { TranslatePipe } from '@ngx-translate/core';
|
||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
import { EpgListComponent, EpgData } from './epg-list.component';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatListModule } from '@angular/material/list';
|
||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
||||
import { TranslatePipe } from '@ngx-translate/core';
|
||||
import * as moment from 'moment';
|
||||
import { MockComponent, MockModule, MockPipe, MockProvider } from 'ng-mocks';
|
||||
import { Channel } from '../../../../../shared/channel.interface';
|
||||
import { EPG_GET_PROGRAM_DONE } from '../../../../../shared/ipc-commands';
|
||||
import { DataService } from '../../../services/data.service';
|
||||
import { ElectronServiceStub } from '../../../services/electron.service.stub';
|
||||
import * as moment from 'moment';
|
||||
import { EPG_GET_PROGRAM_DONE } from '../../../../../shared/ipc-commands';
|
||||
import { Channel, ChannelStore } from '../../../state';
|
||||
import { MomentDatePipe } from '../../../shared/pipes/moment-date.pipe';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { ChannelStore } from '../../../state';
|
||||
import { EpgListItemComponent } from './epg-list-item/epg-list-item.component';
|
||||
import { EpgData, EpgListComponent } from './epg-list.component';
|
||||
|
||||
describe('EpgListComponent', () => {
|
||||
let component: EpgListComponent;
|
||||
|
||||
@@ -7,8 +7,8 @@ import {
|
||||
SimpleChanges,
|
||||
ViewChild,
|
||||
} from '@angular/core';
|
||||
import { Channel } from '../../../state';
|
||||
import Hls from 'hls.js';
|
||||
import { Channel } from '../../../../../shared/channel.interface';
|
||||
|
||||
/**
|
||||
* This component contains the implementation of HTML5 based video player
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Channel } from './../../../state/channel.model';
|
||||
import { Component, Input, OnChanges, SimpleChanges } from '@angular/core';
|
||||
import { EpgProgram } from '../../models/epg-program.model';
|
||||
import * as moment from 'moment';
|
||||
import { Channel } from '../../../../../shared/channel.interface';
|
||||
import { EpgProgram } from '../../models/epg-program.model';
|
||||
|
||||
@Component({
|
||||
selector: 'app-info-overlay',
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
<mat-icon>menu</mat-icon>
|
||||
</button>
|
||||
<button
|
||||
*ngIf="playlistId !== 'GLOBAL_FAVORITES'"
|
||||
mat-icon-button
|
||||
(click)="addToFavorites(activeChannel)"
|
||||
[matTooltip]="'TOP_MENU.TOGGLE_FAVORITE_FLAG' | translate"
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
import { InfoOverlayComponent } from './../info-overlay/info-overlay.component';
|
||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
||||
import { TranslatePipe } from '@ngx-translate/core';
|
||||
/* eslint-disable @typescript-eslint/unbound-method */
|
||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
import { VideoPlayerComponent } from './video-player.component';
|
||||
import { MockComponent, MockModule, MockPipe } from 'ng-mocks';
|
||||
import { ChannelListContainerComponent } from '../channel-list-container/channel-list-container.component';
|
||||
import { VjsPlayerComponent } from '../vjs-player/vjs-player.component';
|
||||
import { MatSidenavModule } from '@angular/material/sidenav';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatToolbarModule } from '@angular/material/toolbar';
|
||||
import { MatSidenavModule } from '@angular/material/sidenav';
|
||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||
import { ChannelStore } from '../../../state/channel.store';
|
||||
import { MatToolbarModule } from '@angular/material/toolbar';
|
||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
||||
import { TranslatePipe } from '@ngx-translate/core';
|
||||
import { MockComponent, MockModule, MockPipe } from 'ng-mocks';
|
||||
import * as MOCKED_PLAYLIST from '../../../../mocks/playlist.json';
|
||||
import { createChannel } from '../../../state';
|
||||
import { HtmlVideoPlayerComponent } from '../html-video-player/html-video-player.component';
|
||||
import { EpgListComponent } from '../epg-list/epg-list.component';
|
||||
import { VideoPlayer } from '../../../settings/settings.interface';
|
||||
import { DataService } from '../../../services/data.service';
|
||||
import { ElectronServiceStub } from '../../../services/electron.service.stub';
|
||||
import { VideoPlayer } from '../../../settings/settings.interface';
|
||||
import { createChannel } from '../../../state';
|
||||
import { ChannelStore } from '../../../state/channel.store';
|
||||
import { ChannelListContainerComponent } from '../channel-list-container/channel-list-container.component';
|
||||
import { EpgListComponent } from '../epg-list/epg-list.component';
|
||||
import { HtmlVideoPlayerComponent } from '../html-video-player/html-video-player.component';
|
||||
import { VjsPlayerComponent } from '../vjs-player/vjs-player.component';
|
||||
import { InfoOverlayComponent } from './../info-overlay/info-overlay.component';
|
||||
import { VideoPlayerComponent } from './video-player.component';
|
||||
|
||||
class MatSnackBarStub {
|
||||
open(): void {}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import { EpgProgram } from './../../models/epg-program.model';
|
||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||
import { ChannelQuery, Channel, ChannelStore } from '../../../state';
|
||||
import { MatSidenav } from '@angular/material/sidenav';
|
||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||
import { StorageMap } from '@ngx-pwa/local-storage';
|
||||
import { Observable } from 'rxjs';
|
||||
import { tap } from 'rxjs/operators';
|
||||
import { MatSidenav } from '@angular/material/sidenav';
|
||||
import { StorageMap } from '@ngx-pwa/local-storage';
|
||||
import { Channel } from '../../../../../shared/channel.interface';
|
||||
import { Settings, VideoPlayer } from '../../../settings/settings.interface';
|
||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||
import { STORE_KEY } from '../../../shared/enums/store-keys.enum';
|
||||
import { ChannelQuery, ChannelStore } from '../../../state';
|
||||
import { EpgProgram } from './../../models/epg-program.model';
|
||||
|
||||
@Component({
|
||||
selector: 'app-video-player',
|
||||
@@ -50,6 +51,9 @@ export class VideoPlayerComponent implements OnInit {
|
||||
/** Sidebar object */
|
||||
@ViewChild('sidenav') sideNav: MatSidenav;
|
||||
|
||||
/** ID of the current playlist */
|
||||
playlistId = this.channelQuery.getValue().playlistId;
|
||||
|
||||
/**
|
||||
* Creates an instance of VideoPlayerComponent
|
||||
* @param channelQuery akita's channel query
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { guid } from '@datorama/akita';
|
||||
import { Channel } from 'diagnostics_channel';
|
||||
import { parse } from 'iptv-playlist-parser';
|
||||
import { NgxIndexedDBService } from 'ngx-indexed-db';
|
||||
import { catchError, combineLatest, map, switchMap, throwError } from 'rxjs';
|
||||
import { GLOBAL_FAVORITES_PLAYLIST_ID } from '../../../shared/constants';
|
||||
import {
|
||||
ERROR,
|
||||
PLAYLIST_GET_ALL,
|
||||
@@ -24,16 +24,15 @@ import {
|
||||
Playlist,
|
||||
PlaylistUpdateState,
|
||||
} from '../../../shared/playlist.interface';
|
||||
import {
|
||||
aggregateFavoriteChannels,
|
||||
createFavoritesPlaylist,
|
||||
} from '../../../shared/playlist.utils';
|
||||
import { AppConfig } from '../../environments/environment';
|
||||
import { ParsedPlaylist } from '../../typings';
|
||||
import { DbStores } from '../indexed-db.config';
|
||||
import { DataService } from './data.service';
|
||||
|
||||
/**
|
||||
* Id of the channel with favorite channels aggregated from all added playlists
|
||||
*/
|
||||
export const GLOBAL_FAVORITES_PLAYLIST_ID = 'GLOBAL_FAVORITES';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
@@ -63,41 +62,6 @@ export class PwaService extends DataService {
|
||||
return AppConfig.version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Aggregates favorite channels as objects from all available playlists
|
||||
* @param playlists all available playlists
|
||||
* @returns favorite channels
|
||||
*/
|
||||
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
|
||||
*/
|
||||
createFavoritesPlaylist(channels: Channel[]): Partial<Playlist> {
|
||||
return {
|
||||
id: GLOBAL_FAVORITES_PLAYLIST_ID,
|
||||
_id: GLOBAL_FAVORITES_PLAYLIST_ID,
|
||||
count: channels.length,
|
||||
playlist: {
|
||||
items: channels,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the count of favorite channels from all playlists
|
||||
*/
|
||||
@@ -124,9 +88,9 @@ export class PwaService extends DataService {
|
||||
.pipe(
|
||||
map((playlists: Playlist[]) => {
|
||||
const favoriteChannels =
|
||||
this.aggregateFavoriteChannels(playlists);
|
||||
aggregateFavoriteChannels(playlists);
|
||||
const favPlaylist =
|
||||
this.createFavoritesPlaylist(favoriteChannels);
|
||||
createFavoritesPlaylist(favoriteChannels);
|
||||
return favPlaylist;
|
||||
})
|
||||
)
|
||||
|
||||
@@ -1,35 +1,4 @@
|
||||
/**
|
||||
* 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;
|
||||
};
|
||||
}
|
||||
import { Channel } from '../../../shared/channel.interface';
|
||||
|
||||
/**
|
||||
* Creates new channel object based on the given fields
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { EntityState, EntityStore, StoreConfig } from '@datorama/akita';
|
||||
import * as moment from 'moment';
|
||||
import { Channel } from '../../../shared/channel.interface';
|
||||
import {
|
||||
CHANNEL_SET_USER_AGENT,
|
||||
EPG_GET_PROGRAM,
|
||||
@@ -8,7 +9,6 @@ import {
|
||||
} from '../../../shared/ipc-commands';
|
||||
import { EpgProgram } from '../player/models/epg-program.model';
|
||||
import { DataService } from '../services/data.service';
|
||||
import { Channel } from './channel.model';
|
||||
|
||||
export interface ChannelState extends EntityState<Channel> {
|
||||
active: Channel;
|
||||
|
||||
Reference in new issue
Block a user