[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>
This commit is contained in:
@@ -148,7 +148,7 @@ module.exports = class Channel {
|
||||
countries: this.countries,
|
||||
tvg: {
|
||||
id: this.tvg.id || null,
|
||||
name: this.tvg.name || null,
|
||||
name: this.tvg.name || this.name.replace(/\"/gi, ''),
|
||||
url: this.tvg.url || null
|
||||
}
|
||||
}
|
||||
|
@@ -11,17 +11,21 @@ module.exports = class Playlist {
|
||||
this.updated = false
|
||||
}
|
||||
|
||||
toString(options = {}) {
|
||||
const config = { raw: false, ...options }
|
||||
let parts = ['#EXTM3U']
|
||||
getHeader() {
|
||||
let header = ['#EXTM3U']
|
||||
for (let key in this.header.attrs) {
|
||||
let value = this.header.attrs[key]
|
||||
if (value) {
|
||||
parts.push(`${key}="${value}"`)
|
||||
header.push(`${key}="${value}"`)
|
||||
}
|
||||
}
|
||||
|
||||
let output = `${parts.join(' ')}\n`
|
||||
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)
|
||||
}
|
||||
|
@@ -2,15 +2,21 @@ const categories = require('../data/categories')
|
||||
const parser = require('./parser')
|
||||
const utils = require('./utils')
|
||||
const file = require('./file')
|
||||
const epg = require('./epg')
|
||||
|
||||
const db = {}
|
||||
|
||||
db.load = async function () {
|
||||
let files = await file.list()
|
||||
const files = await file.list()
|
||||
const codes = await epg.codes.load()
|
||||
for (const file of files) {
|
||||
const playlist = await parser.parsePlaylist(file)
|
||||
db.playlists.add(playlist)
|
||||
for (const channel of playlist.channels) {
|
||||
const code = codes.find(ch => ch['tvg_id'] === channel.tvg.id)
|
||||
if (code && Array.isArray(code.guides) && code.guides.length) {
|
||||
channel.tvg.url = code.guides[0]
|
||||
}
|
||||
|
||||
db.channels.add(channel)
|
||||
|
||||
for (const country of channel.countries) {
|
||||
@@ -25,6 +31,8 @@ db.load = async function () {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
db.playlists.add(playlist)
|
||||
}
|
||||
}
|
||||
|
||||
|
12
scripts/helpers/epg.js
Normal file
12
scripts/helpers/epg.js
Normal file
@@ -0,0 +1,12 @@
|
||||
const axios = require('axios')
|
||||
|
||||
module.exports = {
|
||||
codes: {
|
||||
async load() {
|
||||
return await axios
|
||||
.get('https://iptv-org.github.io/epg/codes.json')
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user