mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 09:00:07 -04:00
Merge pull request #432 from iptv-org/update-create-database.js
Update create-database.js
This commit is contained in:
commit
731807028c
6 changed files with 44 additions and 41 deletions
14
package-lock.json
generated
14
package-lock.json
generated
|
@ -12,7 +12,7 @@
|
||||||
"commander": "^8.2.0",
|
"commander": "^8.2.0",
|
||||||
"csv-parser": "^3.0.0",
|
"csv-parser": "^3.0.0",
|
||||||
"dayjs": "^1.10.4",
|
"dayjs": "^1.10.4",
|
||||||
"epg-grabber": "^0.17.1",
|
"epg-grabber": "^0.18.0",
|
||||||
"epg-parser": "^0.1.6",
|
"epg-parser": "^0.1.6",
|
||||||
"form-data": "^4.0.0",
|
"form-data": "^4.0.0",
|
||||||
"glob": "^7.2.0",
|
"glob": "^7.2.0",
|
||||||
|
@ -2007,9 +2007,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/epg-grabber": {
|
"node_modules/epg-grabber": {
|
||||||
"version": "0.17.1",
|
"version": "0.18.0",
|
||||||
"resolved": "https://registry.npmjs.org/epg-grabber/-/epg-grabber-0.17.1.tgz",
|
"resolved": "https://registry.npmjs.org/epg-grabber/-/epg-grabber-0.18.0.tgz",
|
||||||
"integrity": "sha512-Nxt7dBv6lFdPkAmkan5fvSxDFIesopuQbftqKxUORRASro7A4pNV1qwUekKYujQZa0D/XhpqCtmIFXIHiVS7hQ==",
|
"integrity": "sha512-E+aKgjlMxAjGN3YdrJmP57l/NEffGlfi/mb8uy71jqnkcpB9bOpFKae7zM2G5a5v3Lpk7E8L618qkjeI3jCu1g==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^0.21.1",
|
"axios": "^0.21.1",
|
||||||
"axios-cookiejar-support": "^1.0.1",
|
"axios-cookiejar-support": "^1.0.1",
|
||||||
|
@ -6426,9 +6426,9 @@
|
||||||
"integrity": "sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A=="
|
"integrity": "sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A=="
|
||||||
},
|
},
|
||||||
"epg-grabber": {
|
"epg-grabber": {
|
||||||
"version": "0.17.1",
|
"version": "0.18.0",
|
||||||
"resolved": "https://registry.npmjs.org/epg-grabber/-/epg-grabber-0.17.1.tgz",
|
"resolved": "https://registry.npmjs.org/epg-grabber/-/epg-grabber-0.18.0.tgz",
|
||||||
"integrity": "sha512-Nxt7dBv6lFdPkAmkan5fvSxDFIesopuQbftqKxUORRASro7A4pNV1qwUekKYujQZa0D/XhpqCtmIFXIHiVS7hQ==",
|
"integrity": "sha512-E+aKgjlMxAjGN3YdrJmP57l/NEffGlfi/mb8uy71jqnkcpB9bOpFKae7zM2G5a5v3Lpk7E8L618qkjeI3jCu1g==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"axios": "^0.21.1",
|
"axios": "^0.21.1",
|
||||||
"axios-cookiejar-support": "^1.0.1",
|
"axios-cookiejar-support": "^1.0.1",
|
||||||
|
|
|
@ -3,7 +3,9 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"update-codes": "node scripts/update-codes.js",
|
"update-codes": "node scripts/update-codes.js",
|
||||||
"act": "act workflow_dispatch -W .github/workflows/auto-update.yml --artifact-server-path ./.artifacts",
|
"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,
|
"private": true,
|
||||||
"author": "Arhey",
|
"author": "Arhey",
|
||||||
|
@ -17,7 +19,7 @@
|
||||||
"commander": "^8.2.0",
|
"commander": "^8.2.0",
|
||||||
"csv-parser": "^3.0.0",
|
"csv-parser": "^3.0.0",
|
||||||
"dayjs": "^1.10.4",
|
"dayjs": "^1.10.4",
|
||||||
"epg-grabber": "^0.17.1",
|
"epg-grabber": "^0.18.0",
|
||||||
"epg-parser": "^0.1.6",
|
"epg-parser": "^0.1.6",
|
||||||
"form-data": "^4.0.0",
|
"form-data": "^4.0.0",
|
||||||
"glob": "^7.2.0",
|
"glob": "^7.2.0",
|
||||||
|
|
|
@ -34,13 +34,18 @@ async function loadChannels() {
|
||||||
for (const filepath of files) {
|
for (const filepath of files) {
|
||||||
const dir = file.dirname(filepath)
|
const dir = file.dirname(filepath)
|
||||||
const filename = file.basename(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)
|
const items = await parser.parseChannels(filepath)
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
const countryCode = item.xmltv_id.split('.')[1]
|
const countryCode = item.xmltv_id.split('.')[1]
|
||||||
item.country = countryCode ? countryCode.toUpperCase() : null
|
item.country = countryCode ? countryCode.toUpperCase() : null
|
||||||
item.channelsPath = filepath
|
item.channelsPath = filepath
|
||||||
item.configPath = `${dir}/${item.site}.config.js`
|
item.configPath = configPath
|
||||||
item.gid = gid
|
item.gid = gid
|
||||||
channels.push(item)
|
channels.push(item)
|
||||||
}
|
}
|
||||||
|
|
10
tests/__data__/input/sites/ignore.com.config.js
Normal file
10
tests/__data__/input/sites/ignore.com.config.js
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
module.exports = {
|
||||||
|
site: 'ignore.com',
|
||||||
|
ignore: true,
|
||||||
|
url() {
|
||||||
|
return `https://ignore.com`
|
||||||
|
},
|
||||||
|
parser() {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<site site="example.com">
|
<site site="ignore.com">
|
||||||
<channels>
|
<channels>
|
||||||
<channel lang="en" xmltv_id="1Plus2.lv" site_id="1341">1+2</channel>
|
<channel lang="en" xmltv_id="1Plus2.lv" site_id="1341">1+2</channel>
|
||||||
</channels>
|
</channels>
|
|
@ -6,7 +6,7 @@ beforeEach(() => {
|
||||||
fs.rmdirSync('tests/__data__/output', { recursive: true })
|
fs.rmdirSync('tests/__data__/output', { recursive: true })
|
||||||
fs.mkdirSync('tests/__data__/output')
|
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',
|
'DB_DIR=tests/__data__/output/database node scripts/commands/create-database.js --channels=tests/__data__/input/sites/*.channels.xml --max-clusters=1',
|
||||||
{ encoding: 'utf8' }
|
{ encoding: 'utf8' }
|
||||||
)
|
)
|
||||||
|
@ -15,21 +15,8 @@ beforeEach(() => {
|
||||||
it('can create channels database', () => {
|
it('can create channels database', () => {
|
||||||
const output = content('tests/__data__/output/database/channels.db')
|
const output = content('tests/__data__/output/database/channels.db')
|
||||||
|
|
||||||
expect(output).toEqual(
|
expect(output).toMatchObject([
|
||||||
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',
|
lang: 'ru',
|
||||||
country: 'US',
|
country: 'US',
|
||||||
xmltv_id: 'CNNInternationalEurope.us',
|
xmltv_id: 'CNNInternationalEurope.us',
|
||||||
|
@ -40,9 +27,8 @@ it('can create channels database', () => {
|
||||||
configPath: 'tests/__data__/input/sites/example.com.config.js',
|
configPath: 'tests/__data__/input/sites/example.com.config.js',
|
||||||
gid: 'ca-nl',
|
gid: 'ca-nl',
|
||||||
cluster_id: 1
|
cluster_id: 1
|
||||||
})
|
}
|
||||||
])
|
])
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
function content(filepath) {
|
function content(filepath) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue