Files
iptv/scripts/commands/api/generate.ts

40 lines
1.4 KiB
TypeScript
Raw Normal View History

2025-04-16 20:54:55 +03:00
import { DataLoader, DataProcessor, PlaylistParser } from '../../core'
import type { DataProcessorData } from '../../types/dataProcessor'
2025-03-29 11:39:46 +03:00
import { API_DIR, STREAMS_DIR, DATA_DIR } from '../../constants'
2025-04-16 20:54:55 +03:00
import type { DataLoaderData } from '../../types/dataLoader'
import { Logger, Storage } from '@freearhey/core'
import { Stream } from '../../models'
2023-09-15 18:40:35 +03:00
async function main() {
const logger = new Logger()
2025-04-16 20:54:55 +03:00
logger.info('loading data from api...')
const processor = new DataProcessor()
2025-03-29 11:39:46 +03:00
const dataStorage = new Storage(DATA_DIR)
2025-04-16 20:54:55 +03:00
const dataLoader = new DataLoader({ storage: dataStorage })
const data: DataLoaderData = await dataLoader.load()
2025-07-10 21:13:43 +03:00
const { channelsKeyById, feedsGroupedByChannelId, logosGroupedByStreamId }: DataProcessorData =
processor.process(data)
2025-03-29 11:39:46 +03:00
2023-09-17 04:08:50 +03:00
logger.info('loading streams...')
const streamsStorage = new Storage(STREAMS_DIR)
2025-03-29 11:39:46 +03:00
const parser = new PlaylistParser({
storage: streamsStorage,
2025-04-16 20:54:55 +03:00
channelsKeyById,
2025-07-10 21:13:43 +03:00
logosGroupedByStreamId,
2025-03-29 11:39:46 +03:00
feedsGroupedByChannelId
})
2023-09-17 04:08:50 +03:00
const files = await streamsStorage.list('**/*.m3u')
let streams = await parser.parse(files)
streams = streams
2025-03-29 11:39:46 +03:00
.orderBy((stream: Stream) => stream.getId())
2023-09-15 18:40:35 +03:00
.map((stream: Stream) => stream.toJSON())
logger.info(`found ${streams.count()} streams`)
logger.info('saving to .api/streams.json...')
2023-09-17 04:08:50 +03:00
const apiStorage = new Storage(API_DIR)
await apiStorage.save('streams.json', streams.toJSON())
2023-09-15 18:40:35 +03:00
}
main()