Make code prettier

This commit is contained in:
freearhey 2020-04-11 04:33:53 +03:00
parent 71ba959695
commit d9bef97c88
1 changed files with 103 additions and 62 deletions

View File

@ -1,8 +1,8 @@
const fs = require("fs")
const fs = require('fs')
const path = require('path')
const playlistParser = require('iptv-playlist-parser')
const axios = require('axios')
const zlib = require("zlib")
const zlib = require('zlib')
const epgParser = require('epg-parser')
const urlParser = require('url')
const ISO6391 = require('iso-639-1')
@ -15,8 +15,12 @@ let helper = {}
helper.sortBy = function (arr, fields) {
return arr.sort((a, b) => {
for (let field of fields) {
if(a[field].toLowerCase() < b[field].toLowerCase()) { return -1 }
if(a[field].toLowerCase() > b[field].toLowerCase()) { return 1 }
if (a[field].toLowerCase() < b[field].toLowerCase()) {
return -1
}
if (a[field].toLowerCase() > b[field].toLowerCase()) {
return 1
}
}
return 0
})
@ -73,7 +77,8 @@ helper.getEPG = function(url) {
url: url,
responseType: 'stream',
timeout: 60000
}).then(res => {
})
.then(res => {
let stream
if (/\.gz$/i.test(url)) {
let gunzip = zlib.createGunzip()
@ -83,21 +88,25 @@ helper.getEPG = function(url) {
stream = res.data
}
stream.on('data', function(data) {
stream
.on('data', function (data) {
buffer.push(data.toString())
}).on("end", function() {
resolve(buffer.join(""))
}).on("error", function(e) {
})
.on('end', function () {
resolve(buffer.join(''))
})
.on('error', function (e) {
reject(e)
})
}).catch(e => {
})
.catch(e => {
reject(e)
})
})
}
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) {
@ -233,8 +242,40 @@ class Channel {
_filterGroup(groupTitle) {
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 groupIndex = supportedCategories.map(g => g.toLowerCase()).indexOf(groupTitle.toLowerCase())
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 groupIndex = supportedCategories
.map(g => g.toLowerCase())
.indexOf(groupTitle.toLowerCase())
if (groupIndex === -1) {
groupTitle = ''
@ -255,7 +296,7 @@ class Channel {
toString() {
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}`
return '#EXTINF:' + info + '\n' + this.url + '\n'