mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-09 16:40:07 -04:00
Install fuse.js package
This commit is contained in:
parent
2e64b51b79
commit
c4189460cb
4 changed files with 41 additions and 52 deletions
49
package-lock.json
generated
49
package-lock.json
generated
|
@ -12,7 +12,6 @@
|
||||||
"@eslint/eslintrc": "^3.2.0",
|
"@eslint/eslintrc": "^3.2.0",
|
||||||
"@eslint/js": "^9.17.0",
|
"@eslint/js": "^9.17.0",
|
||||||
"@freearhey/core": "^0.4.0",
|
"@freearhey/core": "^0.4.0",
|
||||||
"@freearhey/search-js": "^0.1.1",
|
|
||||||
"@ntlab/sfetch": "^1.0.0",
|
"@ntlab/sfetch": "^1.0.0",
|
||||||
"@octokit/plugin-paginate-rest": "^11.3.6",
|
"@octokit/plugin-paginate-rest": "^11.3.6",
|
||||||
"@octokit/plugin-rest-endpoint-methods": "^13.2.6",
|
"@octokit/plugin-rest-endpoint-methods": "^13.2.6",
|
||||||
|
@ -43,6 +42,7 @@
|
||||||
"eslint-config-prettier": "^9.0.0",
|
"eslint-config-prettier": "^9.0.0",
|
||||||
"form-data": "^4.0.0",
|
"form-data": "^4.0.0",
|
||||||
"fs-extra": "^10.0.1",
|
"fs-extra": "^10.0.1",
|
||||||
|
"fuse.js": "^7.0.0",
|
||||||
"glob": "^7.2.0",
|
"glob": "^7.2.0",
|
||||||
"globals": "^15.14.0",
|
"globals": "^15.14.0",
|
||||||
"husky": "^9.1.7",
|
"husky": "^9.1.7",
|
||||||
|
@ -1284,17 +1284,6 @@
|
||||||
"url": "https://github.com/sponsors/isaacs"
|
"url": "https://github.com/sponsors/isaacs"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@freearhey/search-js": {
|
|
||||||
"version": "0.1.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@freearhey/search-js/-/search-js-0.1.1.tgz",
|
|
||||||
"integrity": "sha512-nmXhqBg5lh6GxMT2g1hgmSc/pbXGw0P4ZxXaPt/cnuZYtvPHSo0CPOF65iNC9LEqvrrnLig4RFlG1dBDPNAU0g==",
|
|
||||||
"dependencies": {
|
|
||||||
"lodash": "^4.17.21"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=16.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@humanfs/core": {
|
"node_modules/@humanfs/core": {
|
||||||
"version": "0.19.1",
|
"version": "0.19.1",
|
||||||
"resolved": "https://registry.npmjs.org/@humanfs/core/-/core-0.19.1.tgz",
|
"resolved": "https://registry.npmjs.org/@humanfs/core/-/core-0.19.1.tgz",
|
||||||
|
@ -5002,9 +4991,20 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/function-bind": {
|
"node_modules/function-bind": {
|
||||||
"version": "1.1.1",
|
"version": "1.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
|
||||||
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A=="
|
"integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/fuse.js": {
|
||||||
|
"version": "7.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/fuse.js/-/fuse.js-7.0.0.tgz",
|
||||||
|
"integrity": "sha512-14F4hBIxqKvD4Zz/XjDc3y94mNZN6pRv3U13Udo0lNLCWRBUsrMv2xwcF/y/Z5sV6+FQW+/ow68cHpm4sunt8Q==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"node_modules/gensync": {
|
"node_modules/gensync": {
|
||||||
"version": "1.0.0-beta.2",
|
"version": "1.0.0-beta.2",
|
||||||
|
@ -10090,14 +10090,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@freearhey/search-js": {
|
|
||||||
"version": "0.1.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@freearhey/search-js/-/search-js-0.1.1.tgz",
|
|
||||||
"integrity": "sha512-nmXhqBg5lh6GxMT2g1hgmSc/pbXGw0P4ZxXaPt/cnuZYtvPHSo0CPOF65iNC9LEqvrrnLig4RFlG1dBDPNAU0g==",
|
|
||||||
"requires": {
|
|
||||||
"lodash": "^4.17.21"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"@humanfs/core": {
|
"@humanfs/core": {
|
||||||
"version": "0.19.1",
|
"version": "0.19.1",
|
||||||
"resolved": "https://registry.npmjs.org/@humanfs/core/-/core-0.19.1.tgz",
|
"resolved": "https://registry.npmjs.org/@humanfs/core/-/core-0.19.1.tgz",
|
||||||
|
@ -12752,9 +12744,14 @@
|
||||||
"optional": true
|
"optional": true
|
||||||
},
|
},
|
||||||
"function-bind": {
|
"function-bind": {
|
||||||
"version": "1.1.1",
|
"version": "1.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
|
||||||
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A=="
|
"integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA=="
|
||||||
|
},
|
||||||
|
"fuse.js": {
|
||||||
|
"version": "7.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/fuse.js/-/fuse.js-7.0.0.tgz",
|
||||||
|
"integrity": "sha512-14F4hBIxqKvD4Zz/XjDc3y94mNZN6pRv3U13Udo0lNLCWRBUsrMv2xwcF/y/Z5sV6+FQW+/ow68cHpm4sunt8Q=="
|
||||||
},
|
},
|
||||||
"gensync": {
|
"gensync": {
|
||||||
"version": "1.0.0-beta.2",
|
"version": "1.0.0-beta.2",
|
||||||
|
|
|
@ -30,7 +30,10 @@
|
||||||
"transform": {
|
"transform": {
|
||||||
"^.+\\.(ts|js)$": "@swc/jest"
|
"^.+\\.(ts|js)$": "@swc/jest"
|
||||||
},
|
},
|
||||||
"testMatch": ["<rootDir>/sites/**/*.test.(js|ts)", "<rootDir>/tests/commands/**/*.test.(js|ts)"],
|
"testMatch": [
|
||||||
|
"<rootDir>/sites/**/*.test.(js|ts)",
|
||||||
|
"<rootDir>/tests/commands/**/*.test.(js|ts)"
|
||||||
|
],
|
||||||
"testTimeout": 10000
|
"testTimeout": 10000
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -38,7 +41,6 @@
|
||||||
"@eslint/eslintrc": "^3.2.0",
|
"@eslint/eslintrc": "^3.2.0",
|
||||||
"@eslint/js": "^9.17.0",
|
"@eslint/js": "^9.17.0",
|
||||||
"@freearhey/core": "^0.4.0",
|
"@freearhey/core": "^0.4.0",
|
||||||
"@freearhey/search-js": "^0.1.1",
|
|
||||||
"@ntlab/sfetch": "^1.0.0",
|
"@ntlab/sfetch": "^1.0.0",
|
||||||
"@octokit/plugin-paginate-rest": "^11.3.6",
|
"@octokit/plugin-paginate-rest": "^11.3.6",
|
||||||
"@octokit/plugin-rest-endpoint-methods": "^13.2.6",
|
"@octokit/plugin-rest-endpoint-methods": "^13.2.6",
|
||||||
|
@ -69,6 +71,7 @@
|
||||||
"eslint-config-prettier": "^9.0.0",
|
"eslint-config-prettier": "^9.0.0",
|
||||||
"form-data": "^4.0.0",
|
"form-data": "^4.0.0",
|
||||||
"fs-extra": "^10.0.1",
|
"fs-extra": "^10.0.1",
|
||||||
|
"fuse.js": "^7.0.0",
|
||||||
"glob": "^7.2.0",
|
"glob": "^7.2.0",
|
||||||
"globals": "^15.14.0",
|
"globals": "^15.14.0",
|
||||||
"husky": "^9.1.7",
|
"husky": "^9.1.7",
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { Channel } from 'epg-grabber'
|
||||||
import nodeCleanup from 'node-cleanup'
|
import nodeCleanup from 'node-cleanup'
|
||||||
import { program } from 'commander'
|
import { program } from 'commander'
|
||||||
import inquirer, { QuestionCollection } from 'inquirer'
|
import inquirer, { QuestionCollection } from 'inquirer'
|
||||||
import sj from '@freearhey/search-js'
|
import Fuse from 'fuse.js'
|
||||||
|
|
||||||
program.argument('<filepath>', 'Path to *.channels.xml file to edit').parse(process.argv)
|
program.argument('<filepath>', 'Path to *.channels.xml file to edit').parse(process.argv)
|
||||||
|
|
||||||
|
@ -25,15 +25,15 @@ async function main() {
|
||||||
|
|
||||||
const dataStorage = new Storage(DATA_DIR)
|
const dataStorage = new Storage(DATA_DIR)
|
||||||
const channelsContent = await dataStorage.json('channels.json')
|
const channelsContent = await dataStorage.json('channels.json')
|
||||||
const channelsIndex = sj.createIndex(channelsContent)
|
const searchIndex = new Fuse(channelsContent, { keys: ['name', 'alt_names'], threshold: 0.4 })
|
||||||
|
|
||||||
for (const channel of channels.all()) {
|
for (const channel of channels.all()) {
|
||||||
if (channel.xmltv_id) continue
|
if (channel.xmltv_id) continue
|
||||||
const question: QuestionCollection = {
|
const question: QuestionCollection = {
|
||||||
name: 'option',
|
name: 'option',
|
||||||
message: `"${channel.name}" (${channel.site_id}):`,
|
message: `Select xmltv_id for "${channel.name}" (${channel.site_id}):`,
|
||||||
type: 'list',
|
type: 'list',
|
||||||
choices: getOptions(channelsIndex, channel),
|
choices: getOptions(searchIndex, channel),
|
||||||
pageSize: 10
|
pageSize: 10
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,8 +94,7 @@ async function getInput(channel: Channel) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getOptions(index, channel: Channel) {
|
function getOptions(index, channel: Channel) {
|
||||||
const query = prepareQuery(channel.name)
|
const similar = index.search(channel.name).map(result => new ApiChannel(result.item))
|
||||||
const similar = index.search(query).map(item => new ApiChannel(item))
|
|
||||||
|
|
||||||
const variants = new Collection()
|
const variants = new Collection()
|
||||||
similar.forEach((_channel: ApiChannel) => {
|
similar.forEach((_channel: ApiChannel) => {
|
||||||
|
@ -110,11 +109,3 @@ function getOptions(index, channel: Channel) {
|
||||||
|
|
||||||
return variants.all()
|
return variants.all()
|
||||||
}
|
}
|
||||||
|
|
||||||
function prepareQuery(channelName: string) {
|
|
||||||
return channelName
|
|
||||||
.replace(/\s(SD|TV|HD|SD\/HD|HDTV)$/i, '')
|
|
||||||
.replace(/(\(|\)|,)/gi, '')
|
|
||||||
.replace(/-/gi, ' ')
|
|
||||||
.replace(/\+/gi, '')
|
|
||||||
}
|
|
||||||
|
|
18
yarn.lock
18
yarn.lock
|
@ -414,13 +414,6 @@
|
||||||
object-treeify "^2.1.1"
|
object-treeify "^2.1.1"
|
||||||
signale "^1.4.0"
|
signale "^1.4.0"
|
||||||
|
|
||||||
"@freearhey/search-js@^0.1.1":
|
|
||||||
version "0.1.1"
|
|
||||||
resolved "https://registry.npmjs.org/@freearhey/search-js/-/search-js-0.1.1.tgz"
|
|
||||||
integrity sha512-nmXhqBg5lh6GxMT2g1hgmSc/pbXGw0P4ZxXaPt/cnuZYtvPHSo0CPOF65iNC9LEqvrrnLig4RFlG1dBDPNAU0g==
|
|
||||||
dependencies:
|
|
||||||
lodash "^4.17.21"
|
|
||||||
|
|
||||||
"@humanfs/core@^0.19.1":
|
"@humanfs/core@^0.19.1":
|
||||||
version "0.19.1"
|
version "0.19.1"
|
||||||
resolved "https://registry.npmjs.org/@humanfs/core/-/core-0.19.1.tgz"
|
resolved "https://registry.npmjs.org/@humanfs/core/-/core-0.19.1.tgz"
|
||||||
|
@ -2667,9 +2660,14 @@ fsevents@^2.3.2, fsevents@~2.3.3:
|
||||||
integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==
|
integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==
|
||||||
|
|
||||||
function-bind@^1.1.1:
|
function-bind@^1.1.1:
|
||||||
version "1.1.1"
|
version "1.1.2"
|
||||||
resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz"
|
resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz"
|
||||||
integrity sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==
|
integrity sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==
|
||||||
|
|
||||||
|
fuse.js@^7.0.0:
|
||||||
|
version "7.0.0"
|
||||||
|
resolved "https://registry.npmjs.org/fuse.js/-/fuse.js-7.0.0.tgz"
|
||||||
|
integrity sha512-14F4hBIxqKvD4Zz/XjDc3y94mNZN6pRv3U13Udo0lNLCWRBUsrMv2xwcF/y/Z5sV6+FQW+/ow68cHpm4sunt8Q==
|
||||||
|
|
||||||
gensync@^1.0.0-beta.2:
|
gensync@^1.0.0-beta.2:
|
||||||
version "1.0.0-beta.2"
|
version "1.0.0-beta.2"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue