Moved filterPlaylists function to format.js
This commit is contained in:
		| @@ -4,7 +4,7 @@ const config = { | ||||
|   debug: process.env.npm_config_debug || false, | ||||
|   country: process.env.npm_config_country, | ||||
|   exclude: process.env.npm_config_exclude, | ||||
|   epg: process.env.npm_config_epg || false | ||||
|   epg: process.env.npm_config_epg || false, | ||||
| } | ||||
|  | ||||
| let updated = 0 | ||||
| @@ -58,7 +58,7 @@ async function main() { | ||||
|  | ||||
| function parseIndex() { | ||||
|   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)`) | ||||
|  | ||||
| @@ -68,7 +68,7 @@ function parseIndex() { | ||||
| function parsePlaylist(url) { | ||||
|   const playlist = helper.parsePlaylist(url) | ||||
|  | ||||
|   playlist.items = playlist.items.map(item => { | ||||
|   playlist.items = playlist.items.map((item) => { | ||||
|     return helper.createChannel(item) | ||||
|   }) | ||||
|  | ||||
| @@ -88,7 +88,7 @@ function sortChannels(playlist) { | ||||
| function removeDuplicates(playlist) { | ||||
|   let buffer = {} | ||||
|   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' | ||||
|  | ||||
|     if (result) { | ||||
| @@ -165,4 +165,20 @@ function updatePlaylist(filepath, playlist) { | ||||
|   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() | ||||
|   | ||||
| @@ -65,7 +65,7 @@ helper.parseEPG = async function (url) { | ||||
|  | ||||
|   return Promise.resolve({ | ||||
|     url, | ||||
|     channels | ||||
|     channels, | ||||
|   }) | ||||
| } | ||||
|  | ||||
| @@ -76,9 +76,9 @@ helper.getEPG = function (url) { | ||||
|       method: 'get', | ||||
|       url: url, | ||||
|       responseType: 'stream', | ||||
|       timeout: 60000 | ||||
|       timeout: 60000, | ||||
|     }) | ||||
|       .then(res => { | ||||
|       .then((res) => { | ||||
|         let stream | ||||
|         if (/\.gz$/i.test(url)) { | ||||
|           let gunzip = zlib.createGunzip() | ||||
| @@ -99,7 +99,7 @@ helper.getEPG = function (url) { | ||||
|             reject(e) | ||||
|           }) | ||||
|       }) | ||||
|       .catch(e => { | ||||
|       .catch((e) => { | ||||
|         reject(e) | ||||
|       }) | ||||
|   }) | ||||
| @@ -129,22 +129,6 @@ helper.getUrlPath = function (u) { | ||||
|   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) { | ||||
|   let output = '<table>\n' | ||||
|  | ||||
| @@ -191,7 +175,7 @@ helper.parseMessage = function (err, u) { | ||||
|  | ||||
|   if (msgArr.length === 0) return | ||||
|  | ||||
|   const line = msgArr.find(line => { | ||||
|   const line = msgArr.find((line) => { | ||||
|     return line.indexOf(u) === 0 | ||||
|   }) | ||||
|  | ||||
| @@ -226,7 +210,7 @@ class Channel { | ||||
|     this.name = data.tvg.name | ||||
|     this.language = data.tvg.language | ||||
|       .split(';') | ||||
|       .filter(l => !!helper.getISO6391Code(l)) | ||||
|       .filter((l) => !!helper.getISO6391Code(l)) | ||||
|       .join(';') | ||||
|     this.logo = data.tvg.logo | ||||
|     this.group = this._filterGroup(data.group.title) | ||||
| @@ -268,10 +252,10 @@ class Channel { | ||||
|       'Sport', | ||||
|       'Travel', | ||||
|       'Weather', | ||||
|       'XXX' | ||||
|       'XXX', | ||||
|     ] | ||||
|     const groupIndex = supportedCategories | ||||
|       .map(g => g.toLowerCase()) | ||||
|       .map((g) => g.toLowerCase()) | ||||
|       .indexOf(groupTitle.toLowerCase()) | ||||
|  | ||||
|     if (groupIndex === -1) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user