mirror of
https://github.com/iptv-org/iptv.git
synced 2025-05-12 01:50:04 -04:00
Update create-database.js
This commit is contained in:
parent
fa4bad3dca
commit
46deb7f004
8 changed files with 34 additions and 27 deletions
|
@ -1,11 +1,12 @@
|
|||
const file = require('./file')
|
||||
const parser = require('./parser')
|
||||
const transliteration = require('transliteration')
|
||||
|
||||
const cid = {}
|
||||
|
||||
cid.generate = function (title, filepath) {
|
||||
const name = parseChannelName(title)
|
||||
const code = parseCountryCode(filepath)
|
||||
const name = parser.parseChannelName(title)
|
||||
const code = parser.parseCountryCode(filepath)
|
||||
|
||||
if (name && code) {
|
||||
const slug = transliteration
|
||||
|
@ -20,22 +21,3 @@ cid.generate = function (title, filepath) {
|
|||
}
|
||||
|
||||
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(' ')
|
||||
}
|
||||
|
|
|
@ -28,4 +28,23 @@ 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.split('_') || [null]
|
||||
|
||||
return code
|
||||
}
|
||||
|
||||
module.exports = parser
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue