mirror of
https://github.com/iptv-org/iptv
synced 2026-05-07 01:57:21 -04:00
Installed epg-parser package
This commit is contained in:
@@ -87,14 +87,16 @@ async function main() {
|
||||
for(let channel of channels) {
|
||||
for(let channelId in buffer[epgUrl].channels) {
|
||||
let c = buffer[epgUrl].channels[channelId]
|
||||
for(let epgName of c.names) {
|
||||
epgName = escapeStringRegexp(epgName)
|
||||
channelTitle = channel.title.replace(/(fhd|hd|sd|高清)$/i, '').trim()
|
||||
let regexp = new RegExp(`^${epgName}$`, 'i')
|
||||
if(regexp.test(channelTitle)) {
|
||||
if(!channel.id) {
|
||||
channel.id = c.id
|
||||
continue
|
||||
for(let epgName of c.name) {
|
||||
if(epgName.value) {
|
||||
let escaped = escapeStringRegexp(epgName.value)
|
||||
channelTitle = channel.title.replace(/(fhd|hd|sd|高清)$/i, '').trim()
|
||||
let regexp = new RegExp(`^${escaped}$`, 'i')
|
||||
if(regexp.test(channelTitle)) {
|
||||
if(!channel.id) {
|
||||
channel.id = c.id
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -111,16 +113,16 @@ async function main() {
|
||||
if(!c) continue
|
||||
let updated = false
|
||||
|
||||
if(!channel.name && c.names[0]) {
|
||||
channel.name = c.names[0]
|
||||
if(!channel.name && c.name.length) {
|
||||
channel.name = c.name[0].value
|
||||
updated = true
|
||||
if(verbose) {
|
||||
console.log(`Added name '${c.names[0]}' to '${channel.id}'`)
|
||||
console.log(`Added name '${c.name[0].value}' to '${channel.id}'`)
|
||||
}
|
||||
}
|
||||
|
||||
if(!channel.logo && c.icon) {
|
||||
const icon = c.icon.split('|')[0]
|
||||
if(!channel.logo && c.icon.length) {
|
||||
const icon = c.icon[0].split('|')[0]
|
||||
channel.logo = icon
|
||||
updated = true
|
||||
if(verbose) {
|
||||
|
||||
@@ -3,7 +3,7 @@ const path = require('path')
|
||||
const parser = require('iptv-playlist-parser')
|
||||
const axios = require('axios')
|
||||
const zlib = require("zlib")
|
||||
const DOMParser = require('xmldom').DOMParser
|
||||
const epgParser = require('epg-parser')
|
||||
const urlParser = require('url')
|
||||
|
||||
const supportedCategories = [ 'Auto','Business', 'Classic','Comedy','Documentary','Education','Entertainment', 'Family','Fashion','Food', 'General', 'Health', 'History', 'Hobby', 'Kids', 'Legislative','Lifestyle','Local', 'Movies', 'Music', 'News', 'Quiz', 'Religious','Sci-Fi', 'Shop', 'Sport', 'Travel', 'Weather', 'XXX' ]
|
||||
@@ -78,38 +78,20 @@ function createChannel(data) {
|
||||
}
|
||||
|
||||
async function loadEPG(url) {
|
||||
const data = await getGzipped(url)
|
||||
const doc = new DOMParser().parseFromString(data, 'text/xml')
|
||||
const channelElements = doc.getElementsByTagName('channel')
|
||||
let channels = {}
|
||||
for(let i = 0; i < channelElements.length; i++) {
|
||||
let channel = {}
|
||||
let channelElement = channelElements[i]
|
||||
channel.id = channelElement.getAttribute('id')
|
||||
channel.names = []
|
||||
for(let nameElement of Object.values(channelElement.getElementsByTagName('display-name'))) {
|
||||
if(nameElement.firstChild) {
|
||||
channel.names.push(nameElement.firstChild.nodeValue)
|
||||
}
|
||||
}
|
||||
channel.names = channel.names.filter(n => n)
|
||||
const iconElements = channelElement.getElementsByTagName('icon')
|
||||
if(iconElements.length) {
|
||||
channel.icon = iconElements[0].getAttribute('src')
|
||||
}
|
||||
|
||||
const content = await getEPGFile(url)
|
||||
const result = epgParser.parse(content)
|
||||
const channels = {}
|
||||
for(let channel of result.channels) {
|
||||
channels[channel.id] = channel
|
||||
}
|
||||
|
||||
return Promise.resolve({
|
||||
url,
|
||||
channels
|
||||
channels
|
||||
})
|
||||
}
|
||||
|
||||
function getGzipped(url) {
|
||||
const supportedTypes = ['application/x-gzip', 'application/octet-stream']
|
||||
|
||||
function getEPGFile(url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
var buffer = []
|
||||
axios({
|
||||
@@ -118,7 +100,7 @@ function getGzipped(url) {
|
||||
responseType:'stream'
|
||||
}).then(res => {
|
||||
let stream
|
||||
if(supportedTypes.indexOf(res.headers['content-type']) > -1) {
|
||||
if(/\.gz$/i.test(url)) {
|
||||
let gunzip = zlib.createGunzip()
|
||||
res.data.pipe(gunzip)
|
||||
stream = gunzip
|
||||
|
||||
Reference in New Issue
Block a user