feat: store channels in filesystem
This commit is contained in:
@@ -16,6 +16,10 @@ class Channel {
|
||||
restream() {
|
||||
return this.mode === 'restream';
|
||||
}
|
||||
|
||||
static from(json){
|
||||
return Object.assign(new Channel(), json);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Channel;
|
||||
@@ -1,33 +1,12 @@
|
||||
const streamController = require('./restream/StreamController');
|
||||
const Channel = require('../models/Channel');
|
||||
const storageService = require('./restream/StorageService');
|
||||
const ChannelStorage = require('./ChannelStorage');
|
||||
|
||||
|
||||
class ChannelService {
|
||||
constructor() {
|
||||
|
||||
const daddyHeaders = [
|
||||
{ "key": "Origin", "value": "https://cookiewebplay.xyz" },
|
||||
{ "key": "User-Agent", "value": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36" },
|
||||
{ "key": "Referer", "value": "https://cookiewebplay.xyz/" }
|
||||
];
|
||||
|
||||
const streamedSuHeaders = [
|
||||
{ "key": "Origin", "value": "https://embedme.top" },
|
||||
{ "key": "User-Agent", "value": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:132.0) Gecko/20100101 Firefox/132.0" },
|
||||
{ "key": "Referer", "value": "https://embedme.top/" }
|
||||
];
|
||||
|
||||
this.channels = [
|
||||
//Some Test-channels to get started, remove this when using your own playlist
|
||||
//new Channel('Das Erste', "https://mcdn.daserste.de/daserste/de/master.m3u8", "https://upload.wikimedia.org/wikipedia/commons/thumb/5/56/Das_Erste-Logo_klein.svg/768px-Das_Erste-Logo_klein.svg.png", 'direct'),
|
||||
new Channel('DAZN 1 DE', "https://xyzdddd.mizhls.ru/lb/premium426/index.m3u8", "https://upload.wikimedia.org/wikipedia/commons/4/49/DAZN_1.svg", 'proxy', daddyHeaders),
|
||||
new Channel('beIN Sports 1', "https://xyzdddd.mizhls.ru/lb/premium61/index.m3u8", "https://www.thesportsdb.com/images/media/channel/logo/BeIn_Sports_1_Australia.png", 'proxy', daddyHeaders),
|
||||
new Channel('beIN Sports 2', "https://xyzdddd.mizhls.ru/lb/premium92/index.m3u8", "https://www.thesportsdb.com/images/media/channel/logo/BeIn_Sports_HD_2_France.png", 'proxy', daddyHeaders),
|
||||
new Channel('Sky Sport Football', "https://xyzdddd.mizhls.ru/lb/premium35/index.m3u8", "https://raw.githubusercontent.com/tv-logo/tv-logos/main/countries/united-kingdom/sky-sports-football-uk.png", 'proxy', daddyHeaders),
|
||||
new Channel('Sky Sports Premier League', "https://xyzdddd.mizhls.ru/lb/premium130/index.m3u8", "https://github.com/tv-logo/tv-logos/blob/main/countries/united-kingdom/sky-sports-premier-league-uk.png?raw=true", 'proxy', daddyHeaders),
|
||||
new Channel('SuperSport Premier League', 'https://xyzdddd.mizhls.ru/lb/premium414/index.m3u8', "https://github.com/tv-logo/tv-logos/blob/8d25ddd79ca2f9cd033b808c45cccd2b3da563ee/countries/south-africa/supersport-premier-league-za.png?raw=true", 'restream', daddyHeaders),
|
||||
//new Channel('TEST', 'https://rr.vipstreams.in/alpha/js/al-taawon-vs-al-qadisiya/1/playlist.m3u8', "https://upload.wikimedia.org/wikipedia/commons/thumb/5/56/Das_Erste-Logo_klein.svg/768px-Das_Erste-Logo_klein.svg.png", 'restream', streamedSuHeaders),
|
||||
];
|
||||
this.channels = ChannelStorage.load();
|
||||
this.currentChannel = this.channels[0];
|
||||
}
|
||||
|
||||
@@ -60,6 +39,7 @@ class ChannelService {
|
||||
const headers = JSON.parse(headersJson);
|
||||
const newChannel = new Channel(name, url, avatar, mode, headers, group, playlist, playlistName);
|
||||
this.channels.push(newChannel);
|
||||
ChannelStorage.save(this.channels);
|
||||
|
||||
return newChannel;
|
||||
}
|
||||
@@ -103,6 +83,7 @@ class ChannelService {
|
||||
await this.setCurrentChannel(0);
|
||||
}
|
||||
|
||||
ChannelStorage.save(this.channels);
|
||||
|
||||
return this.currentChannel;
|
||||
}
|
||||
@@ -130,6 +111,8 @@ class ChannelService {
|
||||
}
|
||||
}
|
||||
|
||||
ChannelStorage.save(this.channels);
|
||||
|
||||
return channel;
|
||||
}
|
||||
}
|
||||
|
||||
59
backend/services/ChannelStorage.js
Normal file
59
backend/services/ChannelStorage.js
Normal file
@@ -0,0 +1,59 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const Channel = require('../models/Channel');
|
||||
|
||||
const storageFilePath = path.resolve('/channels/channels.json');
|
||||
|
||||
module.exports = {
|
||||
load() {
|
||||
|
||||
// Default example channels
|
||||
const daddyHeaders = [
|
||||
{ "key": "Origin", "value": "https://cookiewebplay.xyz" },
|
||||
{ "key": "User-Agent", "value": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36" },
|
||||
{ "key": "Referer", "value": "https://cookiewebplay.xyz/" }
|
||||
];
|
||||
|
||||
const streamedSuHeaders = [
|
||||
{ "key": "Origin", "value": "https://embedme.top" },
|
||||
{ "key": "User-Agent", "value": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:132.0) Gecko/20100101 Firefox/132.0" },
|
||||
{ "key": "Referer", "value": "https://embedme.top/" }
|
||||
];
|
||||
|
||||
const channels = [
|
||||
//Some Test-channels to get started, remove this when using your own playlist
|
||||
//new Channel('Das Erste', "https://mcdn.daserste.de/daserste/de/master.m3u8", "https://upload.wikimedia.org/wikipedia/commons/thumb/5/56/Das_Erste-Logo_klein.svg/768px-Das_Erste-Logo_klein.svg.png", 'direct'),
|
||||
new Channel('DAZN 1 DE', "https://xyzdddd.mizhls.ru/lb/premium426/index.m3u8", "https://upload.wikimedia.org/wikipedia/commons/4/49/DAZN_1.svg", 'proxy', daddyHeaders),
|
||||
new Channel('beIN Sports 1', "https://xyzdddd.mizhls.ru/lb/premium61/index.m3u8", "https://www.thesportsdb.com/images/media/channel/logo/BeIn_Sports_1_Australia.png", 'proxy', daddyHeaders),
|
||||
new Channel('beIN Sports 2', "https://xyzdddd.mizhls.ru/lb/premium92/index.m3u8", "https://www.thesportsdb.com/images/media/channel/logo/BeIn_Sports_HD_2_France.png", 'proxy', daddyHeaders),
|
||||
new Channel('Sky Sport Football', "https://xyzdddd.mizhls.ru/lb/premium35/index.m3u8", "https://raw.githubusercontent.com/tv-logo/tv-logos/main/countries/united-kingdom/sky-sports-football-uk.png", 'proxy', daddyHeaders),
|
||||
new Channel('Sky Sports Premier League', "https://xyzdddd.mizhls.ru/lb/premium130/index.m3u8", "https://github.com/tv-logo/tv-logos/blob/main/countries/united-kingdom/sky-sports-premier-league-uk.png?raw=true", 'proxy', daddyHeaders),
|
||||
new Channel('SuperSport Premier League', 'https://xyzdddd.mizhls.ru/lb/premium414/index.m3u8', "https://github.com/tv-logo/tv-logos/blob/8d25ddd79ca2f9cd033b808c45cccd2b3da563ee/countries/south-africa/supersport-premier-league-za.png?raw=true", 'restream', daddyHeaders),
|
||||
//new Channel('TEST', 'https://rr.vipstreams.in/alpha/js/al-taawon-vs-al-qadisiya/1/playlist.m3u8', "https://upload.wikimedia.org/wikipedia/commons/thumb/5/56/Das_Erste-Logo_klein.svg/768px-Das_Erste-Logo_klein.svg.png", 'restream', streamedSuHeaders),
|
||||
];
|
||||
|
||||
|
||||
if (fs.existsSync(storageFilePath)) {
|
||||
try {
|
||||
const data = fs.readFileSync(storageFilePath, 'utf-8');
|
||||
const channelsJson = JSON.parse(data);
|
||||
|
||||
return channelsJson.map(channelJson => Channel.from(channelJson));
|
||||
} catch (err) {
|
||||
console.error('Error loading data from storage:', err);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
this.save(channels);
|
||||
return channels;
|
||||
},
|
||||
|
||||
save(data) {
|
||||
try {
|
||||
fs.writeFile(storageFilePath, JSON.stringify(data, null, 2), { encoding: 'utf-8' }, (err) => err && console.error(err));
|
||||
console.log('Data saved successfully.');
|
||||
} catch (err) {
|
||||
console.error('Error saving data to storage:', err);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ services:
|
||||
dockerfile: Dockerfile
|
||||
volumes:
|
||||
- streams_data:/streams
|
||||
- channels:/channels
|
||||
environment:
|
||||
STORAGE_PATH: /streams/
|
||||
networks:
|
||||
@@ -59,6 +60,7 @@ volumes:
|
||||
driver_opts:
|
||||
type: tmpfs
|
||||
device: tmpfs
|
||||
channels:
|
||||
|
||||
# Internal docker network
|
||||
networks:
|
||||
|
||||
@@ -9,6 +9,7 @@ services:
|
||||
image: ghcr.io/antebrl/iptv-restream/backend:v2.1
|
||||
volumes:
|
||||
- streams_data:/streams
|
||||
- channels:/channels
|
||||
environment:
|
||||
STORAGE_PATH: /streams/
|
||||
networks:
|
||||
@@ -30,6 +31,7 @@ volumes:
|
||||
driver_opts:
|
||||
type: tmpfs
|
||||
device: tmpfs
|
||||
channels:
|
||||
|
||||
# Internal docker network
|
||||
networks:
|
||||
|
||||
@@ -24,6 +24,7 @@ services:
|
||||
dockerfile: Dockerfile
|
||||
volumes:
|
||||
- streams_data:/streams
|
||||
- channels:/channels
|
||||
environment:
|
||||
STORAGE_PATH: /streams/
|
||||
networks:
|
||||
@@ -46,6 +47,7 @@ volumes:
|
||||
driver_opts:
|
||||
type: tmpfs
|
||||
device: tmpfs
|
||||
channels:
|
||||
|
||||
# Internal docker network
|
||||
networks:
|
||||
|
||||
@@ -25,6 +25,7 @@ function VideoPlayer({ channel, syncEnabled }: VideoPlayerProps) {
|
||||
const hls = new Hls({
|
||||
autoStartLoad: syncEnabled ? false : true,
|
||||
liveDurationInfinity: true,
|
||||
//debug: true,
|
||||
manifestLoadPolicy: {
|
||||
default: {
|
||||
maxTimeToFirstByteMs: Infinity,
|
||||
|
||||
Reference in New Issue
Block a user