Installed iptv-playlist-parser

This commit is contained in:
freearhey 2019-10-07 02:45:06 +03:00
parent 3d6d0cee3b
commit d43e58bc26
3 changed files with 18 additions and 46 deletions

View File

@ -26,14 +26,7 @@ async function main() {
const unsortedPlaylist = util.parsePlaylist('channels/unsorted.m3u') const unsortedPlaylist = util.parsePlaylist('channels/unsorted.m3u')
for(const item of unsortedPlaylist.items) { for(const item of unsortedPlaylist.items) {
unsorted[item.url] = util.createChannel({ unsorted[item.url] = util.createChannel(item)
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
})
} }
for(let country of countries) { for(let country of countries) {
@ -55,14 +48,7 @@ async function main() {
} }
let channels = [] let channels = []
for(let item of playlist.items) { for(let item of playlist.items) {
let channel = util.createChannel({ let channel = util.createChannel(item)
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
})
if(util.checkCache(channel.url)) { if(util.checkCache(channel.url)) {
stats.duplicates++ stats.duplicates++

View File

@ -40,20 +40,13 @@ function main() {
const playlist = util.parsePlaylist(country.url) const playlist = util.parsePlaylist(country.url)
const c = { const c = {
name: country.inf.title, name: country.name,
code: util.getBasename(country.url).toUpperCase() code: util.getBasename(country.url).toUpperCase()
} }
for(let item of playlist.items) { for(let item of playlist.items) {
let channel = util.createChannel({ let channel = util.createChannel(item)
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 group = channel.group let group = channel.group

View File

@ -18,7 +18,10 @@ let cache = {}
class Playlist { class Playlist {
constructor(data) { constructor(data) {
this.attrs = data.attrs this.attrs = {
'x-tvg-url': data.tvg.url
}
this.items = data.items this.items = data.items
} }
@ -26,7 +29,9 @@ class Playlist {
let parts = ['#EXTM3U'] let parts = ['#EXTM3U']
for(let key in this.attrs) { for(let key in this.attrs) {
let value = this.attrs[key] let value = this.attrs[key]
parts.push(`${key}="${value}"`) if(value) {
parts.push(`${key}="${value}"`)
}
} }
return `${parts.join(' ')}\n` return `${parts.join(' ')}\n`
@ -35,12 +40,12 @@ class Playlist {
class Channel { class Channel {
constructor(data) { constructor(data) {
this.id = data.id || '' this.id = data.tvg.id
this.name = data.name || '' this.name = data.tvg.name
this.logo = data.logo || '' this.logo = data.tvg.logo
this.group = this._getGroup(data.group) this.group = this._getGroup(data.group.title)
this.url = data.url this.url = data.url
this.title = data.title this.title = data.name
} }
_getGroup(groupTitle) { _getGroup(groupTitle) {
@ -68,23 +73,11 @@ function parsePlaylist(filename) {
const content = readFile(filename) const content = readFile(filename)
const result = parser.parse(content) const result = parser.parse(content)
console.log(result) return new Playlist(result)
return new Playlist({
attrs: results.attrs,
items: results.segments
})
} }
function createChannel(data) { function createChannel(data) {
return new Channel({ return new Channel(data)
id: data.id,
name: data.name,
logo: data.logo,
group: data.group,
url: data.url,
title: data.title
})
} }
async function loadEPG(url) { async function loadEPG(url) {