mirror of
https://github.com/iptv-org/iptv.git
synced 2025-05-12 01:50:04 -04:00
Update playlist/validate.js
This commit is contained in:
parent
bb8baf348a
commit
bf03dae463
13 changed files with 154 additions and 1378 deletions
|
@ -1,18 +0,0 @@
|
|||
const list = require('../data/blocklist')
|
||||
const parser = require('./parser')
|
||||
|
||||
const blocklist = {}
|
||||
|
||||
blocklist.find = function (title, country) {
|
||||
const name = parser.parseChannelName(title)
|
||||
|
||||
return list.find(item => {
|
||||
const regexp = new RegExp(item.regex, 'i')
|
||||
const hasSameName = regexp.test(name)
|
||||
const fromSameCountry = country === item.country
|
||||
|
||||
return hasSameName && fromSameCountry
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = blocklist
|
|
@ -1,23 +1,19 @@
|
|||
const file = require('./file')
|
||||
const parser = require('./parser')
|
||||
const transliteration = require('transliteration')
|
||||
const { transliterate } = require('transliteration')
|
||||
|
||||
const id = {}
|
||||
|
||||
id.generate = function (title, filepath) {
|
||||
const name = parser.parseChannelName(title)
|
||||
const code = parser.parseCountryCode(filepath)
|
||||
id.generate = function (name, code) {
|
||||
if (!name || !code) return null
|
||||
|
||||
if (name && code) {
|
||||
const slug = transliteration
|
||||
.transliterate(name)
|
||||
.replace(/\+/gi, 'Plus')
|
||||
.replace(/[^a-z\d]+/gi, '')
|
||||
name = name.replace(/ *\([^)]*\) */g, '')
|
||||
name = name.replace(/ *\[[^)]*\] */g, '')
|
||||
name = name.replace(/\+/gi, 'Plus')
|
||||
name = name.replace(/[^a-z\d]+/gi, '')
|
||||
name = name.trim()
|
||||
name = transliterate(name)
|
||||
code = code.toLowerCase()
|
||||
|
||||
return `${slug}.${code.toLowerCase()}`
|
||||
}
|
||||
|
||||
return null
|
||||
return `${name}.${code}`
|
||||
}
|
||||
|
||||
module.exports = id
|
||||
|
|
|
@ -10,4 +10,3 @@ exports.store = require('./store')
|
|||
exports.markdown = require('./markdown')
|
||||
exports.api = require('./api')
|
||||
exports.id = require('./id')
|
||||
exports.blocklist = require('./blocklist')
|
||||
|
|
|
@ -28,23 +28,4 @@ parser.parseNumber = function (string) {
|
|||
return parsed
|
||||
}
|
||||
|
||||
parser.parseChannelName = function (string) {
|
||||
return string
|
||||
.trim()
|
||||
.split(' ')
|
||||
.map(s => s.trim())
|
||||
.filter(s => {
|
||||
return !/\[|\]/i.test(s) && !/\((\d+)P\)/i.test(s)
|
||||
})
|
||||
.join(' ')
|
||||
}
|
||||
|
||||
parser.parseCountryCode = function (filepath) {
|
||||
if (!filepath) return null
|
||||
const basename = file.basename(filepath)
|
||||
const [_, code] = basename.match(/^([a-z]{2})(_|\.)/) || [null, null]
|
||||
|
||||
return code
|
||||
}
|
||||
|
||||
module.exports = parser
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue