mirror of
https://github.com/iptv-org/iptv.git
synced 2025-05-12 01:50:04 -04:00
Create m3u.js
This commit is contained in:
parent
2420f7ba6b
commit
78de33c876
1 changed files with 34 additions and 0 deletions
34
scripts/core/m3u.js
Normal file
34
scripts/core/m3u.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
const m3u = {}
|
||||
|
||||
m3u.create = function (links = [], header = {}) {
|
||||
let output = `#EXTM3U`
|
||||
for (const attr in header) {
|
||||
const value = header[attr]
|
||||
output += ` ${attr}="${value}"`
|
||||
}
|
||||
output += `\n`
|
||||
|
||||
for (const link of links) {
|
||||
output += `#EXTINF:-1`
|
||||
for (const name in link.attrs) {
|
||||
const value = link.attrs[name]
|
||||
if (value !== undefined) {
|
||||
output += ` ${name}="${value}"`
|
||||
}
|
||||
}
|
||||
output += `,${link.title}\n`
|
||||
|
||||
for (const name in link.vlcOpts) {
|
||||
const value = link.vlcOpts[name]
|
||||
if (value !== undefined) {
|
||||
output += `#EXTVLCOPT:${name}=${value}\n`
|
||||
}
|
||||
}
|
||||
|
||||
output += `${link.url}\n`
|
||||
}
|
||||
|
||||
return output
|
||||
}
|
||||
|
||||
module.exports = m3u
|
Loading…
Add table
Add a link
Reference in a new issue