Update filter.js
This commit is contained in:
		| @@ -1,6 +1,5 @@ | |||||||
| const blacklist = require('./helpers/blacklist.json') | const blacklist = require('./helpers/blacklist.json') | ||||||
| const parser = require('./helpers/parser') | const parser = require('./helpers/parser') | ||||||
| const utils = require('./helpers/utils') |  | ||||||
| const log = require('./helpers/log') | const log = require('./helpers/log') | ||||||
|  |  | ||||||
| async function main() { | async function main() { | ||||||
| @@ -10,7 +9,10 @@ async function main() { | |||||||
|   const playlists = parser.parseIndex() |   const playlists = parser.parseIndex() | ||||||
|   for (const playlist of playlists) { |   for (const playlist of playlists) { | ||||||
|     log.print(`\nProcessing '${playlist.url}'...`) |     log.print(`\nProcessing '${playlist.url}'...`) | ||||||
|     await parser.parsePlaylist(playlist.url).then(removeBlacklisted).then(utils.savePlaylist) |     await parser | ||||||
|  |       .parsePlaylist(playlist.url) | ||||||
|  |       .then(removeBlacklisted) | ||||||
|  |       .then(p => p.save()) | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   log.print('\n') |   log.print('\n') | ||||||
| @@ -19,19 +21,20 @@ async function main() { | |||||||
|  |  | ||||||
| async function removeBlacklisted(playlist) { | async function removeBlacklisted(playlist) { | ||||||
|   const channels = playlist.channels.filter(channel => { |   const channels = playlist.channels.filter(channel => { | ||||||
|     return !blacklist.find(i => { |     return !blacklist.find(item => { | ||||||
|       const channelName = channel.name.toLowerCase() |       const hasSameName = | ||||||
|       return ( |         item.name.toLowerCase() === channel.name.toLowerCase() || | ||||||
|         (i.name.toLowerCase() === channelName || |         item.aliases.map(alias => alias.toLowerCase()).includes(channel.name.toLowerCase()) | ||||||
|           i.aliases.map(i => i.toLowerCase()).includes(channelName)) && |       const fromSameCountry = channel.countries.find(c => c.code === item.country) | ||||||
|         i.country === channel.filename |  | ||||||
|       ) |       return hasSameName && fromSameCountry | ||||||
|     }) |     }) | ||||||
|   }) |   }) | ||||||
|  |  | ||||||
|   if (playlist.channels.length !== channels.length) { |   if (playlist.channels.length !== channels.length) { | ||||||
|     log.print(`updated`) |     log.print(`updated`) | ||||||
|     playlist.channels = channels |     playlist.channels = channels | ||||||
|  |     playlist.updated = true | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   return playlist |   return playlist | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user