From 999db200a1446c84f4e557308b4a1bfeaf535a73 Mon Sep 17 00:00:00 2001 From: freearhey Date: Sun, 6 Oct 2019 03:17:36 +0300 Subject: [PATCH 1/5] Added iptv-playlist-parser as dependency --- package-lock.json | 9 +++++++++ package.json | 1 + 2 files changed, 10 insertions(+) diff --git a/package-lock.json b/package-lock.json index c0c250214e..b7f8fcfb7d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31,6 +31,15 @@ "debug": "=3.1.0" } }, + "iptv-playlist-parser": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/iptv-playlist-parser/-/iptv-playlist-parser-0.1.0.tgz", + "integrity": "sha512-YOsAz4lxJZ7125EuY6lGjNAs4jignzRSYURLR/p1GFr5/+bwroPtF1+dHg1QxPcuhZ13KJ2tl6UKhyYnuer/jA==", + "dev": true, + "requires": { + "m3u8-file-parser": "^0.2.1" + } + }, "is-buffer": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.3.tgz", diff --git a/package.json b/package.json index 087d91a377..0757dfae1e 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "dependencies": {}, "devDependencies": { "axios": ">=0.18.1", + "iptv-playlist-parser": "^0.1.0", "m3u8-file-parser": "^0.2.1", "playlist-parser": "0.0.12", "xmldom": "^0.1.27" From 22d6ff080028f7126ec2b1a9b20b9746da2f87c7 Mon Sep 17 00:00:00 2001 From: freearhey Date: Sun, 6 Oct 2019 03:39:27 +0300 Subject: [PATCH 2/5] Upgrade iptv-playlist-parser up to v0.1.2 --- package-lock.json | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index b7f8fcfb7d..b5174de66c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,9 +32,9 @@ } }, "iptv-playlist-parser": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/iptv-playlist-parser/-/iptv-playlist-parser-0.1.0.tgz", - "integrity": "sha512-YOsAz4lxJZ7125EuY6lGjNAs4jignzRSYURLR/p1GFr5/+bwroPtF1+dHg1QxPcuhZ13KJ2tl6UKhyYnuer/jA==", + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/iptv-playlist-parser/-/iptv-playlist-parser-0.1.2.tgz", + "integrity": "sha512-CItFULezZv3o+RANgZDXiVWqEBDtzCXn6YkTBzsWyxnYV/oOyzDsN2xMJ2U/a0CHIXzY3NZ+KNP7+VbcAI2DBQ==", "dev": true, "requires": { "m3u8-file-parser": "^0.2.1" diff --git a/package.json b/package.json index 0757dfae1e..fa0c5e087c 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "dependencies": {}, "devDependencies": { "axios": ">=0.18.1", - "iptv-playlist-parser": "^0.1.0", + "iptv-playlist-parser": "^0.1.2", "m3u8-file-parser": "^0.2.1", "playlist-parser": "0.0.12", "xmldom": "^0.1.27" From de0a5565544c912b28057e55eb51f31525acec29 Mon Sep 17 00:00:00 2001 From: freearhey Date: Sun, 6 Oct 2019 05:12:18 +0300 Subject: [PATCH 3/5] wip --- helpers/util.js | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/helpers/util.js b/helpers/util.js index 2a5754b78e..e8239f1590 100644 --- a/helpers/util.js +++ b/helpers/util.js @@ -1,6 +1,6 @@ const fs = require("fs") const path = require('path') -const M3U8FileParser = require('m3u8-file-parser') +const parser = require('iptv-playlist-parser') const axios = require('axios') const zlib = require("zlib") const DOMParser = require('xmldom').DOMParser @@ -65,24 +65,10 @@ class Channel { } function parsePlaylist(filename) { - const parser = new M3U8FileParser() const content = readFile(filename) - parser.read(content) - let results = parser.getResult() - let contentMatches = content.match(/^.+(?=#|\n|\r)/g) - let head = contentMatches.length ? contentMatches[0] : null - let attrs = {} - if(head) { - const parts = head.split(' ').filter(p => p !== '#EXTM3U').filter(p => p) + const result = parser.parse(content) - for(const attr of parts) { - let attrParts = attr.split('=') - - attrs[attrParts[0]] = attrParts[1].replace(/\"/g, '') - } - } - - results.attrs = attrs + console.log(result) return new Playlist({ attrs: results.attrs, From 3d6d0cee3b70c2df4b3419974fefe0659b0d89d9 Mon Sep 17 00:00:00 2001 From: freearhey Date: Mon, 7 Oct 2019 02:44:42 +0300 Subject: [PATCH 4/5] Removed m3u8-file-parser and playlist-parser --- package-lock.json | 17 ----------------- package.json | 2 -- 2 files changed, 19 deletions(-) diff --git a/package-lock.json b/package-lock.json index b5174de66c..39dc93ac75 100644 --- a/package-lock.json +++ b/package-lock.json @@ -58,23 +58,6 @@ "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", "dev": true }, - "playlist-parser": { - "version": "0.0.12", - "resolved": "https://registry.npmjs.org/playlist-parser/-/playlist-parser-0.0.12.tgz", - "integrity": "sha1-QlDlsRdxrWghOYO/m7bsq2Td9SY=", - "dev": true, - "requires": { - "xmldom": "0.1.16" - }, - "dependencies": { - "xmldom": { - "version": "0.1.16", - "resolved": "https://registry.npmjs.org/xmldom/-/xmldom-0.1.16.tgz", - "integrity": "sha1-zyYCgysatcPmgT/KCP5wGWuhXow=", - "dev": true - } - } - }, "xmldom": { "version": "0.1.27", "resolved": "https://registry.npmjs.org/xmldom/-/xmldom-0.1.27.tgz", diff --git a/package.json b/package.json index fa0c5e087c..d59c02658e 100644 --- a/package.json +++ b/package.json @@ -12,8 +12,6 @@ "devDependencies": { "axios": ">=0.18.1", "iptv-playlist-parser": "^0.1.2", - "m3u8-file-parser": "^0.2.1", - "playlist-parser": "0.0.12", "xmldom": "^0.1.27" } } From d43e58bc2651de8cdfa2c67cfd3c2b6e9a340d6d Mon Sep 17 00:00:00 2001 From: freearhey Date: Mon, 7 Oct 2019 02:45:06 +0300 Subject: [PATCH 5/5] 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) {