mirror of
https://github.com/iptv-org/iptv
synced 2026-05-07 01:57:21 -04:00
fix: V-001 security vulnerability
Automated security fix generated by Orbis Security AI
This commit is contained in:
@@ -1,185 +1,194 @@
|
|||||||
import { loadData, data, searchChannels } from '../../api'
|
import { loadData, data, searchChannels } from '../../api'
|
||||||
import { Collection, Logger } from '@freearhey/core'
|
import { Collection, Logger } from '@freearhey/core'
|
||||||
import { select, input } from '@inquirer/prompts'
|
import { select, input } from '@inquirer/prompts'
|
||||||
import { Playlist, Stream } from '../../models'
|
import { Playlist, Stream } from '../../models'
|
||||||
import { Storage } from '@freearhey/storage-js'
|
import { Storage } from '@freearhey/storage-js'
|
||||||
import { PlaylistParser } from '../../core'
|
import { PlaylistParser } from '../../core'
|
||||||
import nodeCleanup from 'node-cleanup'
|
import nodeCleanup from 'node-cleanup'
|
||||||
import * as sdk from '@iptv-org/sdk'
|
import * as sdk from '@iptv-org/sdk'
|
||||||
import { truncate } from '../../utils'
|
import { truncate } from '../../utils'
|
||||||
import { Command } from 'commander'
|
import { Command } from 'commander'
|
||||||
import readline from 'readline'
|
import readline from 'readline'
|
||||||
|
import path from 'path'
|
||||||
type ChoiceValue = { type: string; value?: sdk.Models.Feed | sdk.Models.Channel }
|
|
||||||
type Choice = { name: string; short?: string; value: ChoiceValue; default?: boolean }
|
type ChoiceValue = { type: string; value?: sdk.Models.Feed | sdk.Models.Channel }
|
||||||
|
type Choice = { name: string; short?: string; value: ChoiceValue; default?: boolean }
|
||||||
if (process.platform === 'win32') {
|
|
||||||
readline
|
if (process.platform === 'win32') {
|
||||||
.createInterface({
|
readline
|
||||||
input: process.stdin,
|
.createInterface({
|
||||||
output: process.stdout
|
input: process.stdin,
|
||||||
})
|
output: process.stdout
|
||||||
.on('SIGINT', function () {
|
})
|
||||||
process.emit('SIGINT')
|
.on('SIGINT', function () {
|
||||||
})
|
process.emit('SIGINT')
|
||||||
}
|
})
|
||||||
|
}
|
||||||
const program = new Command()
|
|
||||||
|
const program = new Command()
|
||||||
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)
|
||||||
const filepath = program.args[0]
|
|
||||||
const logger = new Logger()
|
const filepath = program.args[0]
|
||||||
const storage = new Storage()
|
const logger = new Logger()
|
||||||
let parsedStreams = new Collection<Stream>()
|
|
||||||
|
const resolvedPath = path.resolve(filepath)
|
||||||
main(filepath)
|
const relative = path.relative(process.cwd(), resolvedPath)
|
||||||
nodeCleanup(() => {
|
if (relative.startsWith('..') || path.isAbsolute(relative)) {
|
||||||
save(filepath)
|
console.error(`Error: filepath "${filepath}" is outside the working directory`)
|
||||||
})
|
process.exit(1)
|
||||||
|
}
|
||||||
export default async function main(filepath: string) {
|
|
||||||
if (!(await storage.exists(filepath))) {
|
const storage = new Storage()
|
||||||
throw new Error(`File "${filepath}" does not exists`)
|
let parsedStreams = new Collection<Stream>()
|
||||||
}
|
|
||||||
|
main(filepath)
|
||||||
logger.info('loading data from api...')
|
nodeCleanup(() => {
|
||||||
await loadData()
|
save(filepath)
|
||||||
|
})
|
||||||
logger.info('loading streams...')
|
|
||||||
const parser = new PlaylistParser({
|
export default async function main(filepath: string) {
|
||||||
storage
|
if (!(await storage.exists(filepath))) {
|
||||||
})
|
throw new Error(`File "${filepath}" does not exists`)
|
||||||
parsedStreams = await parser.parseFile(filepath)
|
}
|
||||||
const streamsWithoutId = parsedStreams.filter((stream: Stream) => !stream.tvgId)
|
|
||||||
|
logger.info('loading data from api...')
|
||||||
logger.info(
|
await loadData()
|
||||||
`found ${parsedStreams.count()} streams (including ${streamsWithoutId.count()} without ID)`
|
|
||||||
)
|
logger.info('loading streams...')
|
||||||
|
const parser = new PlaylistParser({
|
||||||
logger.info('starting...\n')
|
storage
|
||||||
|
})
|
||||||
for (const stream of streamsWithoutId.all()) {
|
parsedStreams = await parser.parseFile(filepath)
|
||||||
try {
|
const streamsWithoutId = parsedStreams.filter((stream: Stream) => !stream.tvgId)
|
||||||
stream.tvgId = await selectChannel(stream)
|
|
||||||
} catch (err) {
|
logger.info(
|
||||||
logger.info(err.message)
|
`found ${parsedStreams.count()} streams (including ${streamsWithoutId.count()} without ID)`
|
||||||
break
|
)
|
||||||
}
|
|
||||||
}
|
logger.info('starting...\n')
|
||||||
|
|
||||||
streamsWithoutId.forEach((stream: Stream) => {
|
for (const stream of streamsWithoutId.all()) {
|
||||||
if (stream.tvgId === '-') {
|
try {
|
||||||
stream.tvgId = ''
|
stream.tvgId = await selectChannel(stream)
|
||||||
}
|
} catch (err) {
|
||||||
})
|
logger.info(err.message)
|
||||||
}
|
break
|
||||||
|
}
|
||||||
async function selectChannel(stream: Stream): Promise<string> {
|
}
|
||||||
const similarChannels = searchChannels(stream.title)
|
|
||||||
const url = truncate(stream.url, 50)
|
streamsWithoutId.forEach((stream: Stream) => {
|
||||||
|
if (stream.tvgId === '-') {
|
||||||
const selected: ChoiceValue = await select({
|
stream.tvgId = ''
|
||||||
message: `Select channel ID for "${stream.title}" (${url}):`,
|
}
|
||||||
choices: getChannelChoises(similarChannels),
|
})
|
||||||
pageSize: 10
|
}
|
||||||
})
|
|
||||||
|
async function selectChannel(stream: Stream): Promise<string> {
|
||||||
switch (selected.type) {
|
const similarChannels = searchChannels(stream.title)
|
||||||
case 'skip':
|
const url = truncate(stream.url, 50)
|
||||||
return '-'
|
|
||||||
case 'type': {
|
const selected: ChoiceValue = await select({
|
||||||
const typedChannelId = await input({ message: ' Channel ID:' })
|
message: `Select channel ID for "${stream.title}" (${url}):`,
|
||||||
if (!typedChannelId) return ''
|
choices: getChannelChoises(similarChannels),
|
||||||
const selectedFeedId = await selectFeed(typedChannelId)
|
pageSize: 10
|
||||||
if (selectedFeedId === '-') return typedChannelId
|
})
|
||||||
return [typedChannelId, selectedFeedId].join('@')
|
|
||||||
}
|
switch (selected.type) {
|
||||||
case 'channel': {
|
case 'skip':
|
||||||
const selectedChannel = selected.value
|
return '-'
|
||||||
if (!selectedChannel) return ''
|
case 'type': {
|
||||||
const selectedFeedId = await selectFeed(selectedChannel.id)
|
const typedChannelId = await input({ message: ' Channel ID:' })
|
||||||
if (selectedFeedId === '-') return selectedChannel.id
|
if (!typedChannelId) return ''
|
||||||
return [selectedChannel.id, selectedFeedId].join('@')
|
const selectedFeedId = await selectFeed(typedChannelId)
|
||||||
}
|
if (selectedFeedId === '-') return typedChannelId
|
||||||
}
|
return [typedChannelId, selectedFeedId].join('@')
|
||||||
|
}
|
||||||
return ''
|
case 'channel': {
|
||||||
}
|
const selectedChannel = selected.value
|
||||||
|
if (!selectedChannel) return ''
|
||||||
async function selectFeed(channelId: string): Promise<string> {
|
const selectedFeedId = await selectFeed(selectedChannel.id)
|
||||||
const channelFeeds = new Collection(data.feedsGroupedByChannel.get(channelId))
|
if (selectedFeedId === '-') return selectedChannel.id
|
||||||
const choices = getFeedChoises(channelFeeds)
|
return [selectedChannel.id, selectedFeedId].join('@')
|
||||||
|
}
|
||||||
const selected: ChoiceValue = await select({
|
}
|
||||||
message: `Select feed ID for "${channelId}":`,
|
|
||||||
choices,
|
return ''
|
||||||
pageSize: 10
|
}
|
||||||
})
|
|
||||||
|
async function selectFeed(channelId: string): Promise<string> {
|
||||||
switch (selected.type) {
|
const channelFeeds = new Collection(data.feedsGroupedByChannel.get(channelId))
|
||||||
case 'skip':
|
const choices = getFeedChoises(channelFeeds)
|
||||||
return '-'
|
|
||||||
case 'type':
|
const selected: ChoiceValue = await select({
|
||||||
return await input({ message: ' Feed ID:', default: 'SD' })
|
message: `Select feed ID for "${channelId}":`,
|
||||||
case 'feed':
|
choices,
|
||||||
const selectedFeed = selected.value
|
pageSize: 10
|
||||||
if (!selectedFeed) return ''
|
})
|
||||||
return selectedFeed.id
|
|
||||||
}
|
switch (selected.type) {
|
||||||
|
case 'skip':
|
||||||
return ''
|
return '-'
|
||||||
}
|
case 'type':
|
||||||
|
return await input({ message: ' Feed ID:', default: 'SD' })
|
||||||
function getChannelChoises(channels: Collection<sdk.Models.Channel>): Choice[] {
|
case 'feed':
|
||||||
const choises: Choice[] = []
|
const selectedFeed = selected.value
|
||||||
|
if (!selectedFeed) return ''
|
||||||
channels.forEach((channel: sdk.Models.Channel) => {
|
return selectedFeed.id
|
||||||
const names = new Collection([channel.name, ...channel.alt_names]).uniq().join(', ')
|
}
|
||||||
|
|
||||||
choises.push({
|
return ''
|
||||||
value: {
|
}
|
||||||
type: 'channel',
|
|
||||||
value: channel
|
function getChannelChoises(channels: Collection<sdk.Models.Channel>): Choice[] {
|
||||||
},
|
const choises: Choice[] = []
|
||||||
name: `${channel.id} (${names})`,
|
|
||||||
short: `${channel.id}`
|
channels.forEach((channel: sdk.Models.Channel) => {
|
||||||
})
|
const names = new Collection([channel.name, ...channel.alt_names]).uniq().join(', ')
|
||||||
})
|
|
||||||
|
choises.push({
|
||||||
choises.push({ name: 'Type...', value: { type: 'type' } })
|
value: {
|
||||||
choises.push({ name: 'Skip', value: { type: 'skip' } })
|
type: 'channel',
|
||||||
|
value: channel
|
||||||
return choises
|
},
|
||||||
}
|
name: `${channel.id} (${names})`,
|
||||||
|
short: `${channel.id}`
|
||||||
function getFeedChoises(feeds: Collection<sdk.Models.Feed>): Choice[] {
|
})
|
||||||
const choises: Choice[] = []
|
})
|
||||||
|
|
||||||
feeds.forEach((feed: sdk.Models.Feed) => {
|
choises.push({ name: 'Type...', value: { type: 'type' } })
|
||||||
let name = `${feed.id} (${feed.name})`
|
choises.push({ name: 'Skip', value: { type: 'skip' } })
|
||||||
if (feed.is_main) name += ' [main]'
|
|
||||||
|
return choises
|
||||||
choises.push({
|
}
|
||||||
value: {
|
|
||||||
type: 'feed',
|
function getFeedChoises(feeds: Collection<sdk.Models.Feed>): Choice[] {
|
||||||
value: feed
|
const choises: Choice[] = []
|
||||||
},
|
|
||||||
default: feed.is_main,
|
feeds.forEach((feed: sdk.Models.Feed) => {
|
||||||
name,
|
let name = `${feed.id} (${feed.name})`
|
||||||
short: feed.id
|
if (feed.is_main) name += ' [main]'
|
||||||
})
|
|
||||||
})
|
choises.push({
|
||||||
|
value: {
|
||||||
choises.push({ name: 'Type...', value: { type: 'type' } })
|
type: 'feed',
|
||||||
choises.push({ name: 'Skip', value: { type: 'skip' } })
|
value: feed
|
||||||
|
},
|
||||||
return choises
|
default: feed.is_main,
|
||||||
}
|
name,
|
||||||
|
short: feed.id
|
||||||
function save(filepath: string) {
|
})
|
||||||
if (!storage.existsSync(filepath)) return
|
})
|
||||||
const playlist = new Playlist(parsedStreams)
|
|
||||||
storage.saveSync(filepath, playlist.toString())
|
choises.push({ name: 'Type...', value: { type: 'type' } })
|
||||||
logger.info(`\nFile '${filepath}' successfully saved`)
|
choises.push({ name: 'Skip', value: { type: 'skip' } })
|
||||||
}
|
|
||||||
|
return choises
|
||||||
|
}
|
||||||
|
|
||||||
|
function save(filepath: string) {
|
||||||
|
if (!storage.existsSync(filepath)) return
|
||||||
|
const playlist = new Playlist(parsedStreams)
|
||||||
|
storage.saveSync(filepath, playlist.toString())
|
||||||
|
logger.info(`\nFile '${filepath}' successfully saved`)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user