Update create-database.js
This commit is contained in:
@@ -50,7 +50,7 @@ async function saveToDatabase() {
|
||||
for (const item of chunk) {
|
||||
const stream = store.create()
|
||||
stream.set('id', { id: item.tvg.id })
|
||||
stream.set('display_name', { display_name: item.name })
|
||||
stream.set('title', { title: item.name })
|
||||
stream.set('filepath', { filepath: item.filepath })
|
||||
stream.set('resolution', { title: item.name })
|
||||
stream.set('status', { title: item.name })
|
||||
|
@@ -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
|
||||
|
@@ -2,3 +2,4 @@ exports.is_broken = require('./is_broken')
|
||||
exports.resolution = require('./resolution')
|
||||
exports.status = require('./status')
|
||||
exports.url = require('./url')
|
||||
exports.title = require('./title')
|
||||
|
5
scripts/store/setters/title.js
Normal file
5
scripts/store/setters/title.js
Normal file
@@ -0,0 +1,5 @@
|
||||
const { parser } = require('../../core')
|
||||
|
||||
module.exports = function ({ title }) {
|
||||
return parser.parseChannelName(title)
|
||||
}
|
Reference in New Issue
Block a user