Remove epg parser

This commit is contained in:
freearhey 2021-03-06 21:22:23 +03:00
parent b7b01ad92f
commit 80f3518d57
5 changed files with 0 additions and 132 deletions

View file

@ -11,7 +11,6 @@ program
.option('-d, --debug', 'Debug mode')
.option('-c, --country <country>', 'Comma-separated list of country codes', '')
.option('-e, --exclude <exclude>', 'Comma-separated list of country codes to be excluded', '')
.option('--epg', 'Turn on EPG parser')
.option('--resolution', 'Turn on resolution parser')
.option('--delay <delay>', 'Delay between parser requests', 0)
.option('--timeout <timeout>', 'Set timeout for each request', 5000)
@ -39,7 +38,6 @@ async function main() {
.then(filterChannels)
.then(removeDuplicates)
.then(detectResolution)
.then(updateFromEPG)
.then(savePlaylist)
.then(done)
}
@ -161,40 +159,6 @@ function parseResolution(string) {
: undefined
}
async function updateFromEPG(playlist) {
if (!config.epg) return playlist
const tvgUrl = playlist.header.attrs['x-tvg-url']
if (!tvgUrl) return playlist
console.info(` Adding data from '${tvgUrl}'...`)
return utils
.parseEPG(tvgUrl)
.then(epg => {
if (!epg) return playlist
playlist.channels.map(channel => {
if (!channel.tvg.id) return channel
const epgItem = epg.channels[channel.tvg.id]
if (!epgItem) return channel
if (!channel.tvg.name && epgItem.name.length) {
channel.tvg.name = epgItem.name[0].value
}
if (!channel.languages.length && epgItem.name.length && epgItem.name[0].lang) {
channel.languages = utils.parseLanguages(epgItem.name[0].lang)
}
if (!channel.logo && epgItem.icon.length) {
channel.logo = epgItem.icon[0]
}
})
return playlist
})
.catch(err => {
console.log(`Error: EPG could not be loaded`)
})
}
async function removeUnsortedDuplicates(playlist) {
console.info(` Looking for duplicates...`)
const urls = globalBuffer.map(i => i.url.replace(/(^\w+:|^)\/\//, ''))

View file

@ -1,5 +1,4 @@
const playlistParser = require('iptv-playlist-parser')
const epgParser = require('epg-parser')
const utils = require('./utils')
const categories = require('./categories')
const path = require('path')
@ -22,18 +21,6 @@ parser.parsePlaylist = function (filename) {
return new Playlist({ header: result.header, items: result.items, url: filename, country, name })
}
parser.parseEPG = async function (url) {
return utils.loadEPG(url).then(content => {
const result = epgParser.parse(content)
const channels = {}
for (let channel of result.channels) {
channels[channel.id] = channel
}
return { url, channels }
})
}
class Playlist {
constructor({ header, items, url, name, country }) {
this.url = url

View file

@ -94,42 +94,6 @@ utils.sortBy = function (arr, fields) {
})
}
utils.loadEPG = function (url) {
return new Promise((resolve, reject) => {
var buffer = []
axios({
method: 'get',
url: url,
responseType: 'stream',
timeout: 60000
})
.then(res => {
let stream
if (/\.gz$/i.test(url)) {
let gunzip = zlib.createGunzip()
res.data.pipe(gunzip)
stream = gunzip
} else {
stream = res.data
}
stream
.on('data', function (data) {
buffer.push(data.toString())
})
.on('end', function () {
resolve(buffer.join(''))
})
.on('error', function (e) {
reject(e)
})
})
.catch(e => {
reject(e)
})
})
}
utils.getBasename = function (filename) {
return path.basename(filename, path.extname(filename))
}