iptv/scripts/helpers/Playlist.js
iptv-bot[bot] 3e2bddab82
[Bot] Update playlists (#4600)
* Update Playlist.js

* Install axios package

* Create epg.js

* Update db.js

* Update format.js

* Update Channel.js

* Update db.js

* Update generate.js

* [Bot] Format playlists

* [Bot] Remove duplicates

* [Bot] Sort channels

* [Bot] Update README.md

* [Bot] Format playlists

* [Bot] Remove duplicates

* [Bot] Sort channels

* [Bot] Update README.md

Co-authored-by: Aleksandr Statciuk <free.arhey@gmail.com>
Co-authored-by: iptv-bot[bot] <84861620+iptv-bot[bot]@users.noreply.github.com>
2021-09-17 13:29:47 +00:00

42 lines
925 B
JavaScript

const Channel = require('./Channel')
const file = require('./file')
module.exports = class Playlist {
constructor({ header, items, url, name, country }) {
this.url = url
this.name = name
this.country = country
this.header = header
this.channels = items.map(item => new Channel(item)).filter(channel => channel.url)
this.updated = false
}
getHeader() {
let header = ['#EXTM3U']
for (let key in this.header.attrs) {
let value = this.header.attrs[key]
if (value) {
header.push(`${key}="${value}"`)
}
}
return header.join(' ')
}
toString(options = {}) {
const config = { raw: false, ...options }
let output = `${this.getHeader()}\n`
for (let channel of this.channels) {
output += channel.toString(config.raw)
}
return output
}
save() {
if (this.updated) {
file.create(this.url, this.toString())
}
}
}