Skip to content

Commit

Permalink
Adds M3U playlist download (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tereius authored Dec 17, 2020
1 parent 5e48b1f commit 5545b5a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/providers/m3u.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import stationProvider from './station';

class M3UProvider {
public generateM3U(hostname: string) {

let m3uString = '#EXTM3U' + '\n';
let chNum = 1;

const stations = stationProvider.stations;
for (const station of stations) {
m3uString += '#EXTINF:-1';
m3uString += ` tvg-chno="${chNum}" tvg-name="${station.title}" tvg-logo="${station.image}" group-title="IPTV"`;
m3uString += ',' + station.title + '\n';
m3uString += `${hostname}/live/${station.mcast_source}@${station.mcast_group}:${station.mcast_port}` + '\n';
chNum++
}
return m3uString;
}
}
export default new M3UProvider();
13 changes: 12 additions & 1 deletion src/routes/station.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Router, Request, Response } from 'express';
import stationProvider from '../providers/station';
import xspfProvider from '../providers/xspf';
import m3uProvider from '../providers/m3u';
import config from '../providers/config';

const router = Router();
Expand All @@ -24,4 +25,14 @@ router.get('/download', (req: Request, res: Response) => {
res.end();
});

export default router;
router.get('/downloadm3u', (req: Request, res: Response) => {
res.setHeader('Content-Type', 'application/x-mpegURL');
res.setHeader('Content-Disposition', 'attachment; filename="IPTV-ReStream.m3u"');
const protocol = config['xspf_protocol'] || req.protocol;
const host = config.xspf_host || req.get('X-Forwarded-Host') || req.get('Host');
const pathPrefix = config.xspf_pathPrefix;
res.write(m3uProvider.generateM3U(`${protocol}://${host}${pathPrefix}`));
res.end();
});

export default router;
2 changes: 2 additions & 0 deletions views/stations.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<div class="subMenu">
<i data-feather="download"></i>
<a class="menulink" href="stations/download">Download VLC Playlist</a>
<i data-feather="download"></i>
<a class="menulink" href="stations/downloadm3u">Download M3U Playlist</a>
</div>
<br>
<table class="table text-center">
Expand Down

0 comments on commit 5545b5a

Please sign in to comment.