diff --git a/scripts/format.js b/scripts/format.js index 22c633d385..e5d5d040fb 100644 --- a/scripts/format.js +++ b/scripts/format.js @@ -14,6 +14,7 @@ program .option('-r, --resolution', 'Detect stream resolution') .option('-c, --country ', 'Comma-separated list of country codes', '') .option('-e, --exclude ', 'Comma-separated list of country codes to be excluded', '') + .option('--delay ', 'Set delay for each request', 0) .option('--timeout ', 'Set timeout for each request', 5000) .parse(process.argv) @@ -61,7 +62,7 @@ async function updatePlaylist(playlist) { } for (const channel of playlist.channels) { - addMissingData(channel) + addMissingData(channel, playlist) updateGroupTitle(channel) normalizeUrl(channel) @@ -90,6 +91,8 @@ async function updatePlaylist(playlist) { .catch(err => { if (config.debug) log.print(` ERR: ${channel.url} (${err.message})\n`) }) + + await utils.sleep(config.delay) } if (!config.debug) bar.tick() } @@ -122,7 +125,8 @@ function updateStatus(channel, status) { } } -function addMissingData(channel) { +function addMissingData(channel, playlist) { + const code = playlist.country.code // tvg-name if (!channel.tvg.name && channel.name) { channel.tvg.name = channel.name.replace(/\"/gi, '') diff --git a/scripts/helpers/db.js b/scripts/helpers/db.js index f94ce678a1..52f5370986 100644 --- a/scripts/helpers/db.js +++ b/scripts/helpers/db.js @@ -211,10 +211,10 @@ db.playlists = { return this.list }, only(list = []) { - return this.list.filter(playlist => list.includes(playlist.name)) + return this.list.filter(playlist => list.includes(playlist.filename)) }, except(list = []) { - return this.list.filter(playlist => !list.includes(playlist.name)) + return this.list.filter(playlist => !list.includes(playlist.filename)) }, sortBy(fields) { this.list = utils.sortBy(this.list, fields) diff --git a/scripts/helpers/file.js b/scripts/helpers/file.js index cb946c3378..578c76a73c 100644 --- a/scripts/helpers/file.js +++ b/scripts/helpers/file.js @@ -5,10 +5,6 @@ const fs = require('fs') const rootPath = path.resolve(__dirname) + '/../../' const file = {} -file.getBasename = function (filename) { - return path.basename(filename, path.extname(filename)) -} - file.getFilename = function (filename) { return path.parse(filename).name } diff --git a/scripts/helpers/parser.js b/scripts/helpers/parser.js index 815c819ec0..98f315c168 100644 --- a/scripts/helpers/parser.js +++ b/scripts/helpers/parser.js @@ -15,10 +15,13 @@ parser.parseIndex = function () { parser.parsePlaylist = async function (url) { const content = file.read(url) const result = playlistParser.parse(content) - const name = file.getFilename(url) - const country = utils.code2name(name) + const filename = file.getFilename(url) + const country = { + code: filename, + name: utils.code2name(filename) + } - return new Playlist({ header: result.header, items: result.items, url, country, name }) + return new Playlist({ header: result.header, items: result.items, url, filename, country }) } module.exports = parser diff --git a/scripts/helpers/utils.js b/scripts/helpers/utils.js index f0d9b3e50d..3866ae4cae 100644 --- a/scripts/helpers/utils.js +++ b/scripts/helpers/utils.js @@ -90,4 +90,10 @@ utils.filterPlaylists = function (arr, include = '', exclude = '') { return arr } +utils.sleep = function (ms) { + return function (x) { + return new Promise(resolve => setTimeout(() => resolve(x), ms)) + } +} + module.exports = utils