Make code prettier
This commit is contained in:
parent
71ba959695
commit
d9bef97c88
|
@ -1,8 +1,8 @@
|
||||||
const fs = require("fs")
|
const fs = require('fs')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const playlistParser = require('iptv-playlist-parser')
|
const playlistParser = require('iptv-playlist-parser')
|
||||||
const axios = require('axios')
|
const axios = require('axios')
|
||||||
const zlib = require("zlib")
|
const zlib = require('zlib')
|
||||||
const epgParser = require('epg-parser')
|
const epgParser = require('epg-parser')
|
||||||
const urlParser = require('url')
|
const urlParser = require('url')
|
||||||
const ISO6391 = require('iso-639-1')
|
const ISO6391 = require('iso-639-1')
|
||||||
|
@ -15,8 +15,12 @@ let helper = {}
|
||||||
helper.sortBy = function (arr, fields) {
|
helper.sortBy = function (arr, fields) {
|
||||||
return arr.sort((a, b) => {
|
return arr.sort((a, b) => {
|
||||||
for (let field of fields) {
|
for (let field of fields) {
|
||||||
if(a[field].toLowerCase() < b[field].toLowerCase()) { return -1 }
|
if (a[field].toLowerCase() < b[field].toLowerCase()) {
|
||||||
if(a[field].toLowerCase() > b[field].toLowerCase()) { return 1 }
|
return -1
|
||||||
|
}
|
||||||
|
if (a[field].toLowerCase() > b[field].toLowerCase()) {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
})
|
})
|
||||||
|
@ -73,7 +77,8 @@ helper.getEPG = function(url) {
|
||||||
url: url,
|
url: url,
|
||||||
responseType: 'stream',
|
responseType: 'stream',
|
||||||
timeout: 60000
|
timeout: 60000
|
||||||
}).then(res => {
|
})
|
||||||
|
.then(res => {
|
||||||
let stream
|
let stream
|
||||||
if (/\.gz$/i.test(url)) {
|
if (/\.gz$/i.test(url)) {
|
||||||
let gunzip = zlib.createGunzip()
|
let gunzip = zlib.createGunzip()
|
||||||
|
@ -83,21 +88,25 @@ helper.getEPG = function(url) {
|
||||||
stream = res.data
|
stream = res.data
|
||||||
}
|
}
|
||||||
|
|
||||||
stream.on('data', function(data) {
|
stream
|
||||||
|
.on('data', function (data) {
|
||||||
buffer.push(data.toString())
|
buffer.push(data.toString())
|
||||||
}).on("end", function() {
|
})
|
||||||
resolve(buffer.join(""))
|
.on('end', function () {
|
||||||
}).on("error", function(e) {
|
resolve(buffer.join(''))
|
||||||
|
})
|
||||||
|
.on('error', function (e) {
|
||||||
reject(e)
|
reject(e)
|
||||||
})
|
})
|
||||||
}).catch(e => {
|
})
|
||||||
|
.catch(e => {
|
||||||
reject(e)
|
reject(e)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
helper.readFile = function (filename) {
|
helper.readFile = function (filename) {
|
||||||
return fs.readFileSync(path.resolve(__dirname) + `/../${filename}`, { encoding: "utf8" })
|
return fs.readFileSync(path.resolve(__dirname) + `/../${filename}`, { encoding: 'utf8' })
|
||||||
}
|
}
|
||||||
|
|
||||||
helper.appendToFile = function (filename, data) {
|
helper.appendToFile = function (filename, data) {
|
||||||
|
@ -233,8 +242,40 @@ class Channel {
|
||||||
_filterGroup(groupTitle) {
|
_filterGroup(groupTitle) {
|
||||||
if (!groupTitle) return ''
|
if (!groupTitle) return ''
|
||||||
|
|
||||||
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' ]
|
const supportedCategories = [
|
||||||
const groupIndex = supportedCategories.map(g => g.toLowerCase()).indexOf(groupTitle.toLowerCase())
|
'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'
|
||||||
|
]
|
||||||
|
const groupIndex = supportedCategories
|
||||||
|
.map(g => g.toLowerCase())
|
||||||
|
.indexOf(groupTitle.toLowerCase())
|
||||||
|
|
||||||
if (groupIndex === -1) {
|
if (groupIndex === -1) {
|
||||||
groupTitle = ''
|
groupTitle = ''
|
||||||
|
@ -255,7 +296,7 @@ class Channel {
|
||||||
|
|
||||||
toString() {
|
toString() {
|
||||||
const country = this.countryCode.toUpperCase()
|
const country = this.countryCode.toUpperCase()
|
||||||
const epg = (this.id && this.epg) ? this.epg : ''
|
const epg = this.id && this.epg ? this.epg : ''
|
||||||
const info = `-1 tvg-id="${this.id}" tvg-name="${this.name}" tvg-language="${this.language}" tvg-logo="${this.logo}" tvg-country="${country}" tvg-url="${epg}" group-title="${this.group}",${this.title}`
|
const info = `-1 tvg-id="${this.id}" tvg-name="${this.name}" tvg-language="${this.language}" tvg-logo="${this.logo}" tvg-country="${country}" tvg-url="${epg}" group-title="${this.group}",${this.title}`
|
||||||
|
|
||||||
return '#EXTINF:' + info + '\n' + this.url + '\n'
|
return '#EXTINF:' + info + '\n' + this.url + '\n'
|
||||||
|
|
Loading…
Reference in New Issue