feat: backend integration of playlist m3u text

This commit is contained in:
Ante Brähler
2025-01-13 16:13:52 +00:00
parent 2c92d75b03
commit a13c04603d
4 changed files with 32 additions and 19 deletions

View File

@@ -30,11 +30,10 @@ class ChannelService {
}
addChannel({ name, url, avatar, mode, headersJson, group = null, playlist = null, playlistName = null }) {
const existing = this.channels.find(channel => channel.url === url);
if (existing) {
throw new Error('Channel already exists');
}
// const existing = this.channels.find(channel => channel.url === url);
// if (existing) {
// throw new Error('Channel already exists');
// }
const headers = JSON.parse(headersJson);
const newChannel = new Channel(name, url, avatar, mode, headers, group, playlist, playlistName);

View File

@@ -41,7 +41,7 @@ module.exports = {
return channelsJson.map(channelJson => Channel.from(channelJson));
} catch (err) {
console.error('Error loading data from storage:', err);
return [];
return channels;
}
}
this.save(channels);

View File

@@ -3,12 +3,17 @@ const ChannelService = require('./ChannelService');
class PlaylistService {
async addPlaylist(playlistUrl, playlistName, mode, headersJson) {
async addPlaylist(playlist, playlistName, mode, headersJson) {
console.log('Adding playlist', playlistUrl);
console.log('Adding playlist', playlist);
const response = await fetch(playlistUrl);
const content = await response.text();
let content = "";
if(playlist.startsWith("http")) {
const response = await fetch(playlist);
content = await response.text();
} else {
content = playlist;
}
const parsedPlaylist = m3uParser.parse(content);
@@ -23,7 +28,7 @@ class PlaylistService {
mode: mode,
headersJson: headersJson,
group: channel.group.title,
playlist: playlistUrl,
playlist: playlist,
playlistName: playlistName
});
} catch (error) {