mirror of
https://github.com/iptv-org/iptv.git
synced 2024-09-05 00:01:35 +02:00
Update helper.js
This commit is contained in:
parent
932360a5ac
commit
b16b1e9f57
@ -9,7 +9,6 @@ const escapeStringRegexp = require('escape-string-regexp')
|
|||||||
const markdownInclude = require('markdown-include')
|
const markdownInclude = require('markdown-include')
|
||||||
const iso6393 = require('iso-639-3')
|
const iso6393 = require('iso-639-3')
|
||||||
|
|
||||||
let cache = {}
|
|
||||||
let helper = {}
|
let helper = {}
|
||||||
|
|
||||||
helper.code2flag = function (code) {
|
helper.code2flag = function (code) {
|
||||||
@ -78,16 +77,15 @@ helper.parsePlaylist = function (filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
helper.parseEPG = async function (url) {
|
helper.parseEPG = async function (url) {
|
||||||
const content = await this.getEPG(url)
|
return this.getEPG(url).then(content => {
|
||||||
const result = epgParser.parse(content)
|
const result = epgParser.parse(content)
|
||||||
|
console.log('wo')
|
||||||
const channels = {}
|
const channels = {}
|
||||||
for (let channel of result.channels) {
|
for (let channel of result.channels) {
|
||||||
channels[channel.id] = channel
|
channels[channel.id] = channel
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.resolve({
|
return { url, channels }
|
||||||
url,
|
|
||||||
channels
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,13 +278,15 @@ class Channel {
|
|||||||
this.logo = data.tvg.logo
|
this.logo = data.tvg.logo
|
||||||
this.category = helper.filterGroup(data.group.title)
|
this.category = helper.filterGroup(data.group.title)
|
||||||
this.url = data.url
|
this.url = data.url
|
||||||
this.name = data.name.trim()
|
this.name = this.parseName(data.name)
|
||||||
|
this.status = this.parseStatus(data.name)
|
||||||
this.http = data.http
|
this.http = data.http
|
||||||
this.tvg = data.tvg
|
this.tvg = data.tvg
|
||||||
this.country = {
|
this.country = {
|
||||||
code: null,
|
code: null,
|
||||||
name: null
|
name: null
|
||||||
}
|
}
|
||||||
|
this.resolution = this.parseResolution(data.name)
|
||||||
|
|
||||||
this.setLanguage(data.tvg.language)
|
this.setLanguage(data.tvg.language)
|
||||||
}
|
}
|
||||||
@ -299,6 +299,34 @@ class Channel {
|
|||||||
return this.country.name || null
|
return this.country.name || null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parseName(title) {
|
||||||
|
return title
|
||||||
|
.trim()
|
||||||
|
.split(' ')
|
||||||
|
.map(s => s.trim())
|
||||||
|
.filter(s => {
|
||||||
|
return !/\[|\]/i.test(s) && !/\((\d+)P\)/i.test(s)
|
||||||
|
})
|
||||||
|
.join(' ')
|
||||||
|
}
|
||||||
|
|
||||||
|
parseStatus(title) {
|
||||||
|
const regex = /\[(.*)\]/i
|
||||||
|
const match = title.match(regex)
|
||||||
|
|
||||||
|
return match ? match[1] : null
|
||||||
|
}
|
||||||
|
|
||||||
|
parseResolution(title) {
|
||||||
|
const regex = /\((\d+)P\)/i
|
||||||
|
const match = title.match(regex)
|
||||||
|
|
||||||
|
return {
|
||||||
|
width: null,
|
||||||
|
height: match ? parseInt(match[1]) : null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setLanguage(lang) {
|
setLanguage(lang) {
|
||||||
this.language = lang
|
this.language = lang
|
||||||
.split(';')
|
.split(';')
|
||||||
@ -318,8 +346,10 @@ class Channel {
|
|||||||
const country = this.country.code ? this.country.code.toUpperCase() : ''
|
const country = this.country.code ? this.country.code.toUpperCase() : ''
|
||||||
const tvgUrl = (this.tvg.id || this.tvg.name) && this.tvg.url ? this.tvg.url : ''
|
const tvgUrl = (this.tvg.id || this.tvg.name) && this.tvg.url ? this.tvg.url : ''
|
||||||
const language = this.language.map(l => l.name).join(';')
|
const language = this.language.map(l => l.name).join(';')
|
||||||
|
const resolution = this.resolution.height ? ` (${this.resolution.height}p)` : ''
|
||||||
|
const status = this.status ? ` [${this.status}]` : ''
|
||||||
|
|
||||||
let info = `-1 tvg-id="${this.tvg.id}" tvg-name="${this.tvg.name}" tvg-language="${language}" tvg-logo="${this.logo}" tvg-country="${country}" tvg-url="${tvgUrl}" group-title="${this.category}",${this.name}`
|
let info = `-1 tvg-id="${this.tvg.id}" tvg-name="${this.tvg.name}" tvg-language="${language}" tvg-logo="${this.logo}" tvg-country="${country}" tvg-url="${tvgUrl}" group-title="${this.category}",${this.name}${resolution}${status}`
|
||||||
|
|
||||||
if (this.http['referrer']) {
|
if (this.http['referrer']) {
|
||||||
info += `\n#EXTVLCOPT:http-referrer=${this.http['referrer']}`
|
info += `\n#EXTVLCOPT:http-referrer=${this.http['referrer']}`
|
||||||
@ -334,8 +364,10 @@ class Channel {
|
|||||||
|
|
||||||
toShortString() {
|
toShortString() {
|
||||||
const language = this.language.map(l => l.name).join(';')
|
const language = this.language.map(l => l.name).join(';')
|
||||||
|
const resolution = this.resolution.height ? ` (${this.resolution.height}p)` : ''
|
||||||
|
const status = this.status ? ` [${this.status}]` : ''
|
||||||
|
|
||||||
let info = `-1 tvg-id="${this.tvg.id}" tvg-name="${this.tvg.name}" tvg-language="${language}" tvg-logo="${this.logo}" group-title="${this.category}",${this.name}`
|
let info = `-1 tvg-id="${this.tvg.id}" tvg-name="${this.tvg.name}" tvg-language="${language}" tvg-logo="${this.logo}" group-title="${this.category}",${this.name}${resolution}${status}`
|
||||||
|
|
||||||
if (this.http['referrer']) {
|
if (this.http['referrer']) {
|
||||||
info += `\n#EXTVLCOPT:http-referrer=${this.http['referrer']}`
|
info += `\n#EXTVLCOPT:http-referrer=${this.http['referrer']}`
|
||||||
|
Loading…
Reference in New Issue
Block a user