Merge pull request #4099 from iptv-org/update-format-js

Update format.js
This commit is contained in:
Shadix A 2021-08-16 17:30:26 +02:00 committed by GitHub
commit 6c53f5adc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 11 deletions

View File

@ -14,6 +14,7 @@ program
.option('-r, --resolution', 'Detect stream resolution') .option('-r, --resolution', 'Detect stream resolution')
.option('-c, --country <country>', 'Comma-separated list of country codes', '') .option('-c, --country <country>', 'Comma-separated list of country codes', '')
.option('-e, --exclude <exclude>', 'Comma-separated list of country codes to be excluded', '') .option('-e, --exclude <exclude>', 'Comma-separated list of country codes to be excluded', '')
.option('--delay <delay>', 'Set delay for each request', 0)
.option('--timeout <timeout>', 'Set timeout for each request', 5000) .option('--timeout <timeout>', 'Set timeout for each request', 5000)
.parse(process.argv) .parse(process.argv)
@ -61,7 +62,7 @@ async function updatePlaylist(playlist) {
} }
for (const channel of playlist.channels) { for (const channel of playlist.channels) {
addMissingData(channel) addMissingData(channel, playlist)
updateGroupTitle(channel) updateGroupTitle(channel)
normalizeUrl(channel) normalizeUrl(channel)
@ -90,6 +91,8 @@ async function updatePlaylist(playlist) {
.catch(err => { .catch(err => {
if (config.debug) log.print(` ERR: ${channel.url} (${err.message})\n`) if (config.debug) log.print(` ERR: ${channel.url} (${err.message})\n`)
}) })
await utils.sleep(config.delay)
} }
if (!config.debug) bar.tick() 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 // tvg-name
if (!channel.tvg.name && channel.name) { if (!channel.tvg.name && channel.name) {
channel.tvg.name = channel.name.replace(/\"/gi, '') channel.tvg.name = channel.name.replace(/\"/gi, '')

View File

@ -211,10 +211,10 @@ db.playlists = {
return this.list return this.list
}, },
only(list = []) { only(list = []) {
return this.list.filter(playlist => list.includes(playlist.name)) return this.list.filter(playlist => list.includes(playlist.filename))
}, },
except(list = []) { except(list = []) {
return this.list.filter(playlist => !list.includes(playlist.name)) return this.list.filter(playlist => !list.includes(playlist.filename))
}, },
sortBy(fields) { sortBy(fields) {
this.list = utils.sortBy(this.list, fields) this.list = utils.sortBy(this.list, fields)

View File

@ -5,10 +5,6 @@ const fs = require('fs')
const rootPath = path.resolve(__dirname) + '/../../' const rootPath = path.resolve(__dirname) + '/../../'
const file = {} const file = {}
file.getBasename = function (filename) {
return path.basename(filename, path.extname(filename))
}
file.getFilename = function (filename) { file.getFilename = function (filename) {
return path.parse(filename).name return path.parse(filename).name
} }

View File

@ -15,10 +15,13 @@ parser.parseIndex = function () {
parser.parsePlaylist = async function (url) { parser.parsePlaylist = async function (url) {
const content = file.read(url) const content = file.read(url)
const result = playlistParser.parse(content) const result = playlistParser.parse(content)
const name = file.getFilename(url) const filename = file.getFilename(url)
const country = utils.code2name(name) 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 module.exports = parser

View File

@ -90,4 +90,10 @@ utils.filterPlaylists = function (arr, include = '', exclude = '') {
return arr return arr
} }
utils.sleep = function (ms) {
return function (x) {
return new Promise(resolve => setTimeout(() => resolve(x), ms))
}
}
module.exports = utils module.exports = utils