feat: streamed sports api compatability

This commit is contained in:
antebrl
2025-01-17 10:28:12 +00:00
parent 11df48fa3d
commit 383beac9c2
3 changed files with 52 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
const m3uParser = require('iptv-playlist-parser');
const ChannelService = require('./ChannelService');
const ChannelStorage = require('./ChannelStorage');
const StreamedSuSession = require('./session/StreamedSuSession');
class PlaylistService {
@@ -12,6 +13,18 @@ class PlaylistService {
if(playlist.startsWith("http")) {
const response = await fetch(playlist);
content = await response.text();
//check for streamedSu here and add channel for every source
if(playlist.includes('streamed.su')) {
console.log('Fetching StreamedSu API channels');
const channels = await StreamedSuSession.fetchApiChannels(playlist, mode, headersJson, playlistName);
channels.forEach(channel => {
ChannelService.addChannel(channel, false);
});
ChannelStorage.save(ChannelService.getChannels());
return channels;
}
} else {
content = playlist;
}

View File

@@ -5,6 +5,44 @@ class StreamedSuSession extends SessionHandler {
super();
this.channel = channel;
}
static async fetchApiChannels(apiUrl, mode, headersJson, playlistName) {
try {
const response = await fetch(apiUrl);
if (!response.ok) {
throw new Error(response);
}
const data = await response.json();
let channels = [];
data.forEach(stream => {
const { title, category, poster, sources } = stream;
for(const source of sources) {
const channelUrl = `https://rr.vipstreams.in/${source.source}/js/${source.id}/1/playlist.m3u8`;
const channelAvatar = `https://streamed.su${poster ?? '/api/images/poster/fallback.webp'}`;
channels.push({
name: title,
url: channelUrl,
avatar: channelAvatar,
mode: mode,
headersJson: headersJson,
group: category,
playlist: apiUrl,
playlistName: playlistName
});
}
});
return channels;
} catch (error) {
console.error('Fetch StreamedSu API failed:', error);
return [];
}
}
async createSession() {

View File

@@ -430,7 +430,7 @@ function ChannelModal({ onClose, channel }: ChannelModalProps) {
</button>
</div>
<div className="space-y-2">
{headers.map((header, index) => (
{headers && headers.map((header, index) => (
<div key={index} className="flex items-center space-x-2">
<CustomHeaderInput
header={header}