diff --git a/src/app/components/playlist-uploader/playlist-uploader.component.ts b/src/app/components/playlist-uploader/playlist-uploader.component.ts
index f616ba0d3..399bef1f7 100644
--- a/src/app/components/playlist-uploader/playlist-uploader.component.ts
+++ b/src/app/components/playlist-uploader/playlist-uploader.component.ts
@@ -6,12 +6,12 @@ import {
humanizeBytes,
UploaderOptions,
} from 'ngx-uploader';
-import { ChannelStore, createChannel } from 'src/app/state';
+import { ChannelStore, createChannel, Channel } from 'src/app/state';
import { M3uService } from 'src/app/services/m3u-service.service';
import { Router } from '@angular/router';
import { NgxIndexedDBService } from 'ngx-indexed-db';
import { PLAYLISTS_STORE } from 'src/app/db.config';
-import {MatSnackBar} from '@angular/material/snack-bar';
+import { MatSnackBar } from '@angular/material/snack-bar';
/**
* Describes playlist interface
@@ -74,18 +74,13 @@ export class PlaylistUploaderComponent {
this.isLoading = true;
if (this.files.length > 0) {
const fileReader = new FileReader();
- fileReader.onload = fileLoadedEvent => {
+ fileReader.onload = (fileLoadedEvent) => {
const result = (fileLoadedEvent.target as FileReader)
.result;
const array = (result as string).split('\n');
- const playlist = this.m3uService.convertArrayToPlaylist(
- array
- );
- this.savePlaylist(
- this.files[0].name,
- playlist
- );
+ const playlist = this.m3uService.parsePlaylist(array);
+ this.savePlaylist(this.files[0].name, playlist);
this.setPlaylist(playlist);
};
@@ -101,7 +96,7 @@ export class PlaylistUploaderComponent {
typeof output.file !== 'undefined'
) {
const index = this.files.findIndex(
- file =>
+ (file) =>
typeof output.file !== 'undefined' &&
file.id === output.file.id
);
@@ -138,9 +133,17 @@ export class PlaylistUploaderComponent {
* @param playlist playlist to save
*/
savePlaylist(name: string, playlist: any): void {
- this.dbService.add
('playlists', { filename: name, title: name, playlist, importDate: new Date().getMilliseconds(), lastUsage: new Date().getMilliseconds() }).then(() => {
- console.log('playlist saved!')
- });
+ this.dbService
+ .add('playlists', {
+ filename: name,
+ title: name,
+ playlist,
+ importDate: new Date().getMilliseconds(),
+ lastUsage: new Date().getMilliseconds(),
+ })
+ .then(() => {
+ console.log('playlist saved!');
+ });
}
/**
@@ -148,8 +151,8 @@ export class PlaylistUploaderComponent {
*/
getPlaylists(): void {
this.dbService.getAll('playlists').then(
- (playlists: Playlist[]) => this.playlists = playlists,
- error => {
+ (playlists: Playlist[]) => (this.playlists = playlists),
+ (error) => {
console.error(error);
}
);
@@ -158,10 +161,13 @@ export class PlaylistUploaderComponent {
/**
* Sets the given playlist as active for the current session
* @param playlist m3u playlist
+ * // TODO: use typings from iptv-parser lib
*/
- setPlaylist(playlist: any): void {
- this.channelStore.reset();
- const channels = playlist.segments.map(element => createChannel(element));
+ setPlaylist(playlist: { header: any; items: Channel[] }): void {
+ this.channelStore.reset();
+ const channels = playlist.items.map((element) =>
+ createChannel(element)
+ );
this.channelStore.upsertMany(channels);
this.navigateToPlayer();
}
@@ -170,9 +176,11 @@ export class PlaylistUploaderComponent {
* Removes the provided playlist from the indexedDb
* @param playlist playlist to remove
*/
- removePlaylist(playlist: Playlist) {
+ removePlaylist(playlist: Playlist): void {
this.dbService.delete(PLAYLISTS_STORE, playlist.id);
this.getPlaylists();
- this.snackBar.open('Done! Playlist was removed.', null,{ duration: 2000 });
+ this.snackBar.open('Done! Playlist was removed.', null, {
+ duration: 2000,
+ });
}
}
diff --git a/src/app/components/recent-playlists/recent-playlists.component.html b/src/app/components/recent-playlists/recent-playlists.component.html
index 92da2c9f4..58ea921e4 100644
--- a/src/app/components/recent-playlists/recent-playlists.component.html
+++ b/src/app/components/recent-playlists/recent-playlists.component.html
@@ -1,13 +1,14 @@
- Recently added playlists
+ Recently added playlists ({{playlists.length}})
folder
{{ item.title || item.filename }}
- Channels: {{ item.playlist?.segments.length }}
+ Channels: {{ item.playlist?.items?.length }}
-