From d43e58bc2651de8cdfa2c67cfd3c2b6e9a340d6d Mon Sep 17 00:00:00 2001 From: freearhey Date: Mon, 7 Oct 2019 02:45:06 +0300 Subject: [PATCH] Installed iptv-playlist-parser --- helpers/format.js | 18 ++---------------- helpers/generate.js | 11 ++--------- helpers/util.js | 35 ++++++++++++++--------------------- 3 files changed, 18 insertions(+), 46 deletions(-) diff --git a/helpers/format.js b/helpers/format.js index d289d4ba41..1f1b535464 100644 --- a/helpers/format.js +++ b/helpers/format.js @@ -26,14 +26,7 @@ async function main() { const unsortedPlaylist = util.parsePlaylist('channels/unsorted.m3u') for(const item of unsortedPlaylist.items) { - unsorted[item.url] = util.createChannel({ - id: item.inf['tvg-id'], - name: item.inf['tvg-name'], - logo: item.inf['tvg-logo'], - group: item.inf['group-title'], - url: item.url, - title: item.inf.title - }) + unsorted[item.url] = util.createChannel(item) } for(let country of countries) { @@ -55,14 +48,7 @@ async function main() { } let channels = [] for(let item of playlist.items) { - let channel = util.createChannel({ - id: item.inf['tvg-id'], - name: item.inf['tvg-name'], - logo: item.inf['tvg-logo'], - group: item.inf['group-title'], - url: item.url, - title: item.inf.title - }) + let channel = util.createChannel(item) if(util.checkCache(channel.url)) { stats.duplicates++ diff --git a/helpers/generate.js b/helpers/generate.js index 7a10996ab5..cbcd3d6459 100644 --- a/helpers/generate.js +++ b/helpers/generate.js @@ -40,20 +40,13 @@ function main() { const playlist = util.parsePlaylist(country.url) const c = { - name: country.inf.title, + name: country.name, code: util.getBasename(country.url).toUpperCase() } for(let item of playlist.items) { - let channel = util.createChannel({ - id: item.inf['tvg-id'], - name: item.inf['tvg-name'], - logo: item.inf['tvg-logo'], - group: item.inf['group-title'], - url: item.url, - title: item.inf.title - }) + let channel = util.createChannel(item) let group = channel.group diff --git a/helpers/util.js b/helpers/util.js index e8239f1590..bd24081357 100644 --- a/helpers/util.js +++ b/helpers/util.js @@ -18,7 +18,10 @@ let cache = {} class Playlist { constructor(data) { - this.attrs = data.attrs + this.attrs = { + 'x-tvg-url': data.tvg.url + } + this.items = data.items } @@ -26,7 +29,9 @@ class Playlist { let parts = ['#EXTM3U'] for(let key in this.attrs) { let value = this.attrs[key] - parts.push(`${key}="${value}"`) + if(value) { + parts.push(`${key}="${value}"`) + } } return `${parts.join(' ')}\n` @@ -35,12 +40,12 @@ class Playlist { class Channel { constructor(data) { - this.id = data.id || '' - this.name = data.name || '' - this.logo = data.logo || '' - this.group = this._getGroup(data.group) + this.id = data.tvg.id + this.name = data.tvg.name + this.logo = data.tvg.logo + this.group = this._getGroup(data.group.title) this.url = data.url - this.title = data.title + this.title = data.name } _getGroup(groupTitle) { @@ -68,23 +73,11 @@ function parsePlaylist(filename) { const content = readFile(filename) const result = parser.parse(content) - console.log(result) - - return new Playlist({ - attrs: results.attrs, - items: results.segments - }) + return new Playlist(result) } function createChannel(data) { - return new Channel({ - id: data.id, - name: data.name, - logo: data.logo, - group: data.group, - url: data.url, - title: data.title - }) + return new Channel(data) } async function loadEPG(url) {