Merge branch 'install-iptv-playlist-parser'
This commit is contained in:
commit
40fa21b2dc
|
@ -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++
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
@ -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,8 +29,10 @@ class Playlist {
|
|||
let parts = ['#EXTM3U']
|
||||
for(let key in this.attrs) {
|
||||
let value = this.attrs[key]
|
||||
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) {
|
||||
|
@ -65,40 +70,14 @@ 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
|
||||
|
||||
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) {
|
||||
|
|
|
@ -31,6 +31,15 @@
|
|||
"debug": "=3.1.0"
|
||||
}
|
||||
},
|
||||
"iptv-playlist-parser": {
|
||||
"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"
|
||||
}
|
||||
},
|
||||
"is-buffer": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.3.tgz",
|
||||
|
@ -49,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",
|
||||
|
|
|
@ -11,8 +11,7 @@
|
|||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"axios": ">=0.18.1",
|
||||
"m3u8-file-parser": "^0.2.1",
|
||||
"playlist-parser": "0.0.12",
|
||||
"iptv-playlist-parser": "^0.1.2",
|
||||
"xmldom": "^0.1.27"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue