diff --git a/scripts/db.js b/scripts/db.js index 77ad2eda3..91795217e 100644 --- a/scripts/db.js +++ b/scripts/db.js @@ -8,6 +8,7 @@ db.load = function () { const items = parser.parseIndex() for (const item of items) { const playlist = parser.parsePlaylist(item.url) + db.playlists.add(playlist) for (const channel of playlist.channels) { db.channels.add(channel) @@ -166,4 +167,28 @@ db.categories = { } } +db.playlists = { + list: [], + add(playlist) { + this.list.push(playlist) + }, + all() { + return this.list + }, + only(list = []) { + return this.list.filter(playlist => list.includes(playlist.name)) + }, + except(list = []) { + return this.list.filter(playlist => !list.includes(playlist.name)) + }, + sortBy(fields) { + this.list = utils.sortBy(this.list, fields) + + return this + }, + count() { + return this.list.length + } +} + module.exports = db