Merge pull request #432 from iptv-org/update-create-database.js

Update create-database.js
This commit is contained in:
Aleksandr Statciuk 2022-01-20 23:22:15 +03:00 committed by GitHub
commit 731807028c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 44 additions and 41 deletions

14
package-lock.json generated
View file

@ -12,7 +12,7 @@
"commander": "^8.2.0",
"csv-parser": "^3.0.0",
"dayjs": "^1.10.4",
"epg-grabber": "^0.17.1",
"epg-grabber": "^0.18.0",
"epg-parser": "^0.1.6",
"form-data": "^4.0.0",
"glob": "^7.2.0",
@ -2007,9 +2007,9 @@
}
},
"node_modules/epg-grabber": {
"version": "0.17.1",
"resolved": "https://registry.npmjs.org/epg-grabber/-/epg-grabber-0.17.1.tgz",
"integrity": "sha512-Nxt7dBv6lFdPkAmkan5fvSxDFIesopuQbftqKxUORRASro7A4pNV1qwUekKYujQZa0D/XhpqCtmIFXIHiVS7hQ==",
"version": "0.18.0",
"resolved": "https://registry.npmjs.org/epg-grabber/-/epg-grabber-0.18.0.tgz",
"integrity": "sha512-E+aKgjlMxAjGN3YdrJmP57l/NEffGlfi/mb8uy71jqnkcpB9bOpFKae7zM2G5a5v3Lpk7E8L618qkjeI3jCu1g==",
"dependencies": {
"axios": "^0.21.1",
"axios-cookiejar-support": "^1.0.1",
@ -6426,9 +6426,9 @@
"integrity": "sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A=="
},
"epg-grabber": {
"version": "0.17.1",
"resolved": "https://registry.npmjs.org/epg-grabber/-/epg-grabber-0.17.1.tgz",
"integrity": "sha512-Nxt7dBv6lFdPkAmkan5fvSxDFIesopuQbftqKxUORRASro7A4pNV1qwUekKYujQZa0D/XhpqCtmIFXIHiVS7hQ==",
"version": "0.18.0",
"resolved": "https://registry.npmjs.org/epg-grabber/-/epg-grabber-0.18.0.tgz",
"integrity": "sha512-E+aKgjlMxAjGN3YdrJmP57l/NEffGlfi/mb8uy71jqnkcpB9bOpFKae7zM2G5a5v3Lpk7E8L618qkjeI3jCu1g==",
"requires": {
"axios": "^0.21.1",
"axios-cookiejar-support": "^1.0.1",

View file

@ -3,7 +3,9 @@
"scripts": {
"update-codes": "node scripts/update-codes.js",
"act": "act workflow_dispatch -W .github/workflows/auto-update.yml --artifact-server-path ./.artifacts",
"test": "npx jest --runInBand"
"test": "npx jest --runInBand",
"test:commands": "npx jest --runInBand -- commands",
"test:sites": "npx jest --runInBand -- sites"
},
"private": true,
"author": "Arhey",
@ -17,7 +19,7 @@
"commander": "^8.2.0",
"csv-parser": "^3.0.0",
"dayjs": "^1.10.4",
"epg-grabber": "^0.17.1",
"epg-grabber": "^0.18.0",
"epg-parser": "^0.1.6",
"form-data": "^4.0.0",
"glob": "^7.2.0",

View file

@ -34,13 +34,18 @@ async function loadChannels() {
for (const filepath of files) {
const dir = file.dirname(filepath)
const filename = file.basename(filepath)
const [_, gid] = filename.match(/_([a-z-]+)\.channels\.xml/i) || [null, null]
const [_, site] = filename.match(/([a-z0-9-.]+)_/i) || [null, null]
if (!site) continue
const configPath = `${dir}/${site}.config.js`
const config = require(file.resolve(configPath))
if (config.ignore) continue
const [__, gid] = filename.match(/_([a-z-]+)\.channels\.xml/i) || [null, null]
const items = await parser.parseChannels(filepath)
for (const item of items) {
const countryCode = item.xmltv_id.split('.')[1]
item.country = countryCode ? countryCode.toUpperCase() : null
item.channelsPath = filepath
item.configPath = `${dir}/${item.site}.config.js`
item.configPath = configPath
item.gid = gid
channels.push(item)
}

View file

@ -0,0 +1,10 @@
module.exports = {
site: 'ignore.com',
ignore: true,
url() {
return `https://ignore.com`
},
parser() {
return []
}
}

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<site site="example.com">
<site site="ignore.com">
<channels>
<channel lang="en" xmltv_id="1Plus2.lv" site_id="1341">1+2</channel>
</channels>

View file

@ -6,7 +6,7 @@ beforeEach(() => {
fs.rmdirSync('tests/__data__/output', { recursive: true })
fs.mkdirSync('tests/__data__/output')
execSync(
const stdout = execSync(
'DB_DIR=tests/__data__/output/database node scripts/commands/create-database.js --channels=tests/__data__/input/sites/*.channels.xml --max-clusters=1',
{ encoding: 'utf8' }
)
@ -15,34 +15,20 @@ beforeEach(() => {
it('can create channels database', () => {
const output = content('tests/__data__/output/database/channels.db')
expect(output).toEqual(
expect.arrayContaining([
expect.objectContaining({
lang: 'en',
country: 'LV',
xmltv_id: '1Plus2.lv',
site_id: '1341',
name: '1+2',
site: 'example.com',
channelsPath: 'tests/__data__/input/sites/example.com_en-ee.channels.xml',
configPath: 'tests/__data__/input/sites/example.com.config.js',
gid: 'en-ee',
cluster_id: 1
}),
expect.objectContaining({
lang: 'ru',
country: 'US',
xmltv_id: 'CNNInternationalEurope.us',
site_id: '140',
name: 'CNN International Europe',
site: 'example.com',
channelsPath: 'tests/__data__/input/sites/example.com_ca-nl.channels.xml',
configPath: 'tests/__data__/input/sites/example.com.config.js',
gid: 'ca-nl',
cluster_id: 1
})
])
)
expect(output).toMatchObject([
{
lang: 'ru',
country: 'US',
xmltv_id: 'CNNInternationalEurope.us',
site_id: '140',
name: 'CNN International Europe',
site: 'example.com',
channelsPath: 'tests/__data__/input/sites/example.com_ca-nl.channels.xml',
configPath: 'tests/__data__/input/sites/example.com.config.js',
gid: 'ca-nl',
cluster_id: 1
}
])
})
function content(filepath) {