mirror of
https://github.com/iptv-org/iptv.git
synced 2025-05-12 18:10:04 -04:00
Create cid.js
This commit is contained in:
parent
a367e92bcf
commit
32b86ce842
1 changed files with 41 additions and 0 deletions
41
scripts/core/cid.js
Normal file
41
scripts/core/cid.js
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
const file = require('./file')
|
||||||
|
const transliteration = require('transliteration')
|
||||||
|
|
||||||
|
const cid = {}
|
||||||
|
|
||||||
|
cid.generate = function (title, filepath) {
|
||||||
|
const name = parseChannelName(title)
|
||||||
|
const code = parseCountryCode(filepath)
|
||||||
|
|
||||||
|
if (name && code) {
|
||||||
|
const slug = transliteration
|
||||||
|
.transliterate(name)
|
||||||
|
.replace(/\+/gi, 'Plus')
|
||||||
|
.replace(/[^a-z\d]+/gi, '')
|
||||||
|
|
||||||
|
return `${slug}.${code.toLowerCase()}`
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = cid
|
||||||
|
|
||||||
|
function parseCountryCode(filepath) {
|
||||||
|
if (!filepath) return null
|
||||||
|
const basename = file.basename(filepath)
|
||||||
|
const [code] = basename.split('_') || [null]
|
||||||
|
|
||||||
|
return code
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseChannelName(title) {
|
||||||
|
return title
|
||||||
|
.trim()
|
||||||
|
.split(' ')
|
||||||
|
.map(s => s.trim())
|
||||||
|
.filter(s => {
|
||||||
|
return !/\[|\]/i.test(s) && !/\((\d+)P\)/i.test(s)
|
||||||
|
})
|
||||||
|
.join(' ')
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue