Moved filterPlaylists function to format.js
This commit is contained in:
parent
e93a36cb7f
commit
e9efc5b5f9
@ -4,7 +4,7 @@ const config = {
|
|||||||
debug: process.env.npm_config_debug || false,
|
debug: process.env.npm_config_debug || false,
|
||||||
country: process.env.npm_config_country,
|
country: process.env.npm_config_country,
|
||||||
exclude: process.env.npm_config_exclude,
|
exclude: process.env.npm_config_exclude,
|
||||||
epg: process.env.npm_config_epg || false
|
epg: process.env.npm_config_epg || false,
|
||||||
}
|
}
|
||||||
|
|
||||||
let updated = 0
|
let updated = 0
|
||||||
@ -58,7 +58,7 @@ async function main() {
|
|||||||
|
|
||||||
function parseIndex() {
|
function parseIndex() {
|
||||||
const playlist = helper.parsePlaylist('index.m3u')
|
const playlist = helper.parsePlaylist('index.m3u')
|
||||||
playlist.items = helper.filterPlaylists(playlist.items, config.country, config.exclude)
|
playlist.items = filterPlaylists(playlist.items, config.country, config.exclude)
|
||||||
|
|
||||||
console.log(`Found ${playlist.items.length} playlist(s)`)
|
console.log(`Found ${playlist.items.length} playlist(s)`)
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ function parseIndex() {
|
|||||||
function parsePlaylist(url) {
|
function parsePlaylist(url) {
|
||||||
const playlist = helper.parsePlaylist(url)
|
const playlist = helper.parsePlaylist(url)
|
||||||
|
|
||||||
playlist.items = playlist.items.map(item => {
|
playlist.items = playlist.items.map((item) => {
|
||||||
return helper.createChannel(item)
|
return helper.createChannel(item)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -88,7 +88,7 @@ function sortChannels(playlist) {
|
|||||||
function removeDuplicates(playlist) {
|
function removeDuplicates(playlist) {
|
||||||
let buffer = {}
|
let buffer = {}
|
||||||
const channels = JSON.stringify(playlist.items)
|
const channels = JSON.stringify(playlist.items)
|
||||||
playlist.items = playlist.items.filter(i => {
|
playlist.items = playlist.items.filter((i) => {
|
||||||
let result = typeof buffer[i.url] === 'undefined'
|
let result = typeof buffer[i.url] === 'undefined'
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
@ -165,4 +165,20 @@ function updatePlaylist(filepath, playlist) {
|
|||||||
console.log(`Playlist '${filepath}' has been updated`)
|
console.log(`Playlist '${filepath}' has been updated`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function filterPlaylists(arr, include = '', exclude = '') {
|
||||||
|
if (include) {
|
||||||
|
const included = include.split(',').map((filename) => `channels/${filename}.m3u`)
|
||||||
|
|
||||||
|
return arr.filter((i) => included.indexOf(i.url) > -1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (exclude) {
|
||||||
|
const excluded = exclude.split(',').map((filename) => `channels/${filename}.m3u`)
|
||||||
|
|
||||||
|
return arr.filter((i) => excluded.indexOf(i.url) === -1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return arr
|
||||||
|
}
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
@ -65,7 +65,7 @@ helper.parseEPG = async function (url) {
|
|||||||
|
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
url,
|
url,
|
||||||
channels
|
channels,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,9 +76,9 @@ helper.getEPG = function (url) {
|
|||||||
method: 'get',
|
method: 'get',
|
||||||
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()
|
||||||
@ -99,7 +99,7 @@ helper.getEPG = function (url) {
|
|||||||
reject(e)
|
reject(e)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch((e) => {
|
||||||
reject(e)
|
reject(e)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -129,22 +129,6 @@ helper.getUrlPath = function (u) {
|
|||||||
return path.toLowerCase()
|
return path.toLowerCase()
|
||||||
}
|
}
|
||||||
|
|
||||||
helper.filterPlaylists = function (arr, include = '', exclude = '') {
|
|
||||||
if (include) {
|
|
||||||
const included = include.split(',').map(filename => `channels/${filename}.m3u`)
|
|
||||||
|
|
||||||
return arr.filter(i => included.indexOf(i.url) > -1)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (exclude) {
|
|
||||||
const excluded = exclude.split(',').map(filename => `channels/${filename}.m3u`)
|
|
||||||
|
|
||||||
return arr.filter(i => excluded.indexOf(i.url) === -1)
|
|
||||||
}
|
|
||||||
|
|
||||||
return arr
|
|
||||||
}
|
|
||||||
|
|
||||||
helper.generateTable = function (data, options) {
|
helper.generateTable = function (data, options) {
|
||||||
let output = '<table>\n'
|
let output = '<table>\n'
|
||||||
|
|
||||||
@ -191,7 +175,7 @@ helper.parseMessage = function (err, u) {
|
|||||||
|
|
||||||
if (msgArr.length === 0) return
|
if (msgArr.length === 0) return
|
||||||
|
|
||||||
const line = msgArr.find(line => {
|
const line = msgArr.find((line) => {
|
||||||
return line.indexOf(u) === 0
|
return line.indexOf(u) === 0
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -226,7 +210,7 @@ class Channel {
|
|||||||
this.name = data.tvg.name
|
this.name = data.tvg.name
|
||||||
this.language = data.tvg.language
|
this.language = data.tvg.language
|
||||||
.split(';')
|
.split(';')
|
||||||
.filter(l => !!helper.getISO6391Code(l))
|
.filter((l) => !!helper.getISO6391Code(l))
|
||||||
.join(';')
|
.join(';')
|
||||||
this.logo = data.tvg.logo
|
this.logo = data.tvg.logo
|
||||||
this.group = this._filterGroup(data.group.title)
|
this.group = this._filterGroup(data.group.title)
|
||||||
@ -268,10 +252,10 @@ class Channel {
|
|||||||
'Sport',
|
'Sport',
|
||||||
'Travel',
|
'Travel',
|
||||||
'Weather',
|
'Weather',
|
||||||
'XXX'
|
'XXX',
|
||||||
]
|
]
|
||||||
const groupIndex = supportedCategories
|
const groupIndex = supportedCategories
|
||||||
.map(g => g.toLowerCase())
|
.map((g) => g.toLowerCase())
|
||||||
.indexOf(groupTitle.toLowerCase())
|
.indexOf(groupTitle.toLowerCase())
|
||||||
|
|
||||||
if (groupIndex === -1) {
|
if (groupIndex === -1) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user