From 78de33c8769ccbfe1a1017d8dab80d23d29d4c29 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Fri, 11 Mar 2022 18:30:58 +0300 Subject: [PATCH] Create m3u.js --- scripts/core/m3u.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 scripts/core/m3u.js diff --git a/scripts/core/m3u.js b/scripts/core/m3u.js new file mode 100644 index 0000000000..5b93f22ed7 --- /dev/null +++ b/scripts/core/m3u.js @@ -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