feat: add playlist name
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
class Channel {
|
||||
static nextId = 0;
|
||||
constructor(name, url, avatar, mode, headers = [], group = null, playlist = null) {
|
||||
constructor(name, url, avatar, mode, headers = [], group = null, playlist = null, playlistName = null) {
|
||||
this.id = Channel.nextId++;
|
||||
this.name = name;
|
||||
this.url = url;
|
||||
@@ -10,6 +10,7 @@ class Channel {
|
||||
this.headers = headers;
|
||||
this.group = group;
|
||||
this.playlist = playlist;
|
||||
this.playlistName = playlistName;
|
||||
}
|
||||
|
||||
restream() {
|
||||
|
||||
@@ -34,10 +34,10 @@ class ChannelService {
|
||||
return this.channels;
|
||||
}
|
||||
|
||||
getFilteredChannels({ playlist, group }) {
|
||||
getFilteredChannels({ playlistName, group }) {
|
||||
let filtered = this.channels;
|
||||
if (playlist) {
|
||||
filtered = filtered.filter(ch => ch.playlist && ch.playlist == playlist);
|
||||
if (playlistName) {
|
||||
filtered = filtered.filter(ch => ch.playlistName && ch.playlistName.toLowerCase() == playlistName.toLowerCase());
|
||||
}
|
||||
if (group) {
|
||||
filtered = filtered.filter(ch => ch.group && ch.group.toLowerCase() === group.toLowerCase());
|
||||
@@ -45,7 +45,7 @@ class ChannelService {
|
||||
return filtered;
|
||||
}
|
||||
|
||||
addChannel({ name, url, avatar, mode, headersJson, group = false, playlist = false }) {
|
||||
addChannel({ name, url, avatar, mode, headersJson, group = null, playlist = null, playlistName = null }) {
|
||||
const existing = this.channels.find(channel => channel.url === url);
|
||||
|
||||
if (existing) {
|
||||
@@ -53,7 +53,7 @@ class ChannelService {
|
||||
}
|
||||
|
||||
const headers = JSON.parse(headersJson);
|
||||
const newChannel = new Channel(name, url, avatar, mode, headers, group, playlist);
|
||||
const newChannel = new Channel(name, url, avatar, mode, headers, group, playlist, playlistName);
|
||||
this.channels.push(newChannel);
|
||||
|
||||
return newChannel;
|
||||
|
||||
@@ -3,7 +3,7 @@ const ChannelService = require('./ChannelService');
|
||||
|
||||
class PlaylistService {
|
||||
|
||||
async addPlaylist(playlistUrl, mode, headersJson) {
|
||||
async addPlaylist(playlistUrl, playlistName, mode, headersJson) {
|
||||
|
||||
const response = await fetch(playlistUrl);
|
||||
const content = await response.text();
|
||||
@@ -21,7 +21,8 @@ class PlaylistService {
|
||||
mode: mode,
|
||||
headersJson: headersJson,
|
||||
group: channel.group.title,
|
||||
playlist: playlistUrl
|
||||
playlist: playlistUrl,
|
||||
playlistName: playlistName
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@@ -42,7 +43,7 @@ class PlaylistService {
|
||||
for(let channel of channels) {
|
||||
channel = await ChannelService.updateChannel(channel.id, updatedAttributes);
|
||||
}
|
||||
|
||||
|
||||
return channels;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,9 +4,10 @@ const Channel = require('../models/Channel');
|
||||
|
||||
module.exports = (io, socket) => {
|
||||
|
||||
socket.on('add-playlist', async ({ playlist, mode, headersJson }) => {
|
||||
socket.on('add-playlist', async ({ playlist, playlistName, mode, headersJson }) => {
|
||||
try {
|
||||
const channels = await PlaylistService.addPlaylist(playlist, mode, headersJson);
|
||||
const channels = await PlaylistService.addPlaylist(playlist, playlistName, mode, headersJson);
|
||||
|
||||
if (channels) {
|
||||
channels.forEach(channel => {
|
||||
io.emit('channel-added', channel);
|
||||
@@ -21,7 +22,8 @@ module.exports = (io, socket) => {
|
||||
|
||||
socket.on('update-playlist', async ({ playlist, updatedAttributes }) => {
|
||||
try {
|
||||
const channels = PlaylistService.updatePlaylist(playlist, updatedAttributes);
|
||||
const channels = await PlaylistService.updatePlaylist(playlist, updatedAttributes);
|
||||
|
||||
channels.forEach(channel => {
|
||||
io.emit('channel-updated', channel.toFrontendJson());
|
||||
});
|
||||
@@ -34,7 +36,7 @@ module.exports = (io, socket) => {
|
||||
|
||||
socket.on('delete-playlist', async (playlist) => {
|
||||
try {
|
||||
const channels = PlaylistService.deletePlaylist(playlist);
|
||||
const channels = await PlaylistService.deletePlaylist(playlist);
|
||||
channels.forEach(channel => {
|
||||
io.emit('channel-deleted', channel.id);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user