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('-c, --country <country>', 'Comma-separated list of country codes', '')
.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)
.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, '')

View File

@ -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)

View File

@ -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
}

View File

@ -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

View File

@ -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