feat: backend integration of playlist m3u text
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user